Commit ef68bf26 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

remove peer from kademlia on peer not found in peer registry (#353)

* remove peer from kademlia on peer not found in peer registry
parent dcbbf185
......@@ -433,3 +433,8 @@ func mockNotifier(c cFunc, d dFunc) topology.Notifier {
type cFunc func(context.Context, swarm.Address) error
type dFunc func(swarm.Address)
var noopNotifier = mockNotifier(
func(_ context.Context, _ swarm.Address) error { return nil },
func(_ swarm.Address) {},
)
......@@ -395,6 +395,7 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (address *bzz.
func (s *Service) Disconnect(overlay swarm.Address) error {
peerID, found := s.peers.peerID(overlay)
if !found {
s.peers.disconnecter.Disconnected(overlay)
return p2p.ErrPeerNotFound
}
......@@ -421,6 +422,7 @@ func (s *Service) SetNotifier(n topology.Notifier) {
func (s *Service) NewStream(ctx context.Context, overlay swarm.Address, headers p2p.Headers, protocolName, protocolVersion, streamName string) (p2p.Stream, error) {
peerID, found := s.peers.peerID(overlay)
if !found {
s.peers.disconnecter.Disconnected(overlay)
return nil, p2p.ErrPeerNotFound
}
......
......@@ -62,6 +62,8 @@ func newService(t *testing.T, networkID uint64, o libp2p.Options) (s *libp2p.Ser
t.Fatal(err)
}
s.SetNotifier(noopNotifier)
t.Cleanup(func() {
cancel()
s.Close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment