當前位置: 首頁>>代碼示例>>Golang>>正文


Golang IMsg.IsPeer2Peer方法代碼示例

本文整理匯總了Golang中github.com/FactomProject/factomd/common/interfaces.IMsg.IsPeer2Peer方法的典型用法代碼示例。如果您正苦於以下問題:Golang IMsg.IsPeer2Peer方法的具體用法?Golang IMsg.IsPeer2Peer怎麽用?Golang IMsg.IsPeer2Peer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/FactomProject/factomd/common/interfaces.IMsg的用法示例。


在下文中一共展示了IMsg.IsPeer2Peer方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Send

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
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:26,代碼來源:p2pProxy.go

示例2: Peers

func Peers(fnode *FactomNode) {
	cnt := 0
	for {
		for i := 0; i < 100 && len(fnode.State.APIQueue()) > 0; i++ {
			select {
			case msg := <-fnode.State.APIQueue():
				if msg == nil {
					break
				}
				repeatHash := msg.GetRepeatHash()
				if repeatHash == nil {
					fmt.Println("dddd ERROR!", msg.String())
					break
				}
				cnt++
				msg.SetOrigin(0)
				if fnode.State.Replay.IsTSValid_(constants.NETWORK_REPLAY, repeatHash.Fixed(),
					msg.GetTimestamp(),
					fnode.State.GetTimestamp()) {

					fnode.MLog.add2(fnode, false, fnode.State.FactomNodeName, "API", true, msg)
					if len(fnode.State.InMsgQueue()) < 9000 {
						fnode.State.InMsgQueue() <- msg
					}
				}
			default:

			}
		}

		// Put any broadcasts from our peers into our BroadcastIn queue
		for i, peer := range fnode.Peers {
			for j := 0; j < 100; j++ {

				var msg interfaces.IMsg
				var err error

				if !fnode.State.GetNetStateOff() {
					msg, err = peer.Recieve()
				}

				if msg == nil {
					// Recieve is not blocking; nothing to do, we get a nil.
					break
				}

				cnt++

				if err != nil {
					fmt.Println("ERROR recieving message on", fnode.State.FactomNodeName+":", err)
					break
				}

				msg.SetOrigin(i + 1)
				if fnode.State.Replay.IsTSValid_(constants.NETWORK_REPLAY, msg.GetRepeatHash().Fixed(),
					msg.GetTimestamp(),
					fnode.State.GetTimestamp()) {
					//if state.GetOut() {
					//	fnode.State.Println("In Comming!! ",msg)
					//}
					in := "PeerIn"
					if msg.IsPeer2Peer() {
						in = "P2P In"
					}
					nme := fmt.Sprintf("%s %d", in, i+1)

					fnode.MLog.add2(fnode, false, peer.GetNameTo(), nme, true, msg)

					// Ignore messages if there are too many.
					if len(fnode.State.InMsgQueue()) < 9000 {
						fnode.State.InMsgQueue() <- msg
					}

				} else {
					fnode.MLog.add2(fnode, false, peer.GetNameTo(), "PeerIn", false, msg)
				}
			}
		}
		if cnt == 0 {
			time.Sleep(50 * time.Millisecond)
		}
		cnt = 0
	}
}
開發者ID:FactomProject,項目名稱:factomd,代碼行數:84,代碼來源:NetworkProcessorNet.go


注:本文中的github.com/FactomProject/factomd/common/interfaces.IMsg.IsPeer2Peer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。