From 32268a8135f04e087e0478da32e9f61e6fb95ea9 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 28 Apr 2018 14:41:36 -0400 Subject: [PATCH] limit maxPexMessageSize based on maxAddressSize --- p2p/pex/pex_reactor.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index c6ae4f22d..dfe54e0d6 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -20,10 +20,14 @@ const ( // PexChannel is a channel for PEX messages PexChannel = byte(0x00) - // TODO: make smaller. Should match the maxGetSelection - // this is basically the amplification factor since a request - // msg is like 1 byte ... it can cause us to send msgs of this size! - maxPexMessageSize = 1048576 // 1MB + // over-estimate of max NetAddress size + // hexID (40) + IP (16) + Port (2) + Name (100) ... + // NOTE: dont use massive DNS name .. + maxAddressSize = 256 + + // NOTE: amplificaiton factor! + // small request results in up to maxPexMessageSize response + maxPexMessageSize = maxAddressSize * maxGetSelection // ensure we have enough peers defaultEnsurePeersPeriod = 30 * time.Second