Skip to content

Commit

Permalink
fix logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Mar 24, 2023
1 parent bd3f1f6 commit b78104d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion p2p/host/autorelay/autorelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package autorelay

import (
"context"
"errors"
"sync"

"github.com/libp2p/go-libp2p/core/event"
Expand Down Expand Up @@ -83,7 +84,10 @@ func (r *AutoRelay) background() {
evt := ev.(event.EvtLocalReachabilityChanged)
switch evt.Reachability {
case network.ReachabilityPrivate, network.ReachabilityUnknown:
if err := r.relayFinder.Start(); err != nil {
err := r.relayFinder.Start()
if errors.Is(err, errAlreadyRunning) {
log.Debug("tried to start already running relay finder")
} else if err != nil {
log.Errorw("failed to start relay finder", "error", err)
} else {
r.metricsTracer.RelayFinderStatus(true)
Expand Down
4 changes: 3 additions & 1 deletion p2p/host/autorelay/relay_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type relayFinder struct {
metricsTracer MetricsTracer
}

var errAlreadyRunning = errors.New("relayFinder already running")

func newRelayFinder(host *basic.BasicHost, peerSource PeerSource, conf *config) *relayFinder {
if peerSource == nil {
panic("Can not create a new relayFinder. Need a Peer Source fn or a list of static relays. Refer to the documentation around `libp2p.EnableAutoRelay`")
Expand Down Expand Up @@ -754,7 +756,7 @@ func (rf *relayFinder) Start() error {
rf.ctxCancelMx.Lock()
defer rf.ctxCancelMx.Unlock()
if rf.ctxCancel != nil {
return errors.New("relayFinder already running")
return errAlreadyRunning
}
log.Debug("starting relay finder")
ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit b78104d

Please sign in to comment.