github.com/Hnampk/fabric@v2.1.1+incompatible/gossip/comm/msg.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package comm
     8  
     9  import (
    10  	proto "github.com/hyperledger/fabric-protos-go/gossip"
    11  	"github.com/hyperledger/fabric/gossip/protoext"
    12  	"github.com/pkg/errors"
    13  )
    14  
    15  // ReceivedMessageImpl is an implementation of ReceivedMessage
    16  type ReceivedMessageImpl struct {
    17  	*protoext.SignedGossipMessage
    18  	conn     *connection
    19  	connInfo *protoext.ConnectionInfo
    20  }
    21  
    22  // GetSourceEnvelope Returns the Envelope the ReceivedMessage was
    23  // constructed with
    24  func (m *ReceivedMessageImpl) GetSourceEnvelope() *proto.Envelope {
    25  	return m.Envelope
    26  }
    27  
    28  // Respond sends a msg to the source that sent the ReceivedMessageImpl
    29  func (m *ReceivedMessageImpl) Respond(msg *proto.GossipMessage) {
    30  	sMsg, err := protoext.NoopSign(msg)
    31  	if err != nil {
    32  		err = errors.WithStack(err)
    33  		m.conn.logger.Errorf("Failed creating SignedGossipMessage: %+v", err)
    34  		return
    35  	}
    36  	m.conn.send(sMsg, func(e error) {}, blockingSend)
    37  }
    38  
    39  // GetGossipMessage returns the inner GossipMessage
    40  func (m *ReceivedMessageImpl) GetGossipMessage() *protoext.SignedGossipMessage {
    41  	return m.SignedGossipMessage
    42  }
    43  
    44  // GetConnectionInfo returns information about the remote peer
    45  // that send the message
    46  func (m *ReceivedMessageImpl) GetConnectionInfo() *protoext.ConnectionInfo {
    47  	return m.connInfo
    48  }
    49  
    50  // Ack returns to the sender an acknowledgement for the message
    51  func (m *ReceivedMessageImpl) Ack(err error) {
    52  	ackMsg := &proto.GossipMessage{
    53  		Nonce: m.GetGossipMessage().Nonce,
    54  		Content: &proto.GossipMessage_Ack{
    55  			Ack: &proto.Acknowledgement{},
    56  		},
    57  	}
    58  	if err != nil {
    59  		ackMsg.GetAck().Error = err.Error()
    60  	}
    61  	m.Respond(ackMsg)
    62  }