pex_reactor.go
func (r *PEXReactor) Receive(chID byte, src *Peer, msgBytes []byte) {
	srcAddr := src.Connection().RemoteAddress
	srcAddrStr := srcAddr.String()

	r.IncrementMsgCountForPeer(srcAddrStr)
	if r.ReachedMaxMsgCountForPeer(srcAddrStr) {
		log.Warn("Maximum number of messages reached for peer", "peer", srcAddrStr)
		// TODO remove src from peers?
		return
	}

	_, msg, err := DecodeMessage(msgBytes)
	if err != nil {
		log.Warn("Error decoding message", "error", err)
		return
	}
	log.Notice("Received message", "msg", msg)

	switch msg := msg.(type) {
	case *pexRequestMessage:
		// src requested some peers.
		r.SendAddrs(src, r.book.GetSelection())
	case *pexAddrsMessage:
		// We received some peer addresses from src.
		// (We don't want to get spammed with bad peers)
		for _, addr := range msg.Addrs {
			if addr != nil {
				r.book.AddAddress(addr, srcAddr)
			}
		}
	default:
		log.Warn(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg)))
	}
}
func (r *PEXReactor) Receive(chID byte, src *Peer, msgBytes []byte) {
	srcAddr := src.Connection().RemoteAddress
	srcAddrStr := srcAddr.String()

	r.IncrementMsgCountForPeer(srcAddrStr)
	if r.ReachedMaxMsgCountForPeer(srcAddrStr) {
		log.Warn("Maximum number of messages reached for peer", "peer", srcAddrStr)
		// TODO remove src from peers?
		return
	}

	_, msg, err := DecodeMessage(msgBytes)
	if err != nil {
		log.Warn("Error decoding message", "error", err)
		return
	}
	log.Notice("Received message", "msg", msg)

	switch msg := msg.(type) {
	case *pexRequestMessage:
		// src requested some peers.
		r.SendAddrs(src, r.book.GetSelection())
	case *pexAddrsMessage:
		// We received some peer addresses from src.
		// (We don't want to get spammed with bad peers)
		for _, addr := range msg.Addrs {
			if addr != nil {
				r.book.AddAddress(addr, srcAddr)
			}
		}
	default:
		log.Warn(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg)))
	}
}
func ( r * PEXReactor ) Receive ( chID byte , src * Peer , msgBytes [ ] byte ) { srcAddr := src . Connection ( ) . RemoteAddress srcAddrStr := srcAddr . String ( ) r . IncrementMsgCountForPeer ( srcAddrStr ) if r . ReachedMaxMsgCountForPeer ( srcAddrStr ) { log . Warn ( " " , " " , srcAddrStr ) // TODO remove src from peers? return } _ , msg , err := DecodeMessage ( msgBytes ) if err != nil { log . Warn ( " " , " " , err ) return } log . Notice ( " " , " " , msg ) switch msg := msg . ( type ) { case * pexRequestMessage : // src requested some peers. r . SendAddrs ( src , r . book . GetSelection ( ) ) case * pexAddrsMessage : // We received some peer addresses from src. // (We don't want to get spammed with bad peers) for _ , addr := range msg . Addrs { if addr != nil { r . book . AddAddress ( addr , srcAddr ) } } default : log . Warn ( fmt . Sprintf ( " " , reflect . TypeOf ( msg ) ) ) } }
// Receive implements Reactor by handling incoming PEX messages.
Receive implements Reactor by handling incoming PEX messages .