package ice
import (
"context"
"time"
)
func (a *Agent ) GetCandidatePairsStats () []CandidatePairStats {
var res []CandidatePairStats
err := a .loop .Run (a .loop , func (_ context .Context ) {
result := make ([]CandidatePairStats , 0 , len (a .checklist ))
for _ , cp := range a .checklist {
stat := CandidatePairStats {
Timestamp : time .Now (),
LocalCandidateID : cp .Local .ID (),
RemoteCandidateID : cp .Remote .ID (),
State : cp .state ,
Nominated : cp .nominated ,
FirstRequestTimestamp : cp .FirstRequestSentAt (),
LastRequestTimestamp : cp .LastRequestSentAt (),
FirstResponseTimestamp : cp .FirstReponseReceivedAt (),
LastResponseTimestamp : cp .LastResponseReceivedAt (),
FirstRequestReceivedTimestamp : cp .FirstRequestReceivedAt (),
LastRequestReceivedTimestamp : cp .LastRequestReceivedAt (),
TotalRoundTripTime : cp .TotalRoundTripTime (),
CurrentRoundTripTime : cp .CurrentRoundTripTime (),
RequestsReceived : cp .RequestsReceived (),
RequestsSent : cp .RequestsSent (),
ResponsesReceived : cp .ResponsesReceived (),
ResponsesSent : cp .ResponsesSent (),
}
result = append (result , stat )
}
res = result
})
if err != nil {
a .log .Errorf ("Failed to get candidate pairs stats: %v" , err )
return []CandidatePairStats {}
}
return res
}
func (a *Agent ) GetSelectedCandidatePairStats () (CandidatePairStats , bool ) {
isAvailable := false
var res CandidatePairStats
err := a .loop .Run (a .loop , func (_ context .Context ) {
sp := a .getSelectedPair ()
if sp == nil {
return
}
isAvailable = true
res = CandidatePairStats {
Timestamp : time .Now (),
LocalCandidateID : sp .Local .ID (),
RemoteCandidateID : sp .Remote .ID (),
State : sp .state ,
Nominated : sp .nominated ,
TotalRoundTripTime : sp .TotalRoundTripTime (),
CurrentRoundTripTime : sp .CurrentRoundTripTime (),
ResponsesReceived : sp .ResponsesReceived (),
}
})
if err != nil {
a .log .Errorf ("Failed to get selected candidate pair stats: %v" , err )
return CandidatePairStats {}, false
}
return res , isAvailable
}
func (a *Agent ) GetLocalCandidatesStats () []CandidateStats {
var res []CandidateStats
err := a .loop .Run (a .loop , func (_ context .Context ) {
result := make ([]CandidateStats , 0 , len (a .localCandidates ))
for networkType , localCandidates := range a .localCandidates {
for _ , cand := range localCandidates {
relayProtocol := ""
if cand .Type () == CandidateTypeRelay {
if cRelay , ok := cand .(*CandidateRelay ); ok {
relayProtocol = cRelay .RelayProtocol ()
}
}
stat := CandidateStats {
Timestamp : time .Now (),
ID : cand .ID (),
NetworkType : networkType ,
IP : cand .Address (),
Port : cand .Port (),
CandidateType : cand .Type (),
Priority : cand .Priority (),
RelayProtocol : relayProtocol ,
}
result = append (result , stat )
}
}
res = result
})
if err != nil {
a .log .Errorf ("Failed to get candidate pair stats: %v" , err )
return []CandidateStats {}
}
return res
}
func (a *Agent ) GetRemoteCandidatesStats () []CandidateStats {
var res []CandidateStats
err := a .loop .Run (a .loop , func (_ context .Context ) {
result := make ([]CandidateStats , 0 , len (a .remoteCandidates ))
for networkType , remoteCandidates := range a .remoteCandidates {
for _ , c := range remoteCandidates {
stat := CandidateStats {
Timestamp : time .Now (),
ID : c .ID (),
NetworkType : networkType ,
IP : c .Address (),
Port : c .Port (),
CandidateType : c .Type (),
Priority : c .Priority (),
RelayProtocol : "" ,
}
result = append (result , stat )
}
}
res = result
})
if err != nil {
a .log .Errorf ("Failed to get candidate pair stats: %v" , err )
return []CandidateStats {}
}
return res
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .