mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 09:33:24 +01:00
feat: add retry on connection restart
This commit is contained in:
parent
ead16a35c9
commit
801ce0730d
@ -10,8 +10,7 @@ import (
|
||||
|
||||
type Config struct {
|
||||
// Wireguard private key of local peer
|
||||
PrivateKey string
|
||||
// configured remote peers (Wireguard public keys)
|
||||
PrivateKey string
|
||||
Peers []connection.Peer
|
||||
StunTurnURLs []*ice.URL
|
||||
// host:port of the signal server
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"github.com/pion/ice/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/wiretrustee/wiretrustee/iface"
|
||||
"github.com/wiretrustee/wiretrustee/util"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"net"
|
||||
"time"
|
||||
@ -156,6 +157,8 @@ func (conn *Connection) OnAnswer(remoteAuth IceCredentials) error {
|
||||
|
||||
func (conn *Connection) OnOffer(remoteAuth IceCredentials) error {
|
||||
|
||||
conn.remoteAuthChannel <- remoteAuth
|
||||
|
||||
uFrag, pwd, err := conn.agent.GetLocalUserCredentials()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -166,8 +169,6 @@ func (conn *Connection) OnOffer(remoteAuth IceCredentials) error {
|
||||
return err
|
||||
}
|
||||
|
||||
conn.remoteAuthChannel <- remoteAuth
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -250,8 +251,14 @@ func (conn *Connection) listenOnConnectionStateChanges() error {
|
||||
}
|
||||
log.Debugf("connected to peer %s via selected candidate pair %s", conn.Config.RemoteWgKey.String(), pair)
|
||||
} else if state == ice.ConnectionStateDisconnected || state == ice.ConnectionStateFailed {
|
||||
err := conn.Restart()
|
||||
err := util.Retry(15, time.Second, func() error {
|
||||
return conn.Restart()
|
||||
}, func(err error) {
|
||||
log.Warnf("failed restarting connection, retrying ... %s", err)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("failed restarting connection %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/wiretrustee/wiretrustee/signal/proto"
|
||||
"github.com/wiretrustee/wiretrustee/util"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
@ -64,7 +65,7 @@ func NewClient(addr string, ctx context.Context) (*Client, error) {
|
||||
func (client *Client) Receive(key string, msgHandler func(msg *proto.Message) error) {
|
||||
client.connWg.Add(1)
|
||||
go func() {
|
||||
err := Retry(15, time.Second, func() error {
|
||||
err := util.Retry(15, time.Second, func() error {
|
||||
return client.connect(key, msgHandler)
|
||||
}, func(err error) {
|
||||
log.Warnf("disconnected from the Signal Exchange due to an error %s. Retrying ... ", err)
|
||||
|
@ -1,4 +1,4 @@
|
||||
package signal
|
||||
package util
|
||||
|
||||
import (
|
||||
"math/rand"
|
Loading…
Reference in New Issue
Block a user