This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
msg.go
64 lines (54 loc) · 1.58 KB
/
msg.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
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package comm
import (
"sync"
proto "github.com/hyperledger/fabric/protos/gossip"
"github.com/pkg/errors"
)
// ReceivedMessageImpl is an implementation of ReceivedMessage
type ReceivedMessageImpl struct {
*proto.SignedGossipMessage
lock sync.Locker
conn *connection
connInfo *proto.ConnectionInfo
}
// GetSourceEnvelope Returns the Envelope the ReceivedMessage was
// constructed with
func (m *ReceivedMessageImpl) GetSourceEnvelope() *proto.Envelope {
return m.Envelope
}
// Respond sends a msg to the source that sent the ReceivedMessageImpl
func (m *ReceivedMessageImpl) Respond(msg *proto.GossipMessage) {
sMsg, err := msg.NoopSign()
if err != nil {
err = errors.WithStack(err)
m.conn.logger.Errorf("Failed creating SignedGossipMessage: %+v", err)
return
}
m.conn.send(sMsg, func(e error) {}, blockingSend)
}
// GetGossipMessage returns the inner GossipMessage
func (m *ReceivedMessageImpl) GetGossipMessage() *proto.SignedGossipMessage {
return m.SignedGossipMessage
}
// GetConnectionInfo returns information about the remote peer
// that send the message
func (m *ReceivedMessageImpl) GetConnectionInfo() *proto.ConnectionInfo {
return m.connInfo
}
// Ack returns to the sender an acknowledgement for the message
func (m *ReceivedMessageImpl) Ack(err error) {
ackMsg := &proto.GossipMessage{
Nonce: m.GetGossipMessage().Nonce,
Content: &proto.GossipMessage_Ack{
Ack: &proto.Acknowledgement{},
},
}
if err != nil {
ackMsg.GetAck().Error = err.Error()
}
m.Respond(ackMsg)
}