mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-18 06:39:54 +00:00
code cleaning
This commit is contained in:
@@ -36,15 +36,12 @@ type WorkerICE struct {
|
||||
ctx context.Context
|
||||
log *log.Entry
|
||||
config ConnConfig
|
||||
conn *Conn
|
||||
signaler *Signaler
|
||||
iFaceDiscover stdnet.ExternalIFaceDiscover
|
||||
statusRecorder *Status
|
||||
hasRelayOnLocally bool
|
||||
|
||||
onConnReady func(ICEConnInfo)
|
||||
onDisconnected func()
|
||||
callBackMu sync.Mutex
|
||||
|
||||
agent *ice.Agent
|
||||
muxAgent sync.Mutex
|
||||
|
||||
@@ -56,11 +53,12 @@ type WorkerICE struct {
|
||||
localPwd string
|
||||
}
|
||||
|
||||
func NewWorkerICE(ctx context.Context, log *log.Entry, config ConnConfig, signaler *Signaler, ifaceDiscover stdnet.ExternalIFaceDiscover, statusRecorder *Status, hasRelayOnLocally bool) (*WorkerICE, error) {
|
||||
func NewWorkerICE(ctx context.Context, log *log.Entry, config ConnConfig, conn *Conn, signaler *Signaler, ifaceDiscover stdnet.ExternalIFaceDiscover, statusRecorder *Status, hasRelayOnLocally bool) (*WorkerICE, error) {
|
||||
w := &WorkerICE{
|
||||
ctx: ctx,
|
||||
log: log,
|
||||
config: config,
|
||||
conn: conn,
|
||||
signaler: signaler,
|
||||
iFaceDiscover: ifaceDiscover,
|
||||
statusRecorder: statusRecorder,
|
||||
@@ -157,7 +155,7 @@ func (w *WorkerICE) OnNewOffer(remoteOfferAnswer *OfferAnswer) {
|
||||
Priority: selectedPriority,
|
||||
}
|
||||
w.log.Debugf("on ICE conn read to use ready")
|
||||
w.notifyOnReady(ci)
|
||||
w.conn.iCEConnectionIsReady(ci)
|
||||
}
|
||||
|
||||
// OnRemoteCandidate Handles ICE connection Candidate provided by the remote peer.
|
||||
@@ -181,20 +179,6 @@ func (w *WorkerICE) OnRemoteCandidate(candidate ice.Candidate, haRoutes route.HA
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WorkerICE) SetOnConnReady(f func(ICEConnInfo)) {
|
||||
w.callBackMu.Lock()
|
||||
defer w.callBackMu.Unlock()
|
||||
|
||||
w.onConnReady = f
|
||||
}
|
||||
|
||||
func (w *WorkerICE) SetOnDisconnected(f func()) {
|
||||
w.callBackMu.Lock()
|
||||
defer w.callBackMu.Unlock()
|
||||
|
||||
w.onDisconnected = f
|
||||
}
|
||||
|
||||
func (w *WorkerICE) GetLocalUserCredentials() (frag string, pwd string) {
|
||||
w.muxAgent.Lock()
|
||||
defer w.muxAgent.Unlock()
|
||||
@@ -231,7 +215,7 @@ func (w *WorkerICE) reCreateAgent(agentCancel context.CancelFunc, candidates []i
|
||||
err = agent.OnConnectionStateChange(func(state ice.ConnectionState) {
|
||||
w.log.Debugf("ICE ConnectionState has changed to %s", state.String())
|
||||
if state == ice.ConnectionStateFailed || state == ice.ConnectionStateDisconnected {
|
||||
w.notifyDisconnected()
|
||||
w.conn.onWorkerICEStateDisconnected()
|
||||
|
||||
w.muxAgent.Lock()
|
||||
agentCancel()
|
||||
@@ -343,26 +327,6 @@ func (w *WorkerICE) turnAgentDial(ctx context.Context, remoteOfferAnswer *OfferA
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WorkerICE) notifyDisconnected() {
|
||||
w.callBackMu.Lock()
|
||||
defer w.callBackMu.Unlock()
|
||||
|
||||
if w.onDisconnected == nil {
|
||||
return
|
||||
}
|
||||
w.onDisconnected()
|
||||
}
|
||||
|
||||
func (w *WorkerICE) notifyOnReady(ci ICEConnInfo) {
|
||||
w.callBackMu.Lock()
|
||||
defer w.callBackMu.Unlock()
|
||||
|
||||
if w.onConnReady == nil {
|
||||
return
|
||||
}
|
||||
w.onConnReady(ci)
|
||||
}
|
||||
|
||||
func extraSrflxCandidate(candidate ice.Candidate) (*ice.CandidateServerReflexive, error) {
|
||||
relatedAdd := candidate.RelatedAddress()
|
||||
return ice.NewCandidateServerReflexive(&ice.CandidateServerReflexiveConfig{
|
||||
|
||||
Reference in New Issue
Block a user