From ad8378a8d1c229433aeefcfd5da3d49c88e9fb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 3 Jun 2016 11:25:35 +0300 Subject: [PATCH] eth/downloader: cap the TTL to a reasonable 1 minute --- eth/downloader/downloader.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 08b685ff8a..542934f963 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -57,7 +57,8 @@ var ( rttMinEstimate = 2 * time.Second // Minimum round-trip time to target for download requests rttMaxEstimate = 20 * time.Second // Maximum rount-trip time to target for download requests rttMinConfidence = 0.1 // Worse confidence factor in our estimated RTT value - rttTTLScaling = 3 // Constant scaling factor for RTT -> TTL conversion + ttlScaling = 3 // Constant scaling factor for RTT -> TTL conversion + ttlLimit = time.Minute // Maximum TTL allowance to prevent reaching crazy timeouts qosTuningPeers = 5 // Number of peers to tune based on (best peers) qosConfidenceCap = 10 // Number of peers above which not to modify RTT confidence @@ -1949,5 +1950,9 @@ func (d *Downloader) requestTTL() time.Duration { rtt = time.Duration(atomic.LoadUint64(&d.rttEstimate)) conf = float64(atomic.LoadUint64(&d.rttConfidence)) / 1000000.0 ) - return time.Duration(rttTTLScaling) * time.Duration(float64(rtt)/conf) + ttl := time.Duration(ttlScaling) * time.Duration(float64(rtt)/conf) + if ttl > ttlLimit { + ttl = ttlLimit + } + return ttl }