mirror of https://github.com/status-im/go-waku.git
fix: filter out peers to be considered for circuit-relay (#1130)
Co-authored-by: Richard Ramos <info@richardramos.me>
This commit is contained in:
parent
a06208321e
commit
795322a196
|
@ -893,13 +893,26 @@ func (w *WakuNode) findRelayNodes(ctx context.Context) {
|
||||||
rand.Shuffle(len(peers), func(i, j int) { peers[i], peers[j] = peers[j], peers[i] })
|
rand.Shuffle(len(peers), func(i, j int) { peers[i], peers[j] = peers[j], peers[i] })
|
||||||
|
|
||||||
for _, p := range peers {
|
for _, p := range peers {
|
||||||
|
pENR, err := w.Host().Peerstore().(wps.WakuPeerstore).ENR(p.ID)
|
||||||
|
if err != nil {
|
||||||
|
w.log.Debug("could not get ENR for the peer, skipping for circuit-relay", zap.Stringer("peer", p.ID), zap.Error(err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rs, err := enr.RelayShardList(pENR.Record())
|
||||||
|
if err != nil || rs == nil {
|
||||||
|
w.log.Debug("could not get shard info for the peer from ENR, skipping for circuit-relay", zap.Stringer("peer", p.ID), zap.Error(err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if rs.ClusterID != w.ClusterID() {
|
||||||
|
w.log.Debug("clusterID mismatch for the peer, skipping for circuit-relay", zap.Stringer("peer", p.ID), zap.Error(err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
info := w.Host().Peerstore().PeerInfo(p.ID)
|
info := w.Host().Peerstore().PeerInfo(p.ID)
|
||||||
supportedProtocols, err := w.Host().Peerstore().SupportsProtocols(p.ID, proto.ProtoIDv2Hop)
|
supportedProtocols, err := w.Host().Peerstore().SupportsProtocols(p.ID, proto.ProtoIDv2Hop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.log.Error("could not check supported protocols", zap.Error(err))
|
w.log.Error("could not check supported protocols", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(supportedProtocols) == 0 {
|
if len(supportedProtocols) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,9 @@ type PeerData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommonDiscoveryService struct {
|
type CommonDiscoveryService struct {
|
||||||
commonService *CommonService
|
commonService *CommonService
|
||||||
channel chan PeerData
|
channel chan PeerData
|
||||||
|
canWriteToChannel sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommonDiscoveryService() *CommonDiscoveryService {
|
func NewCommonDiscoveryService() *CommonDiscoveryService {
|
||||||
|
@ -42,7 +43,9 @@ func (sp *CommonDiscoveryService) Stop(stopFn func()) {
|
||||||
stopFn()
|
stopFn()
|
||||||
sp.WaitGroup().Wait() // waitgroup is waited here so that channel can be closed after all the go rountines have stopped in service.
|
sp.WaitGroup().Wait() // waitgroup is waited here so that channel can be closed after all the go rountines have stopped in service.
|
||||||
// there is a wait in the CommonService too
|
// there is a wait in the CommonService too
|
||||||
|
sp.canWriteToChannel.Lock()
|
||||||
close(sp.channel)
|
close(sp.channel)
|
||||||
|
sp.canWriteToChannel.Unlock()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
func (sp *CommonDiscoveryService) GetListeningChan() <-chan PeerData {
|
func (sp *CommonDiscoveryService) GetListeningChan() <-chan PeerData {
|
||||||
|
@ -52,6 +55,10 @@ func (sp *CommonDiscoveryService) PushToChan(data PeerData) bool {
|
||||||
if err := sp.ErrOnNotRunning(); err != nil {
|
if err := sp.ErrOnNotRunning(); err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sp.canWriteToChannel.Lock()
|
||||||
|
defer sp.canWriteToChannel.Unlock()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case sp.channel <- data:
|
case sp.channel <- data:
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue