|
|
|
@ -34,7 +34,7 @@ func TestUDPv4_Lookup(t *testing.T) { |
|
|
|
|
test := newUDPTest(t) |
|
|
|
|
|
|
|
|
|
// Lookup on empty table returns no nodes.
|
|
|
|
|
targetKey, _ := decodePubkey(crypto.S256(), lookupTestnet.target[:]) |
|
|
|
|
targetKey, _ := v4wire.DecodePubkey(crypto.S256(), lookupTestnet.target) |
|
|
|
|
if results := test.udp.LookupPubkey(targetKey); len(results) > 0 { |
|
|
|
|
t.Fatalf("lookup on empty table returned %d results: %#v", len(results), results) |
|
|
|
|
} |
|
|
|
@ -56,7 +56,7 @@ func TestUDPv4_Lookup(t *testing.T) { |
|
|
|
|
results := <-resultC |
|
|
|
|
t.Logf("results:") |
|
|
|
|
for _, e := range results { |
|
|
|
|
t.Logf(" ld=%d, %x", enode.LogDist(lookupTestnet.target.id(), e.ID()), e.ID().Bytes()) |
|
|
|
|
t.Logf(" ld=%d, %x", enode.LogDist(lookupTestnet.target.ID(), e.ID()), e.ID().Bytes()) |
|
|
|
|
} |
|
|
|
|
if len(results) != bucketSize { |
|
|
|
|
t.Errorf("wrong number of results: got %d, want %d", len(results), bucketSize) |
|
|
|
@ -142,7 +142,7 @@ func serveTestnet(test *udpTest, testnet *preminedTestnet) { |
|
|
|
|
case *v4wire.Ping: |
|
|
|
|
test.packetInFrom(nil, key, to, &v4wire.Pong{Expiration: futureExp, ReplyTok: hash}) |
|
|
|
|
case *v4wire.Findnode: |
|
|
|
|
dist := enode.LogDist(n.ID(), testnet.target.id()) |
|
|
|
|
dist := enode.LogDist(n.ID(), testnet.target.ID()) |
|
|
|
|
nodes := testnet.nodesAtDistance(dist - 1) |
|
|
|
|
test.packetInFrom(nil, key, to, &v4wire.Neighbors{Expiration: futureExp, Nodes: nodes}) |
|
|
|
|
} |
|
|
|
@ -156,12 +156,12 @@ func checkLookupResults(t *testing.T, tn *preminedTestnet, results []*enode.Node |
|
|
|
|
t.Helper() |
|
|
|
|
t.Logf("results:") |
|
|
|
|
for _, e := range results { |
|
|
|
|
t.Logf(" ld=%d, %x", enode.LogDist(tn.target.id(), e.ID()), e.ID().Bytes()) |
|
|
|
|
t.Logf(" ld=%d, %x", enode.LogDist(tn.target.ID(), e.ID()), e.ID().Bytes()) |
|
|
|
|
} |
|
|
|
|
if hasDuplicates(results) { |
|
|
|
|
t.Errorf("result set contains duplicate entries") |
|
|
|
|
} |
|
|
|
|
if !sortedByDistanceTo(tn.target.id(), results) { |
|
|
|
|
if !sortedByDistanceTo(tn.target.ID(), results) { |
|
|
|
|
t.Errorf("result set not sorted by distance to target") |
|
|
|
|
} |
|
|
|
|
wantNodes := tn.closest(len(results)) |
|
|
|
@ -231,7 +231,7 @@ var lookupTestnet = &preminedTestnet{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type preminedTestnet struct { |
|
|
|
|
target encPubkey |
|
|
|
|
target v4wire.Pubkey |
|
|
|
|
dists [hashBits + 1][]*ecdsa.PrivateKey |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -304,7 +304,7 @@ func (tn *preminedTestnet) closest(n int) (nodes []*enode.Node) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
slices.SortFunc(nodes, func(a, b *enode.Node) int { |
|
|
|
|
return enode.DistCmp(tn.target.id(), a.ID(), b.ID()) |
|
|
|
|
return enode.DistCmp(tn.target.ID(), a.ID(), b.ID()) |
|
|
|
|
}) |
|
|
|
|
return nodes[:n] |
|
|
|
|
} |
|
|
|
@ -319,11 +319,11 @@ func (tn *preminedTestnet) mine() { |
|
|
|
|
tn.dists[i] = nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
targetSha := tn.target.id() |
|
|
|
|
targetSha := tn.target.ID() |
|
|
|
|
found, need := 0, 40 |
|
|
|
|
for found < need { |
|
|
|
|
k := newkey() |
|
|
|
|
ld := enode.LogDist(targetSha, encodePubkey(&k.PublicKey).id()) |
|
|
|
|
ld := enode.LogDist(targetSha, v4wire.EncodePubkey(&k.PublicKey).ID()) |
|
|
|
|
if len(tn.dists[ld]) < 8 { |
|
|
|
|
tn.dists[ld] = append(tn.dists[ld], k) |
|
|
|
|
found++ |
|
|
|
|