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


Golang peer.NodePeer類代碼示例

本文整理匯總了Golang中github.com/marcosQuesada/mesh/peer.NodePeer的典型用法代碼示例。如果您正苦於以下問題:Golang NodePeer類的具體用法?Golang NodePeer怎麽用?Golang NodePeer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: exists

func (r *defaultRouter) exists(p peer.NodePeer) bool {
	r.mutex.Lock()
	defer r.mutex.Unlock()

	var node node.Node = p.Node()
	_, ok := r.peers[node.String()]

	return ok
}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:9,代碼來源:router.go

示例2: HandleHello

//HandleHello Request
func (r *defaultRouter) HandleHello(c peer.NodePeer, msg message.Message) (message.Message, error) {
	c.Identify(msg.(*message.Hello).From)
	if r.exists(c) {
		return &message.Abort{Id: msg.(*message.Hello).Id, From: r.from}, nil
	}

	c.State(peer.PeerStatusConnecting)

	return &message.Welcome{Id: msg.(*message.Hello).Id, From: r.from}, nil
}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:11,代碼來源:router_handlers.go

示例3: HandleAck

func (r *defaultRouter) HandleAck(c peer.NodePeer, msg message.Message) (message.Message, error) {
	err := r.accept(c)
	if err != nil {
		log.Println("Unexpected Error accepting Peer on HandleAck ", c.Node(), "msg:", msg)
	}

	c.State(peer.PeerStatusConnected)
	r.eventChan <- &peer.OnPeerConnectedEvent{msg.(*message.Ack).From, peer.PeerStatusConnected, c.Mode()}

	go r.watcher.Watch(c)

	return nil, nil
}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:13,代碼來源:router_handlers.go

示例4: remove

func (r *defaultRouter) remove(p peer.NodePeer) error {
	r.mutex.Lock()
	defer r.mutex.Unlock()

	node := p.Node()
	if _, ok := r.peers[node.String()]; !ok {
		return fmt.Errorf("Peer Not found")
	}

	delete(r.peers, node.String())
	delete(r.peerIDs, p.Id())

	return nil
}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:14,代碼來源:router.go

示例5: accept

func (r *defaultRouter) accept(p peer.NodePeer) error {
	r.mutex.Lock()
	defer r.mutex.Unlock()

	var node node.Node = p.Node()
	if _, ok := r.peers[node.String()]; ok {
		return fmt.Errorf("Peer: %s Already registered", node.String())
	}

	r.peers[node.String()] = p
	r.peerIDs[p.Id()] = true

	return nil
}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:14,代碼來源:router.go

示例6: HandleAbort

func (r *defaultRouter) HandleAbort(c peer.NodePeer, msg message.Message) (message.Message, error) {
	r.eventChan <- &peer.OnPeerAbortedEvent{c.Node(), peer.PeerStatusAbort}
	c.State(peer.PeerStatusAbort)
	c.Exit()

	return nil, nil
}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:7,代碼來源:router_handlers.go

示例7: HandleWelcome

//HandleWelcome Request
func (r *defaultRouter) HandleWelcome(c peer.NodePeer, msg message.Message) (message.Message, error) {
	err := r.accept(c)
	if err != nil {
		r.eventChan <- &peer.OnPeerErroredEvent{c.Node(), peer.PeerStatusError, err}

		return &message.Error{Id: msg.(*message.Welcome).Id, From: r.from}, err
	}
	c.State(peer.PeerStatusConnected)
	r.eventChan <- &peer.OnPeerConnectedEvent{c.Node(), peer.PeerStatusConnected, c.Mode()}

	go r.watcher.Watch(c)

	return &message.Ack{Id: msg.(*message.Welcome).Id, From: r.from}, nil

}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:16,代碼來源:router_handlers.go

示例8: HandleError

func (r *defaultRouter) HandleError(c peer.NodePeer, msg message.Message) (message.Message, error) {
	log.Println("HandleError ", c.Node(), "msg:", msg)

	return nil, nil
}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:5,代碼來源:router_handlers.go

示例9: HandleCommand

func (r *Coordinator) HandleCommand(c peer.NodePeer, msg message.Message) (message.Message, error) {
	from := c.From()
	log.Println("HandleCommand, from peer", from.String())

	return nil, nil
}
開發者ID:sp-marcos-quesada,項目名稱:mesh,代碼行數:6,代碼來源:coordinator_handlers.go


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