From 92928309b2f0e274a6103b21a650eb07e78f88ea Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 24 Mar 2015 15:36:11 +0100 Subject: [PATCH] p2p/discover: add version number to ping packet The primary motivation for doing this right now is that old PoC 8 nodes and newer PoC 9 nodes keep discovering each other, causing handshake failures. --- p2p/discover/udp.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go index 69e9f3c2e..738a01fb7 100644 --- a/p2p/discover/udp.go +++ b/p2p/discover/udp.go @@ -16,11 +16,14 @@ import ( var log = logger.NewLogger("P2P Discovery") +const Version = 3 + // Errors var ( errPacketTooSmall = errors.New("too small") errBadHash = errors.New("bad hash") errExpired = errors.New("expired") + errBadVersion = errors.New("version mismatch") errTimeout = errors.New("RPC timeout") errClosed = errors.New("socket closed") ) @@ -45,6 +48,7 @@ const ( // RPC request structures type ( ping struct { + Version uint // must match Version IP string // our IP Port uint16 // our port Expiration uint64 @@ -169,6 +173,7 @@ func (t *udp) ping(e *Node) error { // TODO: maybe check for ReplyTo field in callback to measure RTT errc := t.pending(e.ID, pongPacket, func(interface{}) bool { return true }) t.send(e, pingPacket, ping{ + Version: Version, IP: t.self.IP.String(), Port: uint16(t.self.TCPPort), Expiration: uint64(time.Now().Add(expiration).Unix()), @@ -371,6 +376,9 @@ func (req *ping) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte) er if expired(req.Expiration) { return errExpired } + if req.Version != Version { + return errBadVersion + } t.mutex.Lock() // Note: we're ignoring the provided IP address right now n := t.bumpOrAdd(fromID, from)