feat: add stats for known peers, not just connected ones (#4900)
This commit is contained in:
parent
707e51aa9d
commit
bcbd9b77af
|
@ -263,8 +263,12 @@ struct tr_swarm_stats
|
||||||
{
|
{
|
||||||
std::array<uint16_t, 2> active_peer_count;
|
std::array<uint16_t, 2> active_peer_count;
|
||||||
uint16_t active_webseed_count;
|
uint16_t active_webseed_count;
|
||||||
|
// connected peers
|
||||||
uint16_t peer_count;
|
uint16_t peer_count;
|
||||||
|
// connected peers by peer source
|
||||||
std::array<uint16_t, TR_PEER_FROM__MAX> peer_from_count;
|
std::array<uint16_t, TR_PEER_FROM__MAX> peer_from_count;
|
||||||
|
// known peers by peer source
|
||||||
|
std::array<uint16_t, TR_PEER_FROM__MAX> known_peer_from_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
tr_swarm_stats tr_swarmGetStats(tr_swarm const* swarm);
|
tr_swarm_stats tr_swarmGetStats(tr_swarm const* swarm);
|
||||||
|
|
|
@ -336,6 +336,7 @@ public:
|
||||||
auto& [socket_address, peer_info] = *iter;
|
auto& [socket_address, peer_info] = *iter;
|
||||||
if (peer_info.is_inactive(now))
|
if (peer_info.is_inactive(now))
|
||||||
{
|
{
|
||||||
|
--stats.known_peer_from_count[peer_info.from_first()];
|
||||||
iter = connectable_pool.erase(iter);
|
iter = connectable_pool.erase(iter);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -455,6 +456,10 @@ public:
|
||||||
peer_info.found_at(from);
|
peer_info.found_at(from);
|
||||||
peer_info.set_pex_flags(flags);
|
peer_info.set_pex_flags(flags);
|
||||||
}
|
}
|
||||||
|
else if (is_connectable)
|
||||||
|
{
|
||||||
|
++stats.known_peer_from_count[from];
|
||||||
|
}
|
||||||
|
|
||||||
mark_all_seeds_flag_dirty();
|
mark_all_seeds_flag_dirty();
|
||||||
|
|
||||||
|
@ -817,7 +822,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
info_this.merge(info_that);
|
info_this.merge(info_that);
|
||||||
connectable_pool.erase(info_that.listen_socket_address());
|
auto from = info_that.from_first();
|
||||||
|
stats.known_peer_from_count[from] -= connectable_pool.erase(info_that.listen_socket_address());
|
||||||
}
|
}
|
||||||
else if (!was_connectable)
|
else if (!was_connectable)
|
||||||
{
|
{
|
||||||
|
@ -833,6 +839,7 @@ private:
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
++stats.known_peer_from_count[nh.mapped().from_first()];
|
||||||
TR_ASSERT(nh.key().address() == nh.mapped().listen_address());
|
TR_ASSERT(nh.key().address() == nh.mapped().listen_address());
|
||||||
}
|
}
|
||||||
nh.key().port_ = event.port;
|
nh.key().port_ = event.port;
|
||||||
|
@ -859,6 +866,7 @@ private:
|
||||||
TR_ASSERT(it != std::end(peers));
|
TR_ASSERT(it != std::end(peers));
|
||||||
(*it)->do_purge = true;
|
(*it)->do_purge = true;
|
||||||
|
|
||||||
|
--stats.known_peer_from_count[info_that.from_first()];
|
||||||
// Note that it_that is invalid after this point
|
// Note that it_that is invalid after this point
|
||||||
graveyard_pool.insert(connectable_pool.extract(it_that));
|
graveyard_pool.insert(connectable_pool.extract(it_that));
|
||||||
|
|
||||||
|
@ -870,6 +878,7 @@ private:
|
||||||
|
|
||||||
if (was_connectable)
|
if (was_connectable)
|
||||||
{
|
{
|
||||||
|
--stats.known_peer_from_count[info_this.from_first()];
|
||||||
graveyard_pool.insert(connectable_pool.extract(info_this.listen_socket_address()));
|
graveyard_pool.insert(connectable_pool.extract(info_this.listen_socket_address()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1357,6 +1357,7 @@ tr_stat tr_torrent::stats() const
|
||||||
for (int i = 0; i < TR_PEER_FROM__MAX; i++)
|
for (int i = 0; i < TR_PEER_FROM__MAX; i++)
|
||||||
{
|
{
|
||||||
stats.peersFrom[i] = swarm_stats.peer_from_count[i];
|
stats.peersFrom[i] = swarm_stats.peer_from_count[i];
|
||||||
|
stats.knownPeersFrom[i] = swarm_stats.known_peer_from_count[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
auto const piece_upload_speed_byps = this->bandwidth_.get_piece_speed_bytes_per_second(now_msec, TR_UP);
|
auto const piece_upload_speed_byps = this->bandwidth_.get_piece_speed_bytes_per_second(now_msec, TR_UP);
|
||||||
|
|
|
@ -1574,10 +1574,14 @@ struct tr_stat
|
||||||
/** Number of peers that we're connected to */
|
/** Number of peers that we're connected to */
|
||||||
uint16_t peersConnected;
|
uint16_t peersConnected;
|
||||||
|
|
||||||
/** How many peers we found out about from the tracker, or from pex,
|
/** How many connected peers we found out about from the tracker, or from pex,
|
||||||
or from incoming connections, or from our resume file. */
|
or from incoming connections, or from our resume file. */
|
||||||
uint16_t peersFrom[TR_PEER_FROM__MAX];
|
uint16_t peersFrom[TR_PEER_FROM__MAX];
|
||||||
|
|
||||||
|
/** How many known peers we found out about from the tracker, or from pex,
|
||||||
|
or from incoming connections, or from our resume file. */
|
||||||
|
uint16_t knownPeersFrom[TR_PEER_FROM__MAX];
|
||||||
|
|
||||||
/** Number of peers that are sending data to us. */
|
/** Number of peers that are sending data to us. */
|
||||||
uint16_t peersSendingToUs;
|
uint16_t peersSendingToUs;
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,13 @@ static NSString* const kWebSeedAnimationId = @"webSeed";
|
||||||
NSUInteger ltep = 0;
|
NSUInteger ltep = 0;
|
||||||
NSUInteger toUs = 0;
|
NSUInteger toUs = 0;
|
||||||
NSUInteger fromUs = 0;
|
NSUInteger fromUs = 0;
|
||||||
|
NSUInteger knownTracker = 0;
|
||||||
|
NSUInteger knownIncoming = 0;
|
||||||
|
NSUInteger knownCache = 0;
|
||||||
|
NSUInteger knownLpd = 0;
|
||||||
|
NSUInteger knownPex = 0;
|
||||||
|
NSUInteger knownDht = 0;
|
||||||
|
NSUInteger knownLtep = 0;
|
||||||
BOOL anyActive = false;
|
BOOL anyActive = false;
|
||||||
for (Torrent* torrent in self.fTorrents)
|
for (Torrent* torrent in self.fTorrents)
|
||||||
{
|
{
|
||||||
|
@ -170,6 +177,13 @@ static NSString* const kWebSeedAnimationId = @"webSeed";
|
||||||
fromUs += torrent.peersGettingFromUs;
|
fromUs += torrent.peersGettingFromUs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
knownTracker += torrent.totalKnownPeersTracker;
|
||||||
|
knownIncoming += torrent.totalKnownPeersIncoming;
|
||||||
|
knownCache += torrent.totalKnownPeersCache;
|
||||||
|
knownLpd += torrent.totalKnownPeersLocal;
|
||||||
|
knownPex += torrent.totalKnownPeersPex;
|
||||||
|
knownDht += torrent.totalKnownPeersDHT;
|
||||||
|
knownLtep += torrent.totalKnownPeersLTEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.fPeers sortUsingDescriptors:self.peerSortDescriptors];
|
[self.fPeers sortUsingDescriptors:self.peerSortDescriptors];
|
||||||
|
@ -210,44 +224,8 @@ static NSString* const kWebSeedAnimationId = @"webSeed";
|
||||||
connectedText = [connectedText stringByAppendingFormat:@": %@", [upDownComponents componentsJoinedByString:@", "]];
|
connectedText = [connectedText stringByAppendingFormat:@": %@", [upDownComponents componentsJoinedByString:@", "]];
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableArray* fromComponents = [NSMutableArray arrayWithCapacity:7];
|
connectedText = [connectedText
|
||||||
if (tracker > 0)
|
stringByAppendingFormat:@"\n%@", [self connectedTextFrom:tracker:incoming:cache:lpd:pex:dht:ltep]];
|
||||||
{
|
|
||||||
[fromComponents addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu tracker", "Inspector -> Peers tab -> peers"),
|
|
||||||
tracker]];
|
|
||||||
}
|
|
||||||
if (incoming > 0)
|
|
||||||
{
|
|
||||||
[fromComponents addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu incoming", "Inspector -> Peers tab -> peers"),
|
|
||||||
incoming]];
|
|
||||||
}
|
|
||||||
if (cache > 0)
|
|
||||||
{
|
|
||||||
[fromComponents
|
|
||||||
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu cache", "Inspector -> Peers tab -> peers"), cache]];
|
|
||||||
}
|
|
||||||
if (lpd > 0)
|
|
||||||
{
|
|
||||||
[fromComponents addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu local discovery", "Inspector -> Peers tab -> peers"),
|
|
||||||
lpd]];
|
|
||||||
}
|
|
||||||
if (pex > 0)
|
|
||||||
{
|
|
||||||
[fromComponents
|
|
||||||
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu PEX", "Inspector -> Peers tab -> peers"), pex]];
|
|
||||||
}
|
|
||||||
if (dht > 0)
|
|
||||||
{
|
|
||||||
[fromComponents
|
|
||||||
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu DHT", "Inspector -> Peers tab -> peers"), dht]];
|
|
||||||
}
|
|
||||||
if (ltep > 0)
|
|
||||||
{
|
|
||||||
[fromComponents
|
|
||||||
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu LTEP", "Inspector -> Peers tab -> peers"), ltep]];
|
|
||||||
}
|
|
||||||
|
|
||||||
connectedText = [connectedText stringByAppendingFormat:@"\n%@", [fromComponents componentsJoinedByString:@", "]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.fConnectedPeersField.stringValue = connectedText;
|
self.fConnectedPeersField.stringValue = connectedText;
|
||||||
|
@ -266,6 +244,67 @@ static NSString* const kWebSeedAnimationId = @"webSeed";
|
||||||
|
|
||||||
self.fConnectedPeersField.stringValue = notActiveString;
|
self.fConnectedPeersField.stringValue = notActiveString;
|
||||||
}
|
}
|
||||||
|
auto totalKnown = knownTracker + knownIncoming + knownCache + knownLpd + knownPex + knownDht + knownLtep;
|
||||||
|
NSString* knownText = [self connectedTextFrom:knownTracker:knownIncoming:knownCache:knownLpd:knownPex:knownDht:knownLtep];
|
||||||
|
if (totalKnown <= 1)
|
||||||
|
{
|
||||||
|
self.fConnectedPeersField.toolTip = [NSLocalizedString(@"Known:", "Inspector -> Peers tab -> peers")
|
||||||
|
stringByAppendingFormat:@" %@", totalKnown > 0 ? knownText : @"0"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self.fConnectedPeersField.toolTip = [[NSString
|
||||||
|
localizedStringWithFormat:NSLocalizedString(@"%lu Known:", "Inspector -> Peers tab -> peers"), totalKnown]
|
||||||
|
stringByAppendingFormat:@" %@", knownText];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*)connectedTextFrom:(NSUInteger)tracker //
|
||||||
|
:(NSUInteger)incoming
|
||||||
|
:(NSUInteger)cache
|
||||||
|
:(NSUInteger)lpd
|
||||||
|
:(NSUInteger)pex
|
||||||
|
:(NSUInteger)dht
|
||||||
|
:(NSUInteger)ltep
|
||||||
|
{
|
||||||
|
NSMutableArray* fromComponents = [NSMutableArray arrayWithCapacity:7];
|
||||||
|
if (tracker > 0)
|
||||||
|
{
|
||||||
|
[fromComponents
|
||||||
|
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu tracker", "Inspector -> Peers tab -> peers"), tracker]];
|
||||||
|
}
|
||||||
|
if (incoming > 0)
|
||||||
|
{
|
||||||
|
[fromComponents
|
||||||
|
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu incoming", "Inspector -> Peers tab -> peers"), incoming]];
|
||||||
|
}
|
||||||
|
if (cache > 0)
|
||||||
|
{
|
||||||
|
[fromComponents
|
||||||
|
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu cache", "Inspector -> Peers tab -> peers"), cache]];
|
||||||
|
}
|
||||||
|
if (lpd > 0)
|
||||||
|
{
|
||||||
|
[fromComponents
|
||||||
|
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu local discovery", "Inspector -> Peers tab -> peers"), lpd]];
|
||||||
|
}
|
||||||
|
if (pex > 0)
|
||||||
|
{
|
||||||
|
[fromComponents
|
||||||
|
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu PEX", "Inspector -> Peers tab -> peers"), pex]];
|
||||||
|
}
|
||||||
|
if (dht > 0)
|
||||||
|
{
|
||||||
|
[fromComponents
|
||||||
|
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu DHT", "Inspector -> Peers tab -> peers"), dht]];
|
||||||
|
}
|
||||||
|
if (ltep > 0)
|
||||||
|
{
|
||||||
|
[fromComponents
|
||||||
|
addObject:[NSString localizedStringWithFormat:NSLocalizedString(@"%lu LTEP", "Inspector -> Peers tab -> peers"), ltep]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [fromComponents componentsJoinedByString:@", "];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)saveViewSize
|
- (void)saveViewSize
|
||||||
|
|
|
@ -160,6 +160,14 @@ extern NSString* const kTorrentDidChangeGroupNotification;
|
||||||
@property(nonatomic, readonly) NSUInteger totalPeersLocal;
|
@property(nonatomic, readonly) NSUInteger totalPeersLocal;
|
||||||
@property(nonatomic, readonly) NSUInteger totalPeersLTEP;
|
@property(nonatomic, readonly) NSUInteger totalPeersLTEP;
|
||||||
|
|
||||||
|
@property(nonatomic, readonly) NSUInteger totalKnownPeersTracker;
|
||||||
|
@property(nonatomic, readonly) NSUInteger totalKnownPeersIncoming;
|
||||||
|
@property(nonatomic, readonly) NSUInteger totalKnownPeersCache;
|
||||||
|
@property(nonatomic, readonly) NSUInteger totalKnownPeersPex;
|
||||||
|
@property(nonatomic, readonly) NSUInteger totalKnownPeersDHT;
|
||||||
|
@property(nonatomic, readonly) NSUInteger totalKnownPeersLocal;
|
||||||
|
@property(nonatomic, readonly) NSUInteger totalKnownPeersLTEP;
|
||||||
|
|
||||||
@property(nonatomic, readonly) NSUInteger peersSendingToUs;
|
@property(nonatomic, readonly) NSUInteger peersSendingToUs;
|
||||||
@property(nonatomic, readonly) NSUInteger peersGettingFromUs;
|
@property(nonatomic, readonly) NSUInteger peersGettingFromUs;
|
||||||
|
|
||||||
|
|
|
@ -1352,6 +1352,41 @@ bool trashDataFile(char const* filename, void* /*user_data*/, tr_error* error)
|
||||||
return self.fStat->peersFrom[TR_PEER_FROM_LTEP];
|
return self.fStat->peersFrom[TR_PEER_FROM_LTEP];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)totalKnownPeersTracker
|
||||||
|
{
|
||||||
|
return self.fStat->knownPeersFrom[TR_PEER_FROM_TRACKER];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)totalKnownPeersIncoming
|
||||||
|
{
|
||||||
|
return self.fStat->knownPeersFrom[TR_PEER_FROM_INCOMING];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)totalKnownPeersCache
|
||||||
|
{
|
||||||
|
return self.fStat->knownPeersFrom[TR_PEER_FROM_RESUME];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)totalKnownPeersPex
|
||||||
|
{
|
||||||
|
return self.fStat->knownPeersFrom[TR_PEER_FROM_PEX];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)totalKnownPeersDHT
|
||||||
|
{
|
||||||
|
return self.fStat->knownPeersFrom[TR_PEER_FROM_DHT];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)totalKnownPeersLocal
|
||||||
|
{
|
||||||
|
return self.fStat->knownPeersFrom[TR_PEER_FROM_LPD];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger)totalKnownPeersLTEP
|
||||||
|
{
|
||||||
|
return self.fStat->knownPeersFrom[TR_PEER_FROM_LTEP];
|
||||||
|
}
|
||||||
|
|
||||||
- (NSUInteger)peersSendingToUs
|
- (NSUInteger)peersSendingToUs
|
||||||
{
|
{
|
||||||
return self.fStat->peersSendingToUs;
|
return self.fStat->peersSendingToUs;
|
||||||
|
|
Loading…
Reference in New Issue