]> Sergey Matveev's repositories - btrtrc.git/blobdiff - client-stats.go
Fix panic logging unknown holepunch error code
[btrtrc.git] / client-stats.go
index d799bae6bb86f12816d923c7e11809b8d72f1e90..1a8009708fb3a3c893d60a4c542e009eab9957ed 100644 (file)
@@ -1,5 +1,17 @@
 package torrent
 
+import (
+       "net/netip"
+)
+
+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{}
+}
+
 type ClientStats struct {
        ConnStats
 
@@ -7,4 +19,27 @@ type ClientStats struct {
        // 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
 }