mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
feat: add retry on connection restart
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user