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] })
|
||||
|
||||
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)
|
||||
supportedProtocols, err := w.Host().Peerstore().SupportsProtocols(p.ID, proto.ProtoIDv2Hop)
|
||||
if err != nil {
|
||||
w.log.Error("could not check supported protocols", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
if len(supportedProtocols) == 0 {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ type PeerData struct {
|
|||
type CommonDiscoveryService struct {
|
||||
commonService *CommonService
|
||||
channel chan PeerData
|
||||
canWriteToChannel sync.Mutex
|
||||
}
|
||||
|
||||
func NewCommonDiscoveryService() *CommonDiscoveryService {
|
||||
|
@ -42,7 +43,9 @@ func (sp *CommonDiscoveryService) Stop(stopFn func()) {
|
|||
stopFn()
|
||||
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
|
||||
sp.canWriteToChannel.Lock()
|
||||
close(sp.channel)
|
||||
sp.canWriteToChannel.Unlock()
|
||||
})
|
||||
}
|
||||
func (sp *CommonDiscoveryService) GetListeningChan() <-chan PeerData {
|
||||
|
@ -52,6 +55,10 @@ func (sp *CommonDiscoveryService) PushToChan(data PeerData) bool {
|
|||
if err := sp.ErrOnNotRunning(); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
sp.canWriteToChannel.Lock()
|
||||
defer sp.canWriteToChannel.Unlock()
|
||||
|
||||
select {
|
||||
case sp.channel <- data:
|
||||
return true
|
||||
|
|
Loading…
Reference in New Issue