Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
messages/protobuf: Rename fields in Protobuf definitions
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Fedorov <sergey.fedorov@neclab.eu>
  • Loading branch information
Sergey Fedorov committed Jan 9, 2020
1 parent baf72c2 commit 774f914
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 74 deletions.
4 changes: 2 additions & 2 deletions messages/protobuf/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func (m *commit) CertifiedPayload() []byte {
}

func (m *commit) UIBytes() []byte {
return m.pbMsg.ReplicaUi
return m.pbMsg.Ui
}

func (m *commit) SetUIBytes(uiBytes []byte) {
m.pbMsg.ReplicaUi = uiBytes
m.pbMsg.Ui = uiBytes
}

func (commit) ImplementsReplicaMessage() {}
Expand Down
10 changes: 5 additions & 5 deletions messages/protobuf/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (*impl) NewReply(r, cl uint32, seq uint64, res []byte) messages.Reply {
}

func typedMessageFromPb(pbMsg *pb.Message) (messages.Message, error) {
switch t := pbMsg.Type.(type) {
switch t := pbMsg.Typed.(type) {
case *pb.Message_Request:
return newRequestFromPb(t.Request), nil
case *pb.Message_Reply:
Expand All @@ -73,13 +73,13 @@ func marshalMessage(m proto.Message) ([]byte, error) {
pbMsg := &pb.Message{}
switch m := m.(type) {
case *pb.Request:
pbMsg.Type = &pb.Message_Request{Request: m}
pbMsg.Typed = &pb.Message_Request{Request: m}
case *pb.Reply:
pbMsg.Type = &pb.Message_Reply{Reply: m}
pbMsg.Typed = &pb.Message_Reply{Reply: m}
case *pb.Prepare:
pbMsg.Type = &pb.Message_Prepare{Prepare: m}
pbMsg.Typed = &pb.Message_Prepare{Prepare: m}
case *pb.Commit:
pbMsg.Type = &pb.Message_Commit{Commit: m}
pbMsg.Typed = &pb.Message_Commit{Commit: m}
default:
panic("marshaling unknown message type")
}
Expand Down
4 changes: 2 additions & 2 deletions messages/protobuf/pb/authen.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func AuthenBytesFromCommit(m *Commit) []byte {

func writeAuthenBytesFromRequest(buf io.Writer, m *Request) {
_ = binary.Write(buf, binary.BigEndian, m.GetSeq())
_, _ = buf.Write(hashsum(m.GetPayload()))
_, _ = buf.Write(hashsum(m.GetOperation()))
}

func writeAuthenBytesFromReply(buf io.Writer, m *Reply) {
Expand All @@ -80,7 +80,7 @@ func writeAuthenBytesFromCommit(buf io.Writer, m *Commit) {
prep := m.GetPrepare()
_ = binary.Write(buf, binary.BigEndian, prep.GetReplicaId())
writeAuthenBytesFromPrepare(buf, prep)
_, _ = buf.Write(prep.GetReplicaUi())
_, _ = buf.Write(prep.GetUi())
}

func hashsum(data []byte) []byte {
Expand Down
105 changes: 52 additions & 53 deletions messages/protobuf/pb/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions messages/protobuf/pb/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum MessageType {
}

message Message{
oneof type {
oneof typed {
Request request = 1;
Reply reply = 2;
Prepare prepare = 3;
Expand All @@ -39,7 +39,7 @@ message Message{
message Request {
uint32 client_id = 1; // c: client id
uint64 seq = 2; // seq: request sequence per client
bytes payload = 3; // op: operation payload
bytes operation = 3; // op: operation payload
bytes signature = 4; // client signature
}

Expand All @@ -55,11 +55,11 @@ message Prepare {
uint32 replica_id = 1; // s_i: replica id
uint64 view = 2; // v: view
Request request = 3; // m: request message
bytes replica_ui = 4; // UI_i: replica UI
bytes ui = 4; // UI_i: replica UI
}

message Commit {
uint32 replica_id = 1; // s_j: replica id
Prepare prepare = 2; // prepare message
bytes replica_ui = 3; // UI_j: replica UI
bytes ui = 3; // UI_j: replica UI
}
4 changes: 2 additions & 2 deletions messages/protobuf/pb/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func RequestFromAPI(req messages.Request) *Request {
return &Request{
ClientId: req.ClientID(),
Seq: req.Sequence(),
Payload: req.Operation(),
Operation: req.Operation(),
Signature: req.Signature(),
}
}
Expand All @@ -42,6 +42,6 @@ func PrepareFromAPI(prep messages.Prepare) *Prepare {
ReplicaId: prep.ReplicaID(),
View: prep.View(),
Request: RequestFromAPI(prep.Request()),
ReplicaUi: prep.UIBytes(),
Ui: prep.UIBytes(),
}
}
4 changes: 2 additions & 2 deletions messages/protobuf/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func (m *prepare) CertifiedPayload() []byte {
}

func (m *prepare) UIBytes() []byte {
return m.pbMsg.ReplicaUi
return m.pbMsg.Ui
}

func (m *prepare) SetUIBytes(uiBytes []byte) {
m.pbMsg.ReplicaUi = uiBytes
m.pbMsg.Ui = uiBytes
}

func (prepare) ImplementsReplicaMessage() {}
Expand Down
8 changes: 4 additions & 4 deletions messages/protobuf/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ type request struct {

func newRequest(cl uint32, seq uint64, op []byte) *request {
return &request{pbMsg: &pb.Request{
ClientId: cl,
Seq: seq,
Payload: op,
ClientId: cl,
Seq: seq,
Operation: op,
}}
}

Expand All @@ -48,7 +48,7 @@ func (m *request) Sequence() uint64 {
}

func (m *request) Operation() []byte {
return m.pbMsg.GetPayload()
return m.pbMsg.GetOperation()
}

func (m *request) SignedPayload() []byte {
Expand Down

0 comments on commit 774f914

Please sign in to comment.