Xmit called by other module to broadcast msg
(message interface{})
| 150 | |
| 151 | //Xmit called by other module to broadcast msg |
| 152 | func (this *P2PServer) Xmit(message interface{}) error { |
| 153 | log.Debug() |
| 154 | var msg msgtypes.Message |
| 155 | switch message.(type) { |
| 156 | case *types.Transaction: |
| 157 | log.Debug("[p2p]TX transaction message") |
| 158 | txn := message.(*types.Transaction) |
| 159 | msg = msgpack.NewTxn(txn) |
| 160 | case *msgtypes.ConsensusPayload: |
| 161 | log.Debug("[p2p]TX consensus message") |
| 162 | consensusPayload := message.(*msgtypes.ConsensusPayload) |
| 163 | msg = msgpack.NewConsensus(consensusPayload) |
| 164 | case comm.Uint256: |
| 165 | log.Debug("[p2p]TX block hash message") |
| 166 | hash := message.(comm.Uint256) |
| 167 | // construct inv message |
| 168 | invPayload := msgpack.NewInvPayload(comm.BLOCK, []comm.Uint256{hash}) |
| 169 | msg = msgpack.NewInv(invPayload) |
| 170 | default: |
| 171 | log.Warnf("[p2p]Unknown Xmit message %v , type %v", message, |
| 172 | reflect.TypeOf(message)) |
| 173 | return errors.New("[p2p]Unknown Xmit message type") |
| 174 | } |
| 175 | this.network.Xmit(msg) |
| 176 | return nil |
| 177 | } |
| 178 | |
| 179 | //Send tranfer buffer to peer |
| 180 | func (this *P2PServer) Send(p *peer.Peer, msg msgtypes.Message, |