diff --git a/p2p/discv5/net.go b/p2p/discv5/net.go index 9b0bd0c80a..9bfc339101 100644 --- a/p2p/discv5/net.go +++ b/p2p/discv5/net.go @@ -46,8 +46,6 @@ const ( lowPort = 1024 ) -const testTopic = "foo" - const ( printTestImgLogs = false ) @@ -577,16 +575,6 @@ loop: case <-statsDump.C: log.Trace("<-statsDump.C") - /*r, ok := net.ticketStore.radius[testTopic] - if !ok { - fmt.Printf("(%x) no radius @ %v\n", net.tab.self.ID[:8], time.Now()) - } else { - topics := len(net.ticketStore.tickets) - tickets := len(net.ticketStore.nodes) - rad := r.radius / (maxRadius/10000+1) - fmt.Printf("(%x) topics:%d radius:%d tickets:%d @ %v\n", net.tab.self.ID[:8], topics, rad, tickets, time.Now()) - }*/ - tm := mclock.Now() for topic, r := range net.ticketStore.radius { if printTestImgLogs { diff --git a/p2p/discv5/node.go b/p2p/discv5/node.go index 3d47485122..8f553743e0 100644 --- a/p2p/discv5/node.go +++ b/p2p/discv5/node.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "math/big" - "math/rand" "net" "net/url" "regexp" @@ -416,23 +415,3 @@ func logdist(a, b common.Hash) int { } return len(a)*8 - lz } - -// hashAtDistance returns a random hash such that logdist(a, b) == n -func hashAtDistance(a common.Hash, n int) (b common.Hash) { - if n == 0 { - return a - } - // flip bit at position n, fill the rest with random bits - b = a - pos := len(a) - n/8 - 1 - bit := byte(0x01) << (byte(n%8) - 1) - if bit == 0 { - pos++ - bit = 0x80 - } - b[pos] = a[pos]&^bit | ^a[pos]&bit // TODO: randomize end bits - for i := pos + 1; i < len(a); i++ { - b[i] = byte(rand.Intn(255)) - } - return b -} diff --git a/p2p/discv5/node_test.go b/p2p/discv5/node_test.go index ce4ad9e4d4..51de12378b 100644 --- a/p2p/discv5/node_test.go +++ b/p2p/discv5/node_test.go @@ -267,24 +267,6 @@ func TestNodeID_logdistEqual(t *testing.T) { } } -func TestNodeID_hashAtDistance(t *testing.T) { - // we don't use quick.Check here because its output isn't - // very helpful when the test fails. - cfg := quickcfg() - for i := 0; i < cfg.MaxCount; i++ { - a := gen(common.Hash{}, cfg.Rand).(common.Hash) - dist := cfg.Rand.Intn(len(common.Hash{}) * 8) - result := hashAtDistance(a, dist) - actualdist := logdist(result, a) - - if dist != actualdist { - t.Log("a: ", a) - t.Log("result:", result) - t.Fatalf("#%d: distance of result is %d, want %d", i, actualdist, dist) - } - } -} - func quickcfg() *quick.Config { return &quick.Config{ MaxCount: 5000, diff --git a/p2p/discv5/ntp.go b/p2p/discv5/ntp.go index 4fb5f657ae..ec772681c3 100644 --- a/p2p/discv5/ntp.go +++ b/p2p/discv5/ntp.go @@ -20,13 +20,9 @@ package discv5 import ( - "fmt" "net" "sort" - "strings" "time" - - "github.com/ethereum/go-ethereum/log" ) const ( @@ -42,27 +38,6 @@ func (s durationSlice) Len() int { return len(s) } func (s durationSlice) Less(i, j int) bool { return s[i] < s[j] } func (s durationSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -// checkClockDrift queries an NTP server for clock drifts and warns the user if -// one large enough is detected. -func checkClockDrift() { - drift, err := sntpDrift(ntpChecks) - if err != nil { - return - } - if drift < -driftThreshold || drift > driftThreshold { - warning := fmt.Sprintf("System clock seems off by %v, which can prevent network connectivity", drift) - howtofix := fmt.Sprintf("Please enable network time synchronisation in system settings") - separator := strings.Repeat("-", len(warning)) - - log.Warn(separator) - log.Warn(warning) - log.Warn(howtofix) - log.Warn(separator) - } else { - log.Debug(fmt.Sprintf("Sanity NTP check reported %v drift, all ok", drift)) - } -} - // sntpDrift does a naive time resolution against an NTP server and returns the // measured drift. This method uses the simple version of NTP. It's not precise // but should be fine for these purposes. diff --git a/p2p/discv5/sim_test.go b/p2p/discv5/sim_test.go index 543faecd48..b758fde74d 100644 --- a/p2p/discv5/sim_test.go +++ b/p2p/discv5/sim_test.go @@ -31,6 +31,8 @@ import ( "github.com/ethereum/go-ethereum/common" ) +const testTopic = "foo" + // In this test, nodes try to randomly resolve each other. func TestSimRandomResolve(t *testing.T) { t.Skip("boring") diff --git a/p2p/discv5/table_test.go b/p2p/discv5/table_test.go index a29943dab9..0c5885105b 100644 --- a/p2p/discv5/table_test.go +++ b/p2p/discv5/table_test.go @@ -31,6 +31,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" ) +var errTimeout = errors.New("RPC timeout") + type nullTransport struct{} func (nullTransport) sendPing(remote *Node, remoteAddr *net.UDPAddr) []byte { return []byte{1} } @@ -150,15 +152,6 @@ func fillBucket(tab *Table, ld int) (last *Node) { return b.entries[bucketSize-1] } -// nodeAtDistance creates a node for which logdist(base, n.sha) == ld. -// The node's ID does not correspond to n.sha. -func nodeAtDistance(base common.Hash, ld int) (n *Node) { - n = new(Node) - n.sha = hashAtDistance(base, ld) - copy(n.ID[:], n.sha[:]) // ensure the node still has a unique ID - return n -} - type pingRecorder struct{ responding, pinged map[NodeID]bool } func newPingRecorder() *pingRecorder { diff --git a/p2p/discv5/udp.go b/p2p/discv5/udp.go index 49e1cb811a..a1c4e03613 100644 --- a/p2p/discv5/udp.go +++ b/p2p/discv5/udp.go @@ -38,7 +38,6 @@ const Version = 4 var ( errPacketTooSmall = errors.New("too small") errBadPrefix = errors.New("bad prefix") - errTimeout = errors.New("RPC timeout") ) // Timeouts