book/src/development/design/actor.md

2.3 KiB

Actor System

**Actors** work as an abstraction over data storage and messaging.
It allows for all systems *(GUI, Programs, etc.)* to work together, and rely on the same features.
It reduces work of implementation, and all implementations can use the functions.

Features

  • Petnames
  • OCAP security
  • HMAC message verification
// Different possible types of actors (more to be added)
enum ActorType {
    GUI(Widget),
    ProgramInterface,
}

// Possible states an actor can be in
enum ActorState {
    Receive,
    Send,
    Work,
    Idle,
}

// Cryptographic keypair
struct KeyPair {
    privkey: u128,
    pubkey: u128,
}

// The actor itself
struct Actor<D: DataInterface> {
    petname: Option<String>, // Human-meaningful petname (explored further down)
    uuid: Uuid, // Unique identifier
    namespace: Uuid, // Parent namespace of this actor
    actor_type: ActorType,
    state: ActorState,
    keys: Option<KeyPair>, // Cryptographic keypair
    creation_date: DateTime,
    modified_date: DateTime,
    data: Option<D>, // Optional data of the generic D type
}

impl Actor {
    fn new(namespace: Uuid, a_type: ActorType) -> Self {
        Actor {
            petname: None,
            uuid: Uuid::new(),
            namespace: namespace,
            actor_type: a_type,
            state: ActorState::Idle,
            keys: None,
            creation_date:: now(),
            modified_date: now(),
            data: None,
        }
    };
}

impl KeyPair {
    fn generate_keypair(&mut self) -> Self;
    fn get_pubkey(&self) -> u128;
    fn sign(&self, &[u8]) -> Result<&[u8], Error>;
    fn verify_signature(&[u8], u128) -> Result<(), Error>;
}

trait FilesystemInterface { // Interfacing with the filesystem
    fn read(&mut self) -> Result<(), Error>; // Read the data from the disk into the Actor using the Uuid as a search key
    fn write(&self) -> Result<(), Error>; // Write the data to the disk using the Uuid as a key
}

trait DataInterface { // Necessary data functions
    fn to_bytes(&self) -> Result<&[u8], Error>; // Convert the data into a byte array
}

OCAP

TODO

Messages

TODO

  • postcard for message passing
  • Priority Queue for processing multiple messages, while dealing with higher-priority ones first

Latency