summaryrefslogtreecommitdiffstats
path: root/src/peer.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-09-12 16:53:24 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-09-12 16:53:24 +0200
commit7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3 (patch)
treeb06313240468ccee6923366d66eebf583e029162 /src/peer.h
parentd116950984d78392e1daf0adfd89f6cdb4fe8076 (diff)
downloadfastd-7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3.tar
fastd-7ebbe05f46e1b8530a61dd144a4bf36a1c63a4a3.zip
Add per-peer stats
Diffstat (limited to 'src/peer.h')
-rw-r--r--src/peer.h16
1 files changed, 16 insertions, 0 deletions
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
+}