p2p/discover: implement v5.1 wire protocol (#21647)
This change implements the Discovery v5.1 wire protocol and also adds an interactive test suite for this protocol.
This commit is contained in:
@ -146,7 +146,6 @@ func (t *pingRecorder) updateRecord(n *enode.Node) {
|
||||
func (t *pingRecorder) Self() *enode.Node { return nullNode }
|
||||
func (t *pingRecorder) lookupSelf() []*enode.Node { return nil }
|
||||
func (t *pingRecorder) lookupRandom() []*enode.Node { return nil }
|
||||
func (t *pingRecorder) close() {}
|
||||
|
||||
// ping simulates a ping request.
|
||||
func (t *pingRecorder) ping(n *enode.Node) (seq uint64, err error) {
|
||||
@ -188,15 +187,16 @@ func hasDuplicates(slice []*node) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// checkNodesEqual checks whether the two given node lists contain the same nodes.
|
||||
func checkNodesEqual(got, want []*enode.Node) error {
|
||||
if len(got) == len(want) {
|
||||
for i := range got {
|
||||
if !nodeEqual(got[i], want[i]) {
|
||||
goto NotEqual
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
NotEqual:
|
||||
output := new(bytes.Buffer)
|
||||
@ -227,6 +227,7 @@ func sortedByDistanceTo(distbase enode.ID, slice []*node) bool {
|
||||
})
|
||||
}
|
||||
|
||||
// hexEncPrivkey decodes h as a private key.
|
||||
func hexEncPrivkey(h string) *ecdsa.PrivateKey {
|
||||
b, err := hex.DecodeString(h)
|
||||
if err != nil {
|
||||
@ -239,6 +240,7 @@ func hexEncPrivkey(h string) *ecdsa.PrivateKey {
|
||||
return key
|
||||
}
|
||||
|
||||
// hexEncPubkey decodes h as a public key.
|
||||
func hexEncPubkey(h string) (ret encPubkey) {
|
||||
b, err := hex.DecodeString(h)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user