瀏覽代碼

Started working out the definitions of the sector
and filesystem protocols.

Matthew Carr 1 年之前
父節點
當前提交
d626f90ffb
共有 4 個文件被更改,包括 116 次插入15 次删除
  1. 35 0
      crates/btrun/src/fs_proto.rs
  2. 15 13
      crates/btrun/src/lib.rs
  3. 64 0
      crates/btrun/src/sector_proto.rs
  4. 2 2
      doc/BlocktreeDce/BlocktreeDce.tex

+ 35 - 0
crates/btrun/src/fs_proto.rs

@@ -0,0 +1,35 @@
+use btproto::protocol;
+use serde::{Serialize, Deserialize};
+
+use crate::{sector_proto::FileId, CallMsg, ActorName};
+
+#[derive(Serialize, Deserialize)]
+pub struct Open {
+    id: FileId
+}
+
+impl CallMsg for Open {
+    type Reply = ActorName;
+}
+
+protocol! {
+    ServerInit?Activate -> Listening;
+
+    Client -> Client, service(Listening)!Query;
+    Listening?Query -> Listening, Client!Query::Reply;
+    Client?Query::Reply -> Client;
+
+    Client -> Client, service(Listening)!Open;
+    Listening?Open -> Listening, Opened, Client!Open::Reply;
+    Client?Open::Reply -> Client, FileHandle;
+
+    FileInit?Activate -> FileInit;
+    FileInit?Open -> Opened;
+
+    FileHandle -> FileHandle, Opened!FileOp;
+    Opened?FileOp -> Opened, Client!FileOp::Reply;
+    FileClient?FileOp::Reply -> FileClient;
+
+    FileClient -> End, Opened!Close;
+    Opened?Close -> End;
+}

+ 15 - 13
crates/btrun/src/lib.rs

@@ -1,5 +1,8 @@
 #![feature(impl_trait_in_assoc_type)]
 
+pub mod sector_proto;
+pub mod fs_proto;
+
 use std::{
     any::Any,
     collections::HashMap,
@@ -808,10 +811,10 @@ mod tests {
     // simple ping-pong protocol:
     //
     protocol! {
-        ClientInit?Activate -> SentPing, Listening!Ping
-        ServerInit?Activate -> Listening
-        Listening?Ping -> End, SentPing!Ping::Reply
-        SentPing?Ping::Reply -> End
+        ClientInit?Activate -> SentPing, Listening!Ping;
+        ServerInit?Activate -> Listening;
+        Listening?Ping -> End, SentPing!Ping::Reply;
+        SentPing?Ping::Reply -> End;
     }
     //
     // In words, the protocol is described as follows.
@@ -1015,15 +1018,14 @@ mod tests {
     // example in the survey paper "Behavioral Types in Programming Languages."
     //
     protocol! {
-        CustomerInit?Activate -> Choosing
-        AgencyInit?Activate -> Listening
-        Choosing?Choice -> Choosing, Listening!Query|Accept|Reject
-        Listening?Query -> Listening, Choosing!Query::Reply
-        Choosing?Query::Reply -> Choosing
-        Listening?Accept -> End, Choosing!Accept::Reply
-        Choosing?Accept::Reply -> End
-        Listening?Reject -> End, Choosing!Reject:Reply
-        Choosing?Reject::Reply -> End
+        AgencyInit?Activate -> Listening;
+        Choosing -> Choosing, Listening!Query|Accept|Reject;
+        Listening?Query -> Listening, Choosing!Query::Reply;
+        Choosing?Query::Reply -> Choosing;
+        Listening?Accept -> End, Choosing!Accept::Reply;
+        Choosing?Accept::Reply -> End;
+        Listening?Reject -> End, Choosing!Reject:Reply;
+        Choosing?Reject::Reply -> End;
     }
     //
     // The Choice message is from the runtime itself. It represents receiving input from a user.

+ 64 - 0
crates/btrun/src/sector_proto.rs

@@ -0,0 +1,64 @@
+//! Types which define the protocol used by the sector layer.
+
+use btlib::{BlockMeta, crypto::merkle_stream::VariantMerkleTree, Inode};
+use btproto::protocol;
+
+use crate::{Serialize, Deserialize, CallMsg};
+
+#[derive(Serialize, Deserialize)]
+pub struct SectorMsg {
+    id: SectorId,
+    op: SectorOperation,
+}
+
+impl CallMsg for SectorMsg {
+    type Reply = SectorMsgReply;
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct SectorId {
+    file: FileId,
+    sector: SectorKind,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct FileId {
+    generation: u64,
+    inode: Inode,
+}
+
+#[derive(Serialize, Deserialize)]
+pub enum SectorKind {
+    Meta,
+    Merkle,
+    Data(u64),
+}
+
+#[derive(Serialize, Deserialize)]
+pub enum SectorOperation {
+    Read,
+    Write(WriteOperation),
+}
+
+#[derive(Serialize, Deserialize)]
+pub enum WriteOperation {
+    Meta(Box<BlockMeta>),
+    Data {
+        meta: Box<BlockMeta>,
+        contents: Vec<u8>,
+    }
+}
+
+#[derive(Serialize, Deserialize)]
+pub enum SectorMsgReply {
+    Meta(BlockMeta),
+    Merkle(VariantMerkleTree),
+    Data(Vec<u8>),
+}
+
+protocol! {
+    ServerInit?Activate -> Listening;
+    Client -> Client, service(Listening)!SectorMsg;
+    Listening?SectorMsg -> Listening, Client!SectorMsg::Reply;
+    Client?SectorMsg::Reply -> Client;
+}

+ 2 - 2
doc/BlocktreeDce/BlocktreeDce.tex

@@ -726,7 +726,7 @@ The byte offset in the plaintext of the file at which each data sector begins ca
 multiplying the sector's index by the sector size of the file.
 The \texttt{SectorId} type is used to identify a sector.
 \begin{verbatim}
-  pub enum SectorId {
+  pub struct SectorId {
     generation: u64,
     inode: u64,
     sector: SectorKind,
@@ -841,7 +841,7 @@ They use the credentials of the runtime they're hosted in to decrypt sector data
 information contained in file metadata.
 File actors are also responsible for encrypting and integrity protecting data written to files.
 In order for these actors to produce a signature over the root of the file's Merkle tree,
-it maintains a copy of the tree in memory.
+they each maintains a copy of it in memory.
 This copy is read from the sector service when the file is opened.
 While this does mean duplicating data between the sector and filesystem services,
 this design was chosen to reduce the network traffic between the two services,