diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-24 22:36:11 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-04-01 21:53:04 +0800 |
commit | 92928309b2f0e274a6103b21a650eb07e78f88ea (patch) | |
tree | 472d6608a559485c96da1e3766081b93eab16d9d | |
parent | 101ea1a1e8e8f7b0592dbd06e4eca8432e2e2527 (diff) | |
download | go-tangerine-92928309b2f0e274a6103b21a650eb07e78f88ea.tar.gz go-tangerine-92928309b2f0e274a6103b21a650eb07e78f88ea.tar.zst go-tangerine-92928309b2f0e274a6103b21a650eb07e78f88ea.zip |
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.
-rw-r--r-- | p2p/discover/udp.go | 8 |
1 files changed, 8 insertions, 0 deletions
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) |