Skip to content

Commit

Permalink
refactor(protoc): better naming on broadcast options in protogen
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksander-vedvik committed Feb 27, 2024
1 parent 3703fe1 commit fcd720b
Show file tree
Hide file tree
Showing 19 changed files with 458 additions and 316 deletions.
29 changes: 28 additions & 1 deletion broadcastTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,42 @@ func WithSubset(srvAddrs ...string) BroadcastOption {
}
}

func WithGossip(percentage float32) BroadcastOption {
func WithGossip(percentage float32, ttl int) BroadcastOption {
return func(b *BroadcastOptions) {
b.GossipPercentage = percentage
b.TTL = ttl
}
}

func WithTTL(ttl int) BroadcastOption {
return func(b *BroadcastOptions) {
b.TTL = ttl
}
}

func WithDeadline(deadline time.Time) BroadcastOption {
return func(b *BroadcastOptions) {
b.Deadline = deadline
}
}

func WithoutSelf() BroadcastOption {
return func(b *BroadcastOptions) {
b.SkipSelf = true
}
}

func WithoutUniquenessChecks() BroadcastOption {
return func(b *BroadcastOptions) {
b.OmitUniquenessChecks = true
}
}

type BroadcastOptions struct {
ServerAddresses []string
GossipPercentage float32
TTL int
Deadline time.Time
OmitUniquenessChecks bool
SkipSelf bool
}
Expand Down
179 changes: 94 additions & 85 deletions cmd/protoc-gen-gorums/dev/zorums.pb.go

Large diffs are not rendered by default.

45 changes: 35 additions & 10 deletions cmd/protoc-gen-gorums/dev/zorums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,50 @@ service ZorumsService {
option (gorums.quorumcall) = true;
}

// Multiparty with QuorumCall.
rpc Multiparty(Request) returns (Response) {
// QuorumCall with broadcast option enables the server handler to broadcast.
// The handler still works like a regular QuorumCall from the client's
// perpective.
rpc QuorumCallWithBroadcast(Request) returns (Response) {
option (gorums.quorumcall) = true;
option (gorums.broadcast) = true;
}

// Multiparty, internal handler.
rpc MultipartyInternal(Request) returns (google.protobuf.Empty) {
// An rpc method with only the broadcast option specified will create a
// server handler which can be used to broadcast. The handler will not
// be exposed to the client, only to server. Hence, it is named internal.
rpc BroadcastInternal(Request) returns (google.protobuf.Empty) {
option (gorums.broadcast) = true;
}

// Multiparty, send to client handler.
rpc MultipartyClientHandler(Request) returns (Response) {
option (gorums.broadcastrequest) = true;
// The BroadcastCall is similar to a QuorumCall, but it enables the servers
// to send the response to a client-side server handler. I.e. the client
// needs to register a client-side server and register it.
//
// NOTE: this will NOT create a broadcast method, meaning servers cannot
// call this method (only clients)
rpc BroadcastWithClientHandler1(Request) returns (Response) {
option (gorums.broadcastcall) = true;
}

// Multiparty, send to client handler.
rpc MultipartyClientHandler2(Request) returns (ClientResponse) {
option (gorums.broadcastrequest) = true;
// The BroadcastCall is similar to a QuorumCall, but it enables the servers
// to send the response to a client-side server handler. I.e. the client
// needs to register a client-side server and register it.
//
// NOTE: this will NOT create a broadcast method, meaning servers cannot
// call this method (only clients)
rpc BroadcastWithClientHandler2(Request) returns (ClientResponse) {
option (gorums.broadcastcall) = true;
}

// The BroadcastCall is similar to a QuorumCall, but it enables the servers
// to send the response to a client-side server handler. I.e. the client
// needs to register a client-side server and register it.
//
// NOTE: this WILL create a broadcast method, meaning servers (and clients)
// can call this method
rpc BroadcastWithClientHandlerAndBroadcastOption(Request) returns (ClientResponse) {
option (gorums.broadcastcall) = true;
option (gorums.broadcast) = true;
}

// ------------------------------------------------------------------
Expand Down
16 changes: 12 additions & 4 deletions cmd/protoc-gen-gorums/dev/zorums_broadcast_gorums.pb.go

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

198 changes: 198 additions & 0 deletions cmd/protoc-gen-gorums/dev/zorums_broadcastcall_gorums.pb.go

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

Loading

0 comments on commit fcd720b

Please sign in to comment.