Skip to content

Commit

Permalink
refactor(protoc): incorporated replySpec into qSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksander-vedvik committed Feb 29, 2024
1 parent 5b734e0 commit 429ea54
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 34 deletions.
6 changes: 6 additions & 0 deletions broadcastTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ func WithoutUniquenessChecks() BroadcastOption {
}
}

// not sure if this is necessary because the implementer
// can decide to run the broadcast in a go routine.
func WithoutWaiting() BroadcastOption {
return func(b *BroadcastOptions) {}
}

type BroadcastOptions struct {
ServerAddresses []string
GossipPercentage float32
Expand Down
7 changes: 3 additions & 4 deletions cmd/protoc-gen-gorums/dev/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
// procedure calls may be invoked.
type Configuration struct {
gorums.RawConfiguration
nodes []*Node
qspec QuorumSpec
srv *clientServerImpl
replySpec ReplySpec
nodes []*Node
qspec QuorumSpec
srv *clientServerImpl
}

// ConfigurationFromRaw returns a new Configuration from the given raw configuration and QuorumSpec.
Expand Down
3 changes: 1 addition & 2 deletions cmd/protoc-gen-gorums/dev/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type clientServerImpl struct {
grpcServer *grpc.Server
}

func (c *Configuration) RegisterClientServer(listenAddr string, replySpec ReplySpec, opts ...grpc.ServerOption) error {
func (c *Configuration) RegisterClientServer(listenAddr string, opts ...grpc.ServerOption) error {
srvImpl := &clientServerImpl{
grpcServer: grpc.NewServer(opts...),
}
Expand All @@ -71,6 +71,5 @@ func (c *Configuration) RegisterClientServer(listenAddr string, replySpec ReplyS
go srvImpl.grpcServer.Serve(lis)
srvImpl.ClientServer = srv
c.srv = srvImpl
c.replySpec = replySpec
return nil
}
18 changes: 9 additions & 9 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.

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

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

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

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

6 changes: 3 additions & 3 deletions cmd/protoc-gen-gorums/gengorums/template_broadcastcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func (c *Configuration) {{.Method.GoName}}(ctx context.Context, in *{{in .GenFil
if c.srv == nil {
return nil, fmt.Errorf("a client server is not defined. Use configuration.RegisterClientServer() to define a client server")
}
if c.replySpec == nil {
return nil, fmt.Errorf("a reply spec is not defined. Use configuration.RegisterClientServer() to define a reply spec")
if c.qspec == nil {
return nil, fmt.Errorf("a qspec is not defined.")
}
doneChan, cd := c.srv.AddRequest(ctx, in, gorums.ConvertToType(c.replySpec.{{.Method.GoName}}))
doneChan, cd := c.srv.AddRequest(ctx, in, gorums.ConvertToType(c.qspec.{{.Method.GoName}}QF))
c.RawConfiguration.Multicast(ctx, cd, gorums.WithNoSendWaiting())
response, ok := <-doneChan
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion cmd/protoc-gen-gorums/gengorums/template_clientserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ type ReplySpec interface {
{{- end}}
`

var clientServer = clientServerVariables + clientServerInterface + clientServerDesc + clientServerImplInterface
var clientServer = clientServerVariables + clientServerInterface + clientServerDesc
8 changes: 6 additions & 2 deletions cmd/protoc-gen-gorums/gengorums/template_qspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ type QuorumSpec interface {
// supplied to the {{$method}} method at call time, and may or may not
// be used by the quorum function. If the in parameter is not needed
// you should implement your quorum function with '_ *{{$in}}'.
{{- if isBroadcastCall .}}
{{.GoName}}QF(replies []*{{$out}}) (*{{$out}}, bool)
{{- else}}
{{$method}}QF(in *{{$in}}, replies map[uint32]*{{$out}}) (*{{$customOut}}{{withCorrectable . ", int"}}, bool)
{{- end}}
{{end}}
}
{{end}}
Expand All @@ -34,8 +38,8 @@ type QuorumSpec interface {
// a quorum function; that is, all except multicast and plain gRPC methods.
func qspecMethods(methods []*protogen.Method) (s []*protogen.Method) {
for _, method := range methods {
if hasMethodOption(method, gorums.E_Multicast, gorums.E_Unicast, gorums.E_Broadcastcall) || !hasGorumsCallType(method) {
// ignore multicast, broadcast and non-Gorums methods
if hasMethodOption(method, gorums.E_Multicast, gorums.E_Unicast) || !hasGorumsCallType(method) {
// ignore multicast and non-Gorums methods
continue
}
s = append(s, method)
Expand Down
12 changes: 5 additions & 7 deletions cmd/protoc-gen-gorums/gengorums/template_static.go

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

0 comments on commit 429ea54

Please sign in to comment.