Fix dht find value and updates from latest protocol changes #90

Merged
shyba merged 5 commits from fix_dht into master 2021-10-05 15:03:23 +02:00
Showing only changes of commit 4056c44c2e - Show all commits

View file

@ -2,6 +2,7 @@ package dht
import ( import (
"bytes" "bytes"
"encoding/json"
"net" "net"
"sort" "sort"
"strconv" "strconv"
@ -41,6 +42,20 @@ func (c Contact) String() string {
return str return str
} }
func (c Contact) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
ID string
IP string
Port int
PeerPort int
}{
ID: c.ID.Hex(),
IP: c.IP.String(),
Port: c.Port,
PeerPort: c.PeerPort,
})
}
// MarshalCompact returns a compact byteslice representation of the contact // MarshalCompact returns a compact byteslice representation of the contact
// NOTE: The compact representation always uses the tcp PeerPort, not the udp Port. This is dumb, but that's how the python daemon does it // NOTE: The compact representation always uses the tcp PeerPort, not the udp Port. This is dumb, but that's how the python daemon does it
func (c Contact) MarshalCompact() ([]byte, error) { func (c Contact) MarshalCompact() ([]byte, error) {