Commit 612078b8 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Updated tport with custom packet counter and packet rate method + version bump

parent cdaace7c
......@@ -11,12 +11,12 @@ dnl information on the package
dnl ---------------------------
dnl update both the version for AC_INIT and the LIBSOFIA_SIP_UA_MAJOR_MINOR
AC_INIT([sofia-sip], [1.12.11devel])
AC_INIT([sofia-sip], [1.13.0-bc])
AC_CONFIG_SRCDIR([libsofia-sip-ua/sip/sofia-sip/sip.h])
AC_CONFIG_MACRO_DIR([m4])
AC_SUBST(VER_LIBSOFIA_SIP_UA_MAJOR_MINOR, [1.12])
AC_SUBST(VER_LIBSOFIA_SIP_UA_MAJOR_MINOR, [1.13])
dnl Includedir specific to this sofia version
AC_SUBST(include_sofiadir, '${includedir}/sofia-sip-1.12')
AC_SUBST(include_sofiadir, '${includedir}/sofia-sip-1.13')
AC_SUBST(LIBVER_SOFIA_SIP_UA_CUR, [6])
AC_SUBST(LIBVER_SOFIA_SIP_UA_REV, [0])
AC_SUBST(LIBVER_SOFIA_SIP_UA_AGE, [6])
......
......@@ -52,6 +52,8 @@
#include <sofia-sip/tport_tag.h>
#endif
#include <sys/time.h>
SOFIA_BEGIN_DECLS
struct tport_s;
......@@ -369,6 +371,8 @@ TPORT_DLL char *tport_hostport(char buf[], isize_t bufsize,
TPORT_DLL int tport_keepalive(tport_t *tp, su_addrinfo_t const *ai,
tag_type_t tag, tag_value_t value, ...);
TPORT_DLL float tport_get_packet_count_rate(tport_t *tp);
/* ---------------------------------------------------------------------- */
/* SigComp-related functions */
......
......@@ -543,6 +543,10 @@ tport_t *tport_tcreate(tp_stack_t *stack,
tpn->tpn_host = "*";
tpn->tpn_canon = "*";
tpn->tpn_port = "*";
gettimeofday(&mr->mr_master->tp_dos_stats.last_check_recv_msg_check_time, NULL);
mr->mr_master->tp_dos_stats.recv_msg_count_since_last_check = 0;
mr->mr_master->tp_dos_stats.packet_count_rate = 0;
ta_start(ta, tag, value);
......@@ -5056,6 +5060,7 @@ void tport_recv_bytes(tport_t *self, ssize_t bytes, ssize_t on_line)
/** @internal Update message-based receive statistics. */
void tport_recv_message(tport_t *self, msg_t *msg, int error)
{
struct timeval now;
error = error != 0;
self->tp_stats.recv_msgs++;
......@@ -5071,6 +5076,19 @@ void tport_recv_message(tport_t *self, msg_t *msg, int error)
self->tp_stats.recv_msgs++;
self->tp_stats.recv_errors += error;
self->tp_dos_stats.recv_msg_count_since_last_check++;
gettimeofday(&now, NULL);
time_t time_elapsed = now.tv_sec - self->tp_dos_stats.last_check_recv_msg_check_time.tv_sec;
if (time_elapsed < 0) {
self->tp_dos_stats.packet_count_rate = 0;
self->tp_dos_stats.recv_msg_count_since_last_check = 0;
self->tp_dos_stats.last_check_recv_msg_check_time = now;
} else if (time_elapsed >= 1) {
self->tp_dos_stats.packet_count_rate = self->tp_dos_stats.recv_msg_count_since_last_check / time_elapsed;
self->tp_dos_stats.recv_msg_count_since_last_check = 0;
self->tp_dos_stats.last_check_recv_msg_check_time = now;
}
}
/** @internal Update send statistics. */
......@@ -5111,3 +5129,7 @@ void tport_sent_message(tport_t *self, msg_t *msg, int error)
self->tp_stats.sent_msgs++;
self->tp_stats.sent_errors += error;
}
float tport_get_packet_count_rate(tport_t *tp) {
return tp->tp_dos_stats.packet_count_rate;
}
......@@ -242,6 +242,12 @@ struct tport_s {
uint64_t sent_msgs, sent_errors, sent_bytes, sent_on_line;
uint64_t recv_msgs, recv_errors, recv_bytes, recv_on_line;
} tp_stats;
struct {
uint64_t recv_msg_count_since_last_check;
struct timeval last_check_recv_msg_check_time;
float packet_count_rate;
} tp_dos_stats;
};
/** @internal Primary structure */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment