6 g "github.com/anacrolix/generics"
9 func setAdd[K comparable](m *map[K]struct{}, elem K) {
10 g.MakeMapIfNilAndSet(m, elem, struct{}{})
13 type clientHolepunchAddrSets struct {
14 undialableWithoutHolepunch map[netip.AddrPort]struct{}
15 undialableWithoutHolepunchDialedAfterHolepunchConnect map[netip.AddrPort]struct{}
16 dialableOnlyAfterHolepunch map[netip.AddrPort]struct{}
17 dialedSuccessfullyAfterHolepunchConnect map[netip.AddrPort]struct{}
18 probablyOnlyConnectedDueToHolepunch map[netip.AddrPort]struct{}
19 accepted map[netip.AddrPort]struct{}
22 type ClientStats struct {
25 // Ongoing outgoing dial attempts. There may be more than one dial going on per peer address due
26 // to hole-punch connect requests. The total may not match the sum of attempts for all Torrents
27 // if a Torrent is dropped while there are outstanding dials.
28 ActiveHalfOpenAttempts int
30 NumPeersUndialableWithoutHolepunch int
31 // Number of unique peer addresses that were dialed after receiving a holepunch connect message,
32 // that have previously been undialable without any hole-punching attempts.
33 NumPeersUndialableWithoutHolepunchDialedAfterHolepunchConnect int
34 // Number of unique peer addresses that were successfully dialed and connected after a holepunch
35 // connect message and previously failing to connect without holepunching.
36 NumPeersDialableOnlyAfterHolepunch int
37 NumPeersDialedSuccessfullyAfterHolepunchConnect int
38 NumPeersProbablyOnlyConnectedDueToHolepunch int
41 func (cl *Client) statsLocked() (stats ClientStats) {
42 stats.ConnStats = cl.connStats.Copy()
43 stats.ActiveHalfOpenAttempts = cl.numHalfOpen
45 stats.NumPeersUndialableWithoutHolepunch = len(cl.undialableWithoutHolepunch)
46 stats.NumPeersUndialableWithoutHolepunchDialedAfterHolepunchConnect = len(cl.undialableWithoutHolepunchDialedAfterHolepunchConnect)
47 stats.NumPeersDialableOnlyAfterHolepunch = len(cl.dialableOnlyAfterHolepunch)
48 stats.NumPeersDialedSuccessfullyAfterHolepunchConnect = len(cl.dialedSuccessfullyAfterHolepunchConnect)
49 stats.NumPeersProbablyOnlyConnectedDueToHolepunch = len(cl.probablyOnlyConnectedDueToHolepunch)