github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/gossip/comm/msg.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package comm 18 19 import ( 20 "sync" 21 22 proto "github.com/hyperledger/fabric/protos/gossip" 23 ) 24 25 // ReceivedMessageImpl is an implementation of ReceivedMessage 26 type ReceivedMessageImpl struct { 27 *proto.SignedGossipMessage 28 lock sync.Locker 29 conn *connection 30 connInfo *proto.ConnectionInfo 31 } 32 33 // GetSourceEnvelope Returns the Envelope the ReceivedMessage was 34 // constructed with 35 func (m *ReceivedMessageImpl) GetSourceEnvelope() *proto.Envelope { 36 return m.Envelope 37 } 38 39 // Respond sends a msg to the source that sent the ReceivedMessageImpl 40 func (m *ReceivedMessageImpl) Respond(msg *proto.GossipMessage) { 41 sMsg, err := msg.NoopSign() 42 if err != nil { 43 m.conn.logger.Error("Failed creating SignedGossipMessage:", err) 44 return 45 } 46 m.conn.send(sMsg, func(e error) {}) 47 } 48 49 // GetGossipMessage returns the inner GossipMessage 50 func (m *ReceivedMessageImpl) GetGossipMessage() *proto.SignedGossipMessage { 51 return m.SignedGossipMessage 52 } 53 54 // GetConnectionInfo returns information about the remote peer 55 // that send the message 56 func (m *ReceivedMessageImpl) GetConnectionInfo() *proto.ConnectionInfo { 57 return m.connInfo 58 }