]> Sergey Matveev's repositories - btrtrc.git/blob - client-stats.go
Move PeerClientName and PeerExtensionIDs to PeerConn
[btrtrc.git] / client-stats.go
1 package torrent
2
3 import (
4         "net/netip"
5 )
6
7 type clientHolepunchAddrSets struct {
8         undialableWithoutHolepunch                            map[netip.AddrPort]struct{}
9         undialableWithoutHolepunchDialedAfterHolepunchConnect map[netip.AddrPort]struct{}
10         dialableOnlyAfterHolepunch                            map[netip.AddrPort]struct{}
11         dialedSuccessfullyAfterHolepunchConnect               map[netip.AddrPort]struct{}
12         probablyOnlyConnectedDueToHolepunch                   map[netip.AddrPort]struct{}
13 }
14
15 type ClientStats struct {
16         ConnStats
17
18         // Ongoing outgoing dial attempts. There may be more than one dial going on per peer address due
19         // to hole-punch connect requests. The total may not match the sum of attempts for all Torrents
20         // if a Torrent is dropped while there are outstanding dials.
21         ActiveHalfOpenAttempts int
22
23         NumPeersUndialableWithoutHolepunch int
24         // Number of unique peer addresses that were dialed after receiving a holepunch connect message,
25         // that have previously been undialable without any hole-punching attempts.
26         NumPeersUndialableWithoutHolepunchDialedAfterHolepunchConnect int
27         // Number of unique peer addresses that were successfully dialed and connected after a holepunch
28         // connect message and previously failing to connect without holepunching.
29         NumPeersDialableOnlyAfterHolepunch              int
30         NumPeersDialedSuccessfullyAfterHolepunchConnect int
31         NumPeersProbablyOnlyConnectedDueToHolepunch     int
32 }
33
34 func (cl *Client) statsLocked() (stats ClientStats) {
35         stats.ConnStats = cl.connStats.Copy()
36         stats.ActiveHalfOpenAttempts = cl.numHalfOpen
37
38         stats.NumPeersUndialableWithoutHolepunch = len(cl.undialableWithoutHolepunch)
39         stats.NumPeersUndialableWithoutHolepunchDialedAfterHolepunchConnect = len(cl.undialableWithoutHolepunchDialedAfterHolepunchConnect)
40         stats.NumPeersDialableOnlyAfterHolepunch = len(cl.dialableOnlyAfterHolepunch)
41         stats.NumPeersDialedSuccessfullyAfterHolepunchConnect = len(cl.dialedSuccessfullyAfterHolepunchConnect)
42         stats.NumPeersProbablyOnlyConnectedDueToHolepunch = len(cl.probablyOnlyConnectedDueToHolepunch)
43
44         return
45 }