Skip to content

Commit

Permalink
feat(Broadcast): required datatypes
Browse files Browse the repository at this point in the history
Data types, such as dtos and errors, used in the broadcast implementation
  • Loading branch information
aleksander-vedvik committed Jan 11, 2025
1 parent aefe0af commit 6804a92
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
75 changes: 75 additions & 0 deletions broadcast/dtos/dtos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package dtos

import (
"context"
"google.golang.org/protobuf/reflect/protoreflect"
"time"
)

type Msg interface {
GetBroadcastID() uint64
GetMethod() string
String() string
}

type BroadcastMsg struct {
Ctx context.Context
Options BroadcastOptions
OriginAddr string
Info Info
}

func (msg *BroadcastMsg) GetBroadcastID() uint64 {
return msg.Info.BroadcastID
}

func (msg *BroadcastMsg) GetMethod() string {
return msg.Info.Method
}

func (msg *BroadcastMsg) String() string {
return "broadcast"
}

type ReplyMsg struct {
Info Info
ClientAddr string
Err error
}

func (r *ReplyMsg) GetBroadcastID() uint64 {
return r.Info.BroadcastID
}

func (r *ReplyMsg) GetMethod() string {
return "reply"
}

func (r *ReplyMsg) String() string {
return "reply"
}

type Info struct {
Message protoreflect.ProtoMessage
BroadcastID uint64
Method string
Addr string
OriginMethod string
OriginDigest []byte
OriginSignature []byte
OriginPubKey string
}

type Client struct {
Addr string
SendMsg func(timeout time.Duration, dto *ReplyMsg) error
Close func() error
}

type BroadcastOptions struct {
ServerAddresses []string
AllowDuplication bool
SkipSelf bool
ProgressTo string
RelatedToReq uint64
}
57 changes: 57 additions & 0 deletions broadcast/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package broadcastErrors

type BroadcastIDErr struct{}

func (err BroadcastIDErr) Error() string {
return "wrong broadcastID"
}

type MissingClientReqErr struct{}

func (err MissingClientReqErr) Error() string {
return "has not received client req yet"
}

type AlreadyProcessedErr struct{}

func (err AlreadyProcessedErr) Error() string {
return "already processed request"
}

type ReqFinishedErr struct{}

func (err ReqFinishedErr) Error() string {
return "request has terminated"
}

type ClientReqAlreadyReceivedErr struct{}

func (err ClientReqAlreadyReceivedErr) Error() string {
return "the client req has already been received. The forward req is thus dropped."
}

type MissingReqErr struct{}

func (err MissingReqErr) Error() string {
return "a request has not been created yet."
}

type OutOfOrderErr struct{}

func (err OutOfOrderErr) Error() string {
return "the message is out of order"
}

type ShardDownErr struct{}

func (err ShardDownErr) Error() string {
return "the shard is down"
}

type InvalidAddrErr struct {
Addr string
}

func (err InvalidAddrErr) Error() string {
return "provided Addr is invalid. got: " + err.Addr
}
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/relab/gorums v0.7.0
golang.org/x/term v0.18.0
google.golang.org/grpc v1.62.1
google.golang.org/grpc v1.63.0
google.golang.org/protobuf v1.33.0
)

Expand Down
1 change: 1 addition & 0 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/grpc v1.63.0/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0 h1:rNBFJjBCOgVr9pWD7rs/knKL4FRTKgpZmsRfV214zcA=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0/go.mod h1:Dk1tviKTvMCz5tvh7t+fh94dhmQVHuCt2OzJB3CTW9Y=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
Expand Down

0 comments on commit 6804a92

Please sign in to comment.