mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-13 06:08:48 +01:00
Fix nil pointer exception when load empty list and try to cast it (#3282)
This commit is contained in:
parent
206420c085
commit
eb69f2de78
@ -13,7 +13,6 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
@ -147,7 +146,7 @@ type Engine struct {
|
||||
STUNs []*stun.URI
|
||||
// TURNs is a list of STUN servers used by ICE
|
||||
TURNs []*stun.URI
|
||||
stunTurn atomic.Value
|
||||
stunTurn icemaker.StunTurn
|
||||
|
||||
clientCtx context.Context
|
||||
clientCancel context.CancelFunc
|
||||
|
22
client/internal/peer/ice/StunTurn.go
Normal file
22
client/internal/peer/ice/StunTurn.go
Normal file
@ -0,0 +1,22 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/pion/stun/v2"
|
||||
)
|
||||
|
||||
type StunTurn atomic.Value
|
||||
|
||||
func (s *StunTurn) Load() []*stun.URI {
|
||||
v := (*atomic.Value)(s).Load()
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return v.([]*stun.URI)
|
||||
}
|
||||
|
||||
func (s *StunTurn) Store(value []*stun.URI) {
|
||||
(*atomic.Value)(s).Store(value)
|
||||
}
|
13
client/internal/peer/ice/StunTurn_test.go
Normal file
13
client/internal/peer/ice/StunTurn_test.go
Normal file
@ -0,0 +1,13 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStunTurn_LoadEmpty(t *testing.T) {
|
||||
var stStunTurn StunTurn
|
||||
got := stStunTurn.Load()
|
||||
if len(got) != 0 {
|
||||
t.Errorf("StunTurn.Load() = %v, want %v", got, nil)
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/pion/ice/v3"
|
||||
"github.com/pion/randutil"
|
||||
"github.com/pion/stun/v2"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/netbirdio/netbird/client/internal/stdnet"
|
||||
@ -39,7 +38,7 @@ func NewAgent(iFaceDiscover stdnet.ExternalIFaceDiscover, config Config, candida
|
||||
agentConfig := &ice.AgentConfig{
|
||||
MulticastDNSMode: ice.MulticastDNSModeDisabled,
|
||||
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4, ice.NetworkTypeUDP6},
|
||||
Urls: config.StunTurn.Load().([]*stun.URI),
|
||||
Urls: config.StunTurn.Load(),
|
||||
CandidateTypes: candidateTypes,
|
||||
InterfaceFilter: stdnet.InterfaceFilter(config.InterfaceBlackList),
|
||||
UDPMux: config.UDPMux,
|
||||
|
@ -1,14 +1,12 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/pion/ice/v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
// StunTurn is a list of STUN and TURN URLs
|
||||
StunTurn *atomic.Value // []*stun.URI
|
||||
StunTurn *StunTurn // []*stun.URI
|
||||
|
||||
// InterfaceBlackList is a list of machine interfaces that should be filtered out by ICE Candidate gathering
|
||||
// (e.g. if eth0 is in the list, host candidate of this interface won't be used)
|
||||
|
Loading…
Reference in New Issue
Block a user