Browse Source

Started writing out the basic data structures.

Matthew Carr 3 years ago
parent
commit
90acc9b64e
2 changed files with 112 additions and 10 deletions
  1. 45 0
      crates/node/.vscode/launch.json
  2. 67 10
      crates/node/src/main.rs

+ 45 - 0
crates/node/.vscode/launch.json

@@ -0,0 +1,45 @@
+{
+    // Use IntelliSense to learn about possible attributes.
+    // Hover to view descriptions of existing attributes.
+    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "lldb",
+            "request": "launch",
+            "name": "Debug executable 'node'",
+            "cargo": {
+                "args": [
+                    "build",
+                    "--bin=node",
+                    "--package=node"
+                ],
+                "filter": {
+                    "name": "node",
+                    "kind": "bin"
+                }
+            },
+            "args": [],
+            "cwd": "${workspaceFolder}"
+        },
+        {
+            "type": "lldb",
+            "request": "launch",
+            "name": "Debug unit tests in executable 'node'",
+            "cargo": {
+                "args": [
+                    "test",
+                    "--no-run",
+                    "--bin=node",
+                    "--package=node"
+                ],
+                "filter": {
+                    "name": "node",
+                    "kind": "bin"
+                }
+            },
+            "args": [],
+            "cwd": "${workspaceFolder}"
+        }
+    ]
+}

+ 67 - 10
crates/node/src/main.rs

@@ -1,13 +1,70 @@
-// SHA512 requires 64 bytes.
-const signature_len: usize = 64;
-
-struct Block<'a> {
-    version: u8,
-    path: &'a str,
-    read_caps: (),
-    write_cap: (),
-    body: &'a [u8],
-    signature: [u8; signature_len]
+use std::collections::{hash_map, HashMap};
+
+enum VersionedBlock {
+    V0(Block)
+}
+
+struct Block {
+    path: String,
+    read_caps: HashMap<Hash, ReadCap>,
+    write_cap: WriteCap,
+    body: Vec<u8>,
+    signature: Signature
+}
+
+struct ReadCap {
+    issued_to: Hash,
+    key: EnvelopedKey,
+}
+
+struct WriteCap {
+    issued_to: Hash,
+    path: String,
+    chain: Vec<Certificate>,
+    signature: Signature,
+}
+
+struct Certificate {
+    issued_to: Hash,
+    issued_by: Hash,
+    signature: Signature,
+}
+
+enum Hash {
+    None,
+    Sha2_256([u8; 32]),
+    Sha2_512([u8; 64]),
+}
+
+enum Signature {
+    Ed25519([u8; 64]),
+}
+
+enum EnvelopedKey {
+    Xsalsa20Poly1305([u8; 32]),
+}
+
+type Directory = HashMap<String, Vec<FragmentRecord>>;
+
+trait IDirectory {
+    fn file_names(&self) -> hash_map::Keys<'_, String, Vec<FragmentRecord>>;
+}
+
+impl IDirectory for Directory {
+    fn file_names(&self) -> hash_map::Keys<'_, String, Vec<FragmentRecord>> {
+        self.keys()
+    }
+}
+
+struct FragmentRecord {
+    stored_by: Hash,
+    serial: u32,
+}
+
+struct Fragment {
+    path: String,
+    serial: u32,
+    body: Vec<u8>,
 }
 
 fn main() {