book/src/development/design/actor.md

89 lines
2.3 KiB
Markdown
Raw Normal View History

2023-04-17 21:23:10 +00:00
# Actor System
2023-04-20 22:08:37 +00:00
```admonish question title="Why?"
**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
```rust
// 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
}
```
2023-04-20 18:40:38 +00:00
## OCAP
**TODO**
## Messages
**TODO**
- [postcard](https://lib.rs/crates/postcard) for message passing
- Priority Queue for processing multiple messages, while dealing with higher-priority ones first
### Latency