mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
[client] Fix ICE latency handling (#4501)
The GetSelectedCandidatePair() does not carry the latency information.
This commit is contained in:
@@ -218,7 +218,9 @@ func (w *WorkerICE) reCreateAgent(dialerCancel context.CancelFunc, candidates []
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := agent.OnSelectedCandidatePairChange(w.onICESelectedCandidatePair); err != nil {
|
if err := agent.OnSelectedCandidatePairChange(func(c1, c2 ice.Candidate) {
|
||||||
|
w.onICESelectedCandidatePair(agent, c1, c2)
|
||||||
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,26 +367,17 @@ func (w *WorkerICE) onICECandidate(candidate ice.Candidate) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WorkerICE) onICESelectedCandidatePair(c1 ice.Candidate, c2 ice.Candidate) {
|
func (w *WorkerICE) onICESelectedCandidatePair(agent *icemaker.ThreadSafeAgent, c1, c2 ice.Candidate) {
|
||||||
w.log.Debugf("selected candidate pair [local <-> remote] -> [%s <-> %s], peer %s", c1.String(), c2.String(),
|
w.log.Debugf("selected candidate pair [local <-> remote] -> [%s <-> %s], peer %s", c1.String(), c2.String(),
|
||||||
w.config.Key)
|
w.config.Key)
|
||||||
|
|
||||||
w.muxAgent.Lock()
|
pairStat, ok := agent.GetSelectedCandidatePairStats()
|
||||||
|
if !ok {
|
||||||
pair, err := w.agent.GetSelectedCandidatePair()
|
w.log.Warnf("failed to get selected candidate pair stats")
|
||||||
if err != nil {
|
|
||||||
w.log.Warnf("failed to get selected candidate pair: %s", err)
|
|
||||||
w.muxAgent.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if pair == nil {
|
|
||||||
w.log.Warnf("selected candidate pair is nil, cannot proceed")
|
|
||||||
w.muxAgent.Unlock()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.muxAgent.Unlock()
|
|
||||||
|
|
||||||
duration := time.Duration(pair.CurrentRoundTripTime() * float64(time.Second))
|
duration := time.Duration(pairStat.CurrentRoundTripTime * float64(time.Second))
|
||||||
if err := w.statusRecorder.UpdateLatency(w.config.Key, duration); err != nil {
|
if err := w.statusRecorder.UpdateLatency(w.config.Key, duration); err != nil {
|
||||||
w.log.Debugf("failed to update latency for peer: %s", err)
|
w.log.Debugf("failed to update latency for peer: %s", err)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user