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 { ...@@ -433,3 +433,8 @@ func mockNotifier(c cFunc, d dFunc) topology.Notifier {
type cFunc func(context.Context, swarm.Address) error type cFunc func(context.Context, swarm.Address) error
type dFunc func(swarm.Address) 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. ...@@ -395,6 +395,7 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (address *bzz.
func (s *Service) Disconnect(overlay swarm.Address) error { func (s *Service) Disconnect(overlay swarm.Address) error {
peerID, found := s.peers.peerID(overlay) peerID, found := s.peers.peerID(overlay)
if !found { if !found {
s.peers.disconnecter.Disconnected(overlay)
return p2p.ErrPeerNotFound return p2p.ErrPeerNotFound
} }
...@@ -421,6 +422,7 @@ func (s *Service) SetNotifier(n topology.Notifier) { ...@@ -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) { 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) peerID, found := s.peers.peerID(overlay)
if !found { if !found {
s.peers.disconnecter.Disconnected(overlay)
return nil, p2p.ErrPeerNotFound return nil, p2p.ErrPeerNotFound
} }
......
...@@ -62,6 +62,8 @@ func newService(t *testing.T, networkID uint64, o libp2p.Options) (s *libp2p.Ser ...@@ -62,6 +62,8 @@ func newService(t *testing.T, networkID uint64, o libp2p.Options) (s *libp2p.Ser
t.Fatal(err) t.Fatal(err)
} }
s.SetNotifier(noopNotifier)
t.Cleanup(func() { t.Cleanup(func() {
cancel() cancel()
s.Close() 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