Przeglądaj źródła

Manual send of multiple neighbours packets. Test receiving multiple neighbours packets.

subtly 10 lat temu
rodzic
commit
a32693770c
2 zmienionych plików z 19 dodań i 3 usunięć
  1. 7 1
      p2p/discover/udp.go
  2. 12 2
      p2p/discover/udp_test.go

+ 7 - 1
p2p/discover/udp.go

@@ -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
 }
 

+ 12 - 2
p2p/discover/udp_test.go

@@ -163,9 +163,19 @@ func TestUDP_findnode(t *testing.T) {
 	))
 	// check that closest neighbors are returned.
 	test.packetIn(nil, findnodePacket, &findnode{Target: testTarget, Expiration: futureExp})
+	expected := test.table.closest(targetHash, bucketSize)
 	test.waitPacketOut(func(p *neighbors) {
-		expected := test.table.closest(targetHash, bucketSize)
-		if len(p.Nodes) != bucketSize {
+		if len(p.Nodes) != 13 {
+			t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), bucketSize)
+		}
+		for i := range p.Nodes {
+			if p.Nodes[i].ID != expected.entries[i].ID {
+				t.Errorf("result mismatch at %d:\n  got:  %v\n  want: %v", i, p.Nodes[i], expected.entries[i])
+			}
+		}
+	})
+	test.waitPacketOut(func(p *neighbors) {
+		if len(p.Nodes) != 3 {
 			t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), bucketSize)
 		}
 		for i := range p.Nodes {