-
Notifications
You must be signed in to change notification settings - Fork 0
intro
This is a framework to simplify cloud syncing and sending of data. E.g. sending encrypted messages from user a to user b. Or having offline changes to settings/content/game and syncing them to other devices and redundant server storage.
graph LR;
A[User A mobile] -- How are you? --> cloud
cloud -- How are you? --> B[User B]
cloud -- How are you? --> A2[User A desktop Device]
In general there are two types of things, Referenceables and Commands.
-
Referenceables have an unique ids with which they can be found in the cloud -
Commands contain logic with whichReferenceables are manipulated. They are bound to aReferenceablelike methods on a class.
Then there are instances of the cloud generally called Core. There is ServerCore, ClientCore and DevCore they all derive of CoflnetCore which in itself is a Referenceable.
All of the Referenceables are in managed by the ReferenceManager.
You should use CoflnetCore.Instance which is an ServerCore, ClientCore orDevCoreto send Commands and interact with the framework.
After choosing a core with the Init() method e.g. ClientCore.Init() you send commands like this
CoflnetCore.Instance.SendCommand<CommandClass,DataClass>(receiver,data);this will first look at the CommandClass find out if it should instantly apply it to the local ReferenceManager, if so it does.
Then it serializes the data as DataClass and tries to send it to the managing server, if it fails the serialized command is stored and sending is retried periodically.
When the server receives the command it searches for the Referenceable in its ReferenceManager, validates the comand, makes sure the sender is allowed to execute the command, executes it and may distribute it to other Referenceables eg a Device to sync it.
You can make your own Referenceable by inheriting the class Referenceable. To make it globaly available you should call .AssignId() which will assign an id (only on a server).
In case you want to create a Referenceable on a Client and offline you will need to create a CreationCommand.
Your class will need to implement a CommandController which contains all Command that are available to be executed. You may want to register commands in the [static] constructor of your class to make them available.
You can make your own Command by inheriting the class Command. You may want to register it on a CommandController to make it available. You will need to implement 3 things:
-
Execute(MessageData data)which contains the actual logic of your Command and receives the deserialized container -
Slugunique identifier for your command often the class name -
CommandSettingsa custom subclass which defines things like if the command is transmitted end to end encrypted
In Execute(MessageData data) you should use data to do interactions with the rest of the system. For example you can get the target Referenceable like CoflnetUser or the ClientCore by using data.GetTargetAs<CoflnetUser>() which will find and return it.
You can extend the CommandController of eg the ClientCore and use custom extentions by altering the ClientExtentions class. You can add any classes there that implement IRegisterCommands which requires a method that gets the Core CommandController on which you can register your own commands.
A similar class (ServerExtentions exists on the server where you can also register your extentions.
You should use it if you have to
- transmit data
- from multiple users or devices from one to another
- at scale
- encrypted
- and comply with local rules and laws in countries accross the world
- easily
You can call one function in your clients code base and the framework will make sure the data you want to send will reach its target (one or multiple devices) end to end encrypted, anonymously, anywhere in the world, at scale also if the target or the device is currently offline.
Usecases considered:
- secure and anonymous [chat] messaging
- asyncronous round based gaming
- profile managing