forked from anacrolix/torrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client-stats.go
52 lines (42 loc) · 2.25 KB
/
client-stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package torrent
import (
"net/netip"
g "github.com/anacrolix/generics"
)
func setAdd[K comparable](m *map[K]struct{}, elem K) {
g.MakeMapIfNilAndSet(m, elem, struct{}{})
}
type clientHolepunchAddrSets struct {
undialableWithoutHolepunch map[netip.AddrPort]struct{}
undialableWithoutHolepunchDialedAfterHolepunchConnect map[netip.AddrPort]struct{}
dialableOnlyAfterHolepunch map[netip.AddrPort]struct{}
dialedSuccessfullyAfterHolepunchConnect map[netip.AddrPort]struct{}
probablyOnlyConnectedDueToHolepunch map[netip.AddrPort]struct{}
accepted map[netip.AddrPort]struct{}
}
type ClientStats struct {
ConnStats
// Ongoing outgoing dial attempts. There may be more than one dial going on per peer address due
// to hole-punch connect requests. The total may not match the sum of attempts for all Torrents
// if a Torrent is dropped while there are outstanding dials.
ActiveHalfOpenAttempts int
NumPeersUndialableWithoutHolepunch int
// Number of unique peer addresses that were dialed after receiving a holepunch connect message,
// that have previously been undialable without any hole-punching attempts.
NumPeersUndialableWithoutHolepunchDialedAfterHolepunchConnect int
// Number of unique peer addresses that were successfully dialed and connected after a holepunch
// connect message and previously failing to connect without holepunching.
NumPeersDialableOnlyAfterHolepunch int
NumPeersDialedSuccessfullyAfterHolepunchConnect int
NumPeersProbablyOnlyConnectedDueToHolepunch int
}
func (cl *Client) statsLocked() (stats ClientStats) {
stats.ConnStats = cl.connStats.Copy()
stats.ActiveHalfOpenAttempts = cl.numHalfOpen
stats.NumPeersUndialableWithoutHolepunch = len(cl.undialableWithoutHolepunch)
stats.NumPeersUndialableWithoutHolepunchDialedAfterHolepunchConnect = len(cl.undialableWithoutHolepunchDialedAfterHolepunchConnect)
stats.NumPeersDialableOnlyAfterHolepunch = len(cl.dialableOnlyAfterHolepunch)
stats.NumPeersDialedSuccessfullyAfterHolepunchConnect = len(cl.dialedSuccessfullyAfterHolepunchConnect)
stats.NumPeersProbablyOnlyConnectedDueToHolepunch = len(cl.probablyOnlyConnectedDueToHolepunch)
return
}