示例#1
0
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
}
示例#2
0
//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
0
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
0
//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

}