-
Notifications
You must be signed in to change notification settings - Fork 20
/
group.go
38 lines (32 loc) · 719 Bytes
/
group.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
package gyre
import (
"github.com/zeromq/gyre/zre/msg"
)
type group struct {
name string // Group name
peers map[string]*peer // Peers in group
}
// newGroup creates a new group
func newGroup(name string) *group {
return &group{
name: name,
peers: make(map[string]*peer),
}
}
// Join adds peer to group. Ignore duplicate joins
func (g *group) join(peer *peer) {
g.peers[peer.identity] = peer
peer.status++
}
// Leave removes peer from group
func (g *group) leave(peer *peer) {
delete(g.peers, peer.identity)
peer.status++
}
// Send sends message to all peers in group
func (g *group) send(m msg.Transit) {
for _, peer := range g.peers {
cloned := msg.Clone(m)
peer.send(cloned)
}
}