Skip to content

Commit

Permalink
Clean up Commit RPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
bifurcation committed Mar 3, 2023
1 parent 74e7f24 commit 437dd3b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 72 deletions.
13 changes: 6 additions & 7 deletions interop/cpp-mock-client/mock_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class MLSClientImpl final : public MLSClient::Service

response->set_commit("commit");
response->set_welcome("welcome");
response->set_epoch_authenticator("epoch_authenticator");
return Status::OK;
}

Expand All @@ -237,22 +238,20 @@ class MLSClientImpl final : public MLSClient::Service
}

response->set_state_id(newID(states));
response->set_epoch_authenticator("epoch_authenticator");
return Status::OK;
}

Status HandleExternalCommit(ServerContext* /* context */,
const HandleExternalCommitRequest* request,
HandleExternalCommitResponse* response) override
Status HandlePendingCommit(ServerContext* /* context */,
const HandlePendingCommitRequest* request,
HandleCommitResponse* response) override
{
if (states.count(request->state_id()) == 0) {
return Status(StatusCode::INVALID_ARGUMENT, "Invalid state");
}

if (request->commit() != "commit") {
return Status(StatusCode::INVALID_ARGUMENT, "Invalid commit");
}

response->set_state_id(newID(states));
response->set_epoch_authenticator("epoch_authenticator");
return Status::OK;
}
};
Expand Down
19 changes: 9 additions & 10 deletions interop/go-mock-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ func (mc *MockClient) Commit(ctx context.Context, in *pb.CommitRequest) (*pb.Com
}

resp := &pb.CommitResponse{
Commit: []byte("commit"),
Welcome: []byte("welcome"),
Commit: []byte("commit"),
Welcome: []byte("welcome"),
EpochAuthenticator: []byte("epoch_authenticator"),
}

return resp, nil
Expand All @@ -226,25 +227,23 @@ func (mc *MockClient) HandleCommit(ctx context.Context, in *pb.HandleCommitReque
}

resp := &pb.HandleCommitResponse{
StateId: newID(mc.states),
StateId: newID(mc.states),
EpochAuthenticator: []byte("epoch_authenticator"),
}

mc.states[resp.StateId] = true
return resp, nil
}

func (mc *MockClient) HandleExternalCommit(ctx context.Context, in *pb.HandleExternalCommitRequest) (*pb.HandleExternalCommitResponse, error) {
func (mc *MockClient) HandlePendingCommit(ctx context.Context, in *pb.HandlePendingCommitRequest) (*pb.HandleCommitResponse, error) {
if !mc.states[in.StateId] {
fmt.Printf("Invalid state (handle): %d\n", in.StateId)
return nil, status.Error(codes.InvalidArgument, "Invalid state")
}

if string(in.Commit) != "commit" {
return nil, status.Error(codes.InvalidArgument, "Invalid commit")
}

resp := &pb.HandleExternalCommitResponse{
StateId: newID(mc.states),
resp := &pb.HandleCommitResponse{
StateId: newID(mc.states),
EpochAuthenticator: []byte("epoch_authenticator"),
}

mc.states[resp.StateId] = true
Expand Down
18 changes: 2 additions & 16 deletions interop/proto/mls_client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ service MLSClient {
rpc Commit(CommitRequest) returns (CommitResponse) {}
rpc HandleCommit(HandleCommitRequest) returns (HandleCommitResponse) {}
rpc HandlePendingCommit(HandlePendingCommitRequest) returns (HandleCommitResponse) {}
rpc HandleExternalCommit(HandleExternalCommitRequest) returns (HandleExternalCommitResponse) {}
}

// rpc Name
Expand Down Expand Up @@ -199,6 +198,7 @@ message CommitRequest {
message CommitResponse {
bytes commit = 1;
bytes welcome = 2;
bytes epoch_authenticator = 3;
}

// rpc HandleCommit
Expand All @@ -210,24 +210,10 @@ message HandleCommitRequest {

message HandleCommitResponse {
uint32 state_id = 1;
repeated uint32 added = 2;
repeated uint32 removed_indices = 3;
repeated bytes removed_leaves = 4;
repeated uint32 updated = 5;
repeated bytes psks = 6;
bytes epoch_authenticator = 2;
}

// rpc HandlePendingCommit
message HandlePendingCommitRequest {
uint32 state_id = 1;
}

// rpc HandleExternalCommit
message HandleExternalCommitRequest {
uint32 state_id = 1;
bytes commit = 3;
}

message HandleExternalCommitResponse {
uint32 state_id = 1;
}
42 changes: 3 additions & 39 deletions interop/rust-mock-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ impl MlsClient for MlsClientImpl {
let resp = CommitResponse {
commit: String::from("commit").into_bytes(),
welcome: String::from("welcome").into_bytes(),
epoch_authenticator: String::from("epoch_authenticator").into_bytes(),
};

Ok(Response::new(resp)) // TODO
Expand Down Expand Up @@ -335,11 +336,7 @@ impl MlsClient for MlsClientImpl {

let resp = HandleCommitResponse {
state_id: self.new_state_id(),
added: vec![0, 1, 2],
removed_indices: vec![0, 1],
removed_leaves: vec![vec![0u8; 10], vec![1u8; 16]],
updated: vec![],
psks: vec![],
epoch_authenticator: String::from("epoch_authenticator").into_bytes(),
};

Ok(Response::new(resp)) // TODO
Expand All @@ -359,40 +356,7 @@ impl MlsClient for MlsClientImpl {

let resp = HandleCommitResponse {
state_id: self.new_state_id(),
added: vec![0, 1, 2],
removed_indices: vec![0, 1],
removed_leaves: vec![vec![0u8; 10], vec![1u8; 16]],
updated: vec![],
psks: vec![],
};

Ok(Response::new(resp)) // TODO
}

async fn handle_external_commit(
&self,
request: tonic::Request<HandleExternalCommitRequest>,
) -> Result<tonic::Response<HandleExternalCommitResponse>, tonic::Status> {
let obj = request.get_ref();
if !self.known_state_id(obj.state_id) {
return Err(tonic::Status::new(
tonic::Code::InvalidArgument,
"Invalid state ID",
));
}

let obj = request.get_ref();
let commit = String::from("commit");
let commit_in = String::from_utf8(obj.commit.clone()).unwrap();
if commit != commit_in {
return Err(tonic::Status::new(
tonic::Code::InvalidArgument,
"Invalid commit",
));
}

let resp = HandleExternalCommitResponse {
state_id: self.new_state_id(),
epoch_authenticator: String::from("epoch_authenticator").into_bytes(),
};

Ok(Response::new(resp)) // TODO
Expand Down

0 comments on commit 437dd3b

Please sign in to comment.