From 7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 12 Sep 2014 16:53:24 +0200 Subject: Add per-peer stats --- src/peer.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/peer.h') diff --git a/src/peer.h b/src/peer.h index ba97d2b..8c7ef88 100644 --- a/src/peer.h +++ b/src/peer.h @@ -72,6 +72,8 @@ struct fastd_peer { fastd_timeout_t timeout; /**< The timeout after which the peer is reset */ fastd_timeout_t keepalive_timeout; /**< The timeout after which a keepalive is sent to the peer */ + fastd_stats_t stats; /**< Traffic statistics */ + const fastd_peer_group_t *group; /**< The peer group the peer belongs to */ VECTOR(fastd_remote_t) remotes; /**< The vector of the peer's remotes */ @@ -270,3 +272,17 @@ fastd_peer_t * fastd_peer_find_by_eth_addr(fastd_eth_addr_t addr); void fastd_peer_handle_handshake_queue(void); void fastd_peer_maintenance(void); + +/** Adds statistics for a single packet of a given size */ +static inline void fastd_stats_add(UNUSED fastd_peer_t *peer, UNUSED fastd_stat_type_t stat, UNUSED size_t bytes) { +#ifdef WITH_STATUS_SOCKET + if (!bytes) + return; + + ctx.stats.packets[stat]++; + ctx.stats.bytes[stat] += bytes; + + peer->stats.packets[stat]++; + peer->stats.bytes[stat] += bytes; +#endif +} -- cgit v1.2.3