Skip to content

Commit

Permalink
added already connected filter
Browse files Browse the repository at this point in the history
  • Loading branch information
y0sher committed Dec 8, 2024
1 parent 6fbfe8b commit ff03e04
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions network/discovery/dv5_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ func (dvs *DiscV5Service) ssvNodeFilter(logger *zap.Logger) func(node *enode.Nod
}
}

func (dvs *DiscV5Service) alreadyConnectedFilter() func(node *enode.Node) bool {
return func(node *enode.Node) bool {
pid, err := PeerID(node)
if err != nil {
return false
}
return dvs.conns.Connectedness(pid) != libp2pnetwork.Connected
}
}

func (dvs *DiscV5Service) recentlyTrimmedFilter() func(node *enode.Node) bool {
return func(node *enode.Node) bool {
pid, err := PeerID(node)
Expand Down
2 changes: 1 addition & 1 deletion network/discovery/dv5_routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (dvs *DiscV5Service) FindPeers(ctx context.Context, ns string, opt ...disco

dvs.discover(ctx, logger, func(e PeerEvent) {
cn <- e.AddrInfo
}, time.Millisecond, dvs.ssvNodeFilter(logger), dvs.badNodeFilter(logger), dvs.subnetFilter(subnet), dvs.recentlyTrimmedFilter())
}, time.Millisecond, dvs.ssvNodeFilter(logger), dvs.badNodeFilter(logger), dvs.subnetFilter(subnet), dvs.alreadyConnectedFilter(), dvs.recentlyTrimmedFilter())

return cn, nil
}
2 changes: 1 addition & 1 deletion network/discovery/dv5_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (dvs *DiscV5Service) Bootstrap(logger *zap.Logger, handler HandleNewPeer) e
return
}
handler(e)
}, defaultDiscoveryInterval, dvs.ssvNodeFilter(logger), dvs.sharedSubnetsFilter(1), dvs.badNodeFilter(logger), dvs.recentlyTrimmedFilter())
}, defaultDiscoveryInterval, dvs.ssvNodeFilter(logger), dvs.sharedSubnetsFilter(1), dvs.badNodeFilter(logger), dvs.alreadyConnectedFilter(), dvs.recentlyTrimmedFilter())

return nil
}
Expand Down

0 comments on commit ff03e04

Please sign in to comment.