@@ -2,11 +2,8 @@ package discv5
22
33import (
44 "context"
5- "encoding/binary"
6- "encoding/hex"
75 "encoding/json"
86 "fmt"
9- "math/bits"
107 "strings"
118 "sync"
129 "time"
@@ -93,24 +90,26 @@ func (c *Crawler) PeerProperties(node *enode.Node) json.RawMessage {
9390
9491 var enrEntryEth2 ENREntryEth2
9592 if err := node .Load (& enrEntryEth2 ); err == nil {
96- if beaconData , err := enrEntryEth2 .Data (); err == nil {
97- properties ["fork_digest" ] = beaconData .ForkDigest .String ()
98- properties ["next_fork_version" ] = beaconData .NextForkVersion .String ()
99- properties ["next_fork_epoch" ] = beaconData .NextForkEpoch .String ()
100- }
93+ properties ["fork_digest" ] = enrEntryEth2 .ForkDigest .String ()
94+ properties ["next_fork_version" ] = enrEntryEth2 .NextForkVersion .String ()
95+ properties ["next_fork_epoch" ] = enrEntryEth2 .NextForkEpoch .String ()
10196 }
10297
10398 var enrEntryAttnets ENREntryAttnets
10499 if err := node .Load (& enrEntryAttnets ); err == nil {
105- rawInt := binary .BigEndian .Uint64 (enrEntryAttnets )
106- properties ["attnets_num" ] = bits .OnesCount64 (rawInt )
107- properties ["attnets" ] = hex .EncodeToString (enrEntryAttnets )
100+ properties ["attnets_num" ] = enrEntryAttnets .AttnetsNum
101+ properties ["attnets" ] = enrEntryAttnets .Attnest
108102 }
109103
110104 var enrEntrySyncCommsSubnet ENREntrySyncCommsSubnet
111105 if err := node .Load (& enrEntrySyncCommsSubnet ); err == nil {
112- // check out https://github.com/prysmaticlabs/prysm/blob/203dc5f63b060821c2706f03a17d66b3813c860c/beacon-chain/p2p/subnets.go#L221
113- properties ["syncnets" ] = hex .EncodeToString (enrEntrySyncCommsSubnet )
106+ properties ["syncnets" ] = enrEntrySyncCommsSubnet .SyncNets
107+ }
108+
109+ var enrEntryOpStack ENREntryOpStack
110+ if err := node .Load (& enrEntryOpStack ); err == nil {
111+ properties ["opstack_chain_id" ] = enrEntryOpStack .ChainID
112+ properties ["opstack_version" ] = enrEntryOpStack .Version
114113 }
115114
116115 data , err := json .Marshal (properties )
@@ -202,17 +201,31 @@ func (c *Crawler) connect(ctx context.Context, pi peer.AddrInfo) error {
202201 if len (pi .Addrs ) == 0 {
203202 metrics .VisitErrorsCount .With (metrics .CrawlLabel ).Inc ()
204203 return fmt .Errorf ("skipping node as it has no public IP address" ) // change knownErrs map if changing this msg
204+ } else if len (pi .Addrs ) == 1 {
205+ }
206+
207+ dialAddrInfo := peer.AddrInfo {
208+ ID : pi .ID ,
209+ Addrs : ensureTCPAddr (pi .Addrs ),
210+ }
211+
212+ replaced := false
213+ if len (dialAddrInfo .Addrs ) != len (pi .Addrs ) {
214+ replaced = true
205215 }
206216
207217 retry := 0
208218 maxRetries := 1
209219 for {
210220 timeout := time .Duration (c .cfg .DialTimeout .Nanoseconds () / int64 (retry + 1 ))
211221 timeoutCtx , cancel := context .WithTimeout (ctx , timeout )
212- err := c .host .Connect (timeoutCtx , pi )
222+ err := c .host .Connect (timeoutCtx , dialAddrInfo )
213223 cancel ()
214224
215225 if err == nil {
226+ if replaced {
227+ log .WithField ("remoteID" , pi .ID .ShortString ()).Errorln ("hat was gebracht!" )
228+ }
216229 return nil
217230 }
218231
@@ -241,6 +254,52 @@ func (c *Crawler) connect(ctx context.Context, pi peer.AddrInfo) error {
241254 }
242255}
243256
257+ func ensureTCPAddr (maddrs []ma.Multiaddr ) []ma.Multiaddr {
258+ for _ , maddr := range maddrs {
259+ if _ , err := maddr .ValueForProtocol (ma .P_TCP ); err == nil {
260+ return maddrs
261+ }
262+ }
263+
264+ newMaddrs := make ([]ma.Multiaddr , 0 , len (maddrs )+ 1 )
265+
266+ for i , maddr := range maddrs {
267+ newMaddrs = append (newMaddrs , maddr )
268+
269+ udp , err := maddr .ValueForProtocol (ma .P_UDP )
270+ if err != nil {
271+ continue
272+ }
273+
274+ ip := ""
275+ ip4 , err := maddr .ValueForProtocol (ma .P_IP4 )
276+ if err != nil {
277+ ip6 , err := maddr .ValueForProtocol (ma .P_IP6 )
278+ if err != nil {
279+ continue
280+ }
281+ ip = "/ip6/" + ip6
282+ } else {
283+ ip = "/ip4/" + ip4
284+ }
285+
286+ tcpMaddr , err := ma .NewMultiaddr (ip + "/tcp/" + udp )
287+ if err != nil {
288+ continue
289+ }
290+
291+ for _ , remaining := range maddrs [i + 1 :] {
292+ newMaddrs = append (newMaddrs , remaining )
293+ }
294+
295+ newMaddrs = append (newMaddrs , tcpMaddr )
296+
297+ return newMaddrs
298+ }
299+
300+ return maddrs
301+ }
302+
244303// identifyWait waits until any connection to a peer passed the Identify
245304// exchange successfully or all identification attempts have failed.
246305// The call to IdentifyWait returns immediately if the connection was
0 commit comments