mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 10:49:24 +08:00
p2p/net/swarm/listener: consume peerstream listeners
This commit is contained in:
@ -66,10 +66,32 @@ func (s *Swarm) setupListener(maddr ma.Multiaddr) error {
|
|||||||
|
|
||||||
// AddListener to the peerstream Listener. this will begin accepting connections
|
// AddListener to the peerstream Listener. this will begin accepting connections
|
||||||
// and streams!
|
// and streams!
|
||||||
_, err = s.swarm.AddListener(list)
|
sl, err := s.swarm.AddListener(list)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// go consume peerstream's listen accept errors. note, these ARE errors.
|
||||||
|
// they may be killing the listener, and if we get _any_ we should be
|
||||||
|
// fixing this in our conn.Listener (to ignore them or handle them
|
||||||
|
// differently.)
|
||||||
|
go func(ctx context.Context, sl *ps.Listener) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case err, more := <-sl.AcceptErrors():
|
||||||
|
if !more {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Info(err)
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(s.cg.Context(), sl)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// connHandler is called by the StreamSwarm whenever a new connection is added
|
// connHandler is called by the StreamSwarm whenever a new connection is added
|
||||||
// here we configure it slightly. Note that this is sequential, so if anything
|
// here we configure it slightly. Note that this is sequential, so if anything
|
||||||
// will take a while do it in a goroutine.
|
// will take a while do it in a goroutine.
|
||||||
|
Reference in New Issue
Block a user