本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}