func (f *P2PProxy) Send(msg interfaces.IMsg) error { f.logMessage(msg, false) // NODE_TALK_FIX data, err := msg.MarshalBinary() if err != nil { fmt.Println("ERROR on Send: ", err) return err } hash := fmt.Sprintf("%x", msg.GetMsgHash().Bytes()) appType := fmt.Sprintf("%d", msg.Type()) message := factomMessage{message: data, peerHash: msg.GetNetworkOrigin(), appHash: hash, appType: appType} switch { case !msg.IsPeer2Peer(): message.peerHash = p2p.BroadcastFlag f.trace(message.appHash, message.appType, "P2PProxy.Send() - BroadcastFlag", "a") case msg.IsPeer2Peer() && 0 == len(message.peerHash): // directed, with no direction of who to send it to message.peerHash = p2p.RandomPeerFlag f.trace(message.appHash, message.appType, "P2PProxy.Send() - RandomPeerFlag", "a") default: f.trace(message.appHash, message.appType, "P2PProxy.Send() - Addressed by hash", "a") } if msg.IsPeer2Peer() && 1 < f.debugMode { fmt.Printf("%s Sending directed to: %s message: %+v\n", time.Now().String(), message.peerHash, msg.String()) } p2p.BlockFreeChannelSend(f.BroadcastOut, message) return nil }
func (p *P2PProxy) logMessage(msg interfaces.IMsg, received bool) { if 2 < p.debugMode { // if constants.DBSTATE_MSG == msg.Type() { // fmt.Printf("AppMsgLogging: \n Type: %s \n Network Origin: %s \n Message: %s", msg.Type(), msg.GetNetworkOrigin(), msg.String()) // } hash := fmt.Sprintf("%x", msg.GetMsgHash().Bytes()) time := time.Now().Unix() ml := messageLog{hash: hash, received: received, time: time, mtype: msg.Type(), target: msg.GetNetworkOrigin()} p2p.BlockFreeChannelSend(p.logging, ml) } }