1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>
#include <pthread.h>
#include "uthash/utlist.h"
#include "monitor_private.h"
/******************************************** connection manager *****************************************/
struct stm_connection_manager *stm_connection_insert(struct evhttp_connection *evconn)
{
struct stellar_monitor *stm = stellar_monitor_get();
struct stm_connection_manager *conn_mgr = stm->connection_mgr;
struct stm_connection_manager *ele, *tmp;
DL_FOREACH_SAFE(conn_mgr, ele, tmp) // check if current connection already exist
{
if (ele->conn == evconn)
{
stm->gettime_cb(&ele->last_active_time, NULL);
return ele;
}
}
stm_stat_update(stm->stat, stm->worker_thread_num, STM_STAT_CLI_CONNECTION_NEW, 1);
struct stm_connection_manager *new_conn = (struct stm_connection_manager *)calloc(1, sizeof(struct stm_connection_manager));
char *tmp_ip_addr;
uint16_t tmp_port;
evhttp_connection_get_peer(evconn, &tmp_ip_addr, &tmp_port);
if (tmp_ip_addr)
{
strncpy(new_conn->peer_ipaddr, tmp_ip_addr, INET6_ADDRSTRLEN - 1);
}
new_conn->peer_port_host_order = tmp_port;
stm->gettime_cb(&new_conn->link_start_time, NULL);
new_conn->last_active_time = new_conn->link_start_time;
new_conn->conn = evconn;
DL_APPEND(stm->connection_mgr, new_conn);
return new_conn;
}
void stm_connection_delete(struct evhttp_connection *evconn)
{
struct stellar_monitor *stm = stellar_monitor_get();
struct stm_connection_manager *conn_mgr = stm->connection_mgr;
struct stm_connection_manager *ele, *tmp;
DL_FOREACH_SAFE(conn_mgr, ele, tmp)
{
if (ele->conn == evconn)
{
DL_DELETE(conn_mgr, ele);
FREE(ele);
}
}
stm->connection_mgr = conn_mgr;
}
void stm_connection_update(struct stm_connection_manager *conn_mgr, const struct evhttp_connection *evconn)
{
struct stellar_monitor *stm = stellar_monitor_get();
struct stm_connection_manager *ele, *tmp;
DL_FOREACH_SAFE(conn_mgr, ele, tmp)
{
if (ele->conn == evconn)
{
stm->gettime_cb(&ele->last_active_time, NULL);
}
}
}
const struct stm_connection_manager *stm_connection_search(const struct stm_connection_manager *conn_mgr_head, const struct evhttp_connection *evconn)
{
const struct stm_connection_manager *ele, *tmp;
DL_FOREACH_SAFE(conn_mgr_head, ele, tmp)
{
if (ele->conn == evconn)
{
return ele;
}
}
return NULL;
}
|