mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-01 04:21:29 +02:00
Add error code handling
This commit is contained in:
@@ -2,6 +2,7 @@ package peer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
@@ -209,7 +210,11 @@ func (conn *Conn) Open(engineCtx context.Context) error {
|
||||
// both peer send offer
|
||||
if err := conn.handshaker.SendOffer(); err != nil {
|
||||
conn.Log.Errorf("failed to send offer: %v", err)
|
||||
conn.guard.FailedToSendOffer()
|
||||
// if remote peer is offline, no need to try to reconnect.
|
||||
// The remote peer when online will send an offer to us
|
||||
if !errors.Is(err, ErrPeerNotAvailable) {
|
||||
conn.guard.FailedToSendOffer()
|
||||
}
|
||||
}
|
||||
|
||||
conn.opened = true
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package peer
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/pion/ice/v4"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
@@ -9,6 +11,8 @@ import (
|
||||
sProto "github.com/netbirdio/netbird/shared/signal/proto"
|
||||
)
|
||||
|
||||
var ErrPeerNotAvailable = signal.ErrPeerNotAvailable
|
||||
|
||||
type Signaler struct {
|
||||
signal signal.Client
|
||||
wgPrivateKey wgtypes.Key
|
||||
@@ -68,6 +72,9 @@ func (s *Signaler) signalOfferAnswer(offerAnswer OfferAnswer, remoteKey string,
|
||||
}
|
||||
|
||||
if err = s.signal.SendWithDeliveryCheck(msg); err != nil {
|
||||
if errors.Is(err, signal.ErrPeerNotAvailable) {
|
||||
return ErrPeerNotAvailable
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user