-
Notifications
You must be signed in to change notification settings - Fork 4
/
messaging.go
59 lines (49 loc) · 1.38 KB
/
messaging.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
package destiny
import (
"github.com/gogo/protobuf/proto"
"github.com/ibalajiarun/go-consensus/peer/peerpb"
pb "github.com/ibalajiarun/go-consensus/protocols/destiny/destinypb"
)
func (s *destiny) enqueueForSending(to peerpb.PeerID, mm []byte, certificate []byte) {
cm := peerpb.Message{
Content: mm,
Certificate: certificate,
To: to,
From: s.id,
}
s.msgs = append(s.msgs, cm)
}
func (s *destiny) marshall(m proto.Message) []byte {
dMsg := pb.WrapDestinyMessage(m)
mBytes, err := proto.Marshal(dMsg)
if err != nil {
panic("unable to marshall")
}
return mBytes
}
func (s *destiny) sendTo(to peerpb.PeerID, mBytes []byte, sign []byte) {
// sdbftMsg := pb.WrapSDBFTMessage(m)
// mBytes, err := proto.Marshal(sdbftMsg)
// if err != nil {
// panic("unable to marshall")
// }
// cert := s.certifier.CreateSignedCertificate(mBytes, 0)
s.enqueueForSending(to, mBytes, sign)
}
func (s *destiny) broadcast(mBytes []byte, sendToSelf bool, sign []byte) {
// s.logger.Debugf("Broadcasting %v", m)
// sdbftMsg := pb.WrapSDBFTMessage(m)
// mBytes, err := proto.Marshal(sdbftMsg)
// if err != nil {
// panic("unable to marshall")
// }
// cert := s.certifier.CreateSignedCertificate(mBytes, 0)
for _, node := range s.nodes {
if sendToSelf || node != s.id {
s.enqueueForSending(node, mBytes, sign)
}
}
}
func (s *destiny) ClearMsgs() {
s.msgs = nil
}