aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/discover/udp.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-05-14 02:34:10 +0800
committerFelix Lange <fjl@twurst.com>2015-05-14 02:34:10 +0800
commitb2119d8931b054fe85cd80c02a5c9db033f61ab3 (patch)
tree7cf12ba3386d288a08614866b5d0e922381cdf88 /p2p/discover/udp.go
parent3edc4698fed7f22df8b6cb3574f1c3b633094c4e (diff)
parent8eef2b765a035b2bb1dd59c3630649ca371152ff (diff)
downloadgo-tangerine-b2119d8931b054fe85cd80c02a5c9db033f61ab3.tar
go-tangerine-b2119d8931b054fe85cd80c02a5c9db033f61ab3.tar.gz
go-tangerine-b2119d8931b054fe85cd80c02a5c9db033f61ab3.tar.bz2
go-tangerine-b2119d8931b054fe85cd80c02a5c9db033f61ab3.tar.lz
go-tangerine-b2119d8931b054fe85cd80c02a5c9db033f61ab3.tar.xz
go-tangerine-b2119d8931b054fe85cd80c02a5c9db033f61ab3.tar.zst
go-tangerine-b2119d8931b054fe85cd80c02a5c9db033f61ab3.zip
Merge pull request #965 from subtly/patch-1
Better UDP & interop. Limit all received datagrams to 1280bytes.
Diffstat (limited to 'p2p/discover/udp.go')
-rw-r--r--p2p/discover/udp.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go
index 1213c12c8..2b215b45c 100644
--- a/p2p/discover/udp.go
+++ b/p2p/discover/udp.go
@@ -402,7 +402,7 @@ func encodePacket(priv *ecdsa.PrivateKey, ptype byte, req interface{}) ([]byte,
// readLoop runs in its own goroutine. it handles incoming UDP packets.
func (t *udp) readLoop() {
defer t.conn.Close()
- buf := make([]byte, 4096) // TODO: good buffer size
+ buf := make([]byte, 1280)
for {
nbytes, from, err := t.conn.ReadFromUDP(buf)
if err != nil {
@@ -510,9 +510,15 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte
closestrpc[i] = nodeToRPC(n)
}
t.send(from, neighborsPacket, neighbors{
- Nodes: closestrpc,
+ Nodes: closestrpc[:13],
Expiration: uint64(time.Now().Add(expiration).Unix()),
})
+ if len(closestrpc) > 13 {
+ t.send(from, neighborsPacket, neighbors{
+ Nodes: closestrpc[13:],
+ Expiration: uint64(time.Now().Add(expiration).Unix()),
+ })
+ }
return nil
}