-
Notifications
You must be signed in to change notification settings - Fork 9
/
multicast.go
82 lines (71 loc) · 2 KB
/
multicast.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package multicast
import (
"context"
"github.com/gauss-project/aurorafs/pkg/boson"
"github.com/gauss-project/aurorafs/pkg/multicast/model"
"github.com/gauss-project/aurorafs/pkg/multicast/pb"
"github.com/gauss-project/aurorafs/pkg/rpc"
)
type GroupInterface interface {
Multicast(info *pb.MulticastMsg, skip ...boson.Address) error
AddGroup(groups []model.ConfigNodeGroup) error
RemoveGroup(gid boson.Address, gType model.GType) error
Snapshot() *model.KadParams
StartDiscover()
SubscribeLogContent(n *rpc.Notifier, sub *rpc.Subscription)
SubscribeMulticastMsg(n *rpc.Notifier, sub *rpc.Subscription, gid boson.Address) (err error)
GetGroupPeers(groupName string) (out *GroupPeers, err error)
GetOptimumPeer(groupName string) (peer boson.Address, err error)
GetSendStream(ctx context.Context, gid, dest boson.Address) (out SendStreamCh, err error)
SendReceive(ctx context.Context, data []byte, gid, dest boson.Address) (result []byte, err error)
Send(ctx context.Context, data []byte, gid, dest boson.Address) (err error)
}
// Message multicast message
type Message struct {
ID uint64
CreateTime int64
GID boson.Address
Origin boson.Address
Data []byte
From boson.Address
}
type GroupMessage struct {
SessionID rpc.ID `json:"sessionID,omitempty"`
GID boson.Address `json:"gid"`
Data []byte `json:"data"`
From boson.Address `json:"from"`
}
type LogContent struct {
Event string
Time int64 // ms
Data Message
}
type GroupPeers struct {
Connected []boson.Address `json:"connected"`
Keep []boson.Address `json:"keep"`
}
type SendOption int
const (
SendOnly SendOption = iota
SendReceive
SendStream
)
func (s SendOption) String() string {
switch s {
case SendOnly:
return "SendOnly"
case SendReceive:
return "SendReceive"
case SendStream:
return "SendStream"
default:
return ""
}
}
type SendStreamCh struct {
Read chan []byte
ReadErr chan error
Write chan []byte
WriteErr chan error
Close chan struct{}
}