-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Data types, such as dtos and errors, used in the broadcast implementation
- Loading branch information
1 parent
aefe0af
commit 6804a92
Showing
4 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters