go-libp2p-autonat icon indicating copy to clipboard operation
go-libp2p-autonat copied to clipboard

EventBus `EvtLocalReachabilityChanged` emits conflicting measurements

Open acud opened this issue 3 years ago • 2 comments

Hi all,

We have a background worker that taps onto the events from the autonat service and propagates them to the necessary components, like so:

func (s *Service) reachabilityWorker() error {
	sub, err := s.host.EventBus().Subscribe([]interface{}{new(event.EvtLocalReachabilityChanged)})
	if err != nil {
		return fmt.Errorf("failed subscribing to reachability event %w", err)
	}

	go func() {
		defer sub.Close()
		for {
			select {
			case <-s.ctx.Done():
				return
			case e := <-sub.Out():
				if r, ok := e.(event.EvtLocalReachabilityChanged); ok {
					select {
					case <-s.ready:
					case <-s.halt:
						return
					}
					s.logger.Debugf("reachability changed to %s", r.Reachability.String())
					s.notifier.UpdateReachability(p2p.ReachabilityStatus(r.Reachability))
				}
			}
		}
	}()
	return nil
}

Now, looking at the measurements on a local node (which was behind NAT) I managed to see multiple events constantly being emitted, even after the initial status was emitted. So the node pivots between Private and Public intermittently.

Having looked at the issues in this repo (and from our experience within the team) I know that this issue is not trivial to assume, but in the meanwhile, I'd like to ask if we can rely on this data somehow, and if we could apply some sort of a heuristic on top of this, so that the measurement becomes more credible (assuming we are only dealing with public CIDRs).

Many thanks in advance!

acud avatar Dec 06 '21 10:12 acud

Do you have any idea where the Public measurement is coming from? Is there any address that the node is dialable at?

marten-seemann avatar Dec 22 '21 06:12 marten-seemann

No clue whatsoever @marten-seemann. Would you have an idea on how to actually check that? would I have to check the bind addresses for libp2p then try to telnet from another host?

acud avatar Jan 02 '22 22:01 acud