iceCandidatesMu.

This commit is contained in:
Miroslav Šedivý 2022-07-03 23:06:56 +02:00
parent bb35695255
commit e4261c53b1

View File

@ -15,6 +15,7 @@ type metrics struct {
connectionCount prometheus.Counter
iceCandidates map[string]struct{}
iceCandidatesMu *sync.Mutex
iceCandidatesCount prometheus.Counter
iceBytesSent prometheus.Gauge
@ -73,7 +74,8 @@ func (m *metricsCtx) getBySession(session types.Session) metrics {
},
}),
iceCandidates: map[string]struct{}{},
iceCandidates: map[string]struct{}{},
iceCandidatesMu: &sync.Mutex{},
iceCandidatesCount: promauto.NewCounter(prometheus.CounterOpts{
Name: "ice_candidates_count",
Namespace: "neko",
@ -135,6 +137,9 @@ func (m *metricsCtx) NewConnection(session types.Session) {
func (m *metricsCtx) NewICECandidate(session types.Session, id string) {
met := m.getBySession(session)
met.iceCandidatesMu.Lock()
defer met.iceCandidatesMu.Unlock()
if _, found := met.iceCandidates[id]; found {
return
}