-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathctx.h
162 lines (123 loc) · 3.68 KB
/
ctx.h
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* @(#) client/server context data structures and interfaces
*
* Copyright 2008-2011 Pavel V. Cherenkov ([email protected]) ([email protected])
*
* This file is part of udpxy.
*
* udpxy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* udpxy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with udpxy. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UDPXY_CTX_H_0111081738
#define UDPXY_CTX_H_0111081738
#include <sys/types.h>
#include <unistd.h>
#include <netinet/in.h>
#include "udpxy.h"
#include "dpkt.h"
#ifdef __cpluspplus
extern "C" {
#endif
/* throughput statistics */
struct tput_stat {
int32_t sender_id;
double nbytes; /* how many bytes transferred */
double nsec; /* within how many seconds */
};
/* context of a relay client */
struct client_ctx
{
pid_t pid;
char mcast_addr[ IPADDR_STR_SIZE ];
uint16_t mcast_port;
char src_addr[ IPADDR_STR_SIZE ];
uint16_t src_port;
struct tput_stat
tstat;
char tail[ MAX_TAIL_LEN + 1 ];
};
/* statistics on traffic relay & data gathering
*/
struct tps_data {
pid_t pid; /* our PID - cached */
time_t tm_from; /* last time update sent (successfully) */
double niter; /* number of iterations since last try */
double nbytes; /* bytes transferred since last update */
};
/* server request components */
struct srv_request {
char cmd[ MAX_CMD_LEN + 1 ];
char param[ MAX_PARAM_LEN + 1 ];
char tail[ MAX_TAIL_LEN + 1 ];
};
/* context of the server */
struct server_ctx
{
int lsockfd;
char listen_addr[ IPADDR_STR_SIZE ];
uint16_t listen_port;
char mcast_ifc_addr[ IPADDR_STR_SIZE ];
struct in_addr
mcast_inaddr;
struct srv_request rq; /* (current) request to process */
size_t clfree,
clmax;
struct client_ctx*
cl;
u_short rcv_tmout, /* receive/send timeout */
snd_tmout;
int cpipe[ 2 ]; /* client communications pipe */
};
/* initialize server context data
*/
int
init_server_ctx( struct server_ctx* ctx,
const size_t max,
const char* laddr,
uint16_t lport,
const char* mifc_addr );
/* release server context
*/
void
free_server_ctx( struct server_ctx* ctx );
/* find index of the first client with the given pid
*/
int
find_client( const struct server_ctx* ctx, pid_t pid );
/* add client to server context
*/
int
add_client( struct server_ctx* ctx,
pid_t cpid, const char* maddr, uint16_t mport,
int sockfd );
/* delete client from server context
*/
int
delete_client( struct server_ctx* ctx, pid_t cpid );
/* init traffic relay statistics
*/
void
tpstat_init( struct tps_data* d, int setpid );
/* send statistics update to server (if it's time)
*/
void
tpstat_update( struct server_ctx* ctx,
struct tps_data* d, ssize_t nbytes );
/* read client statistics data and update the context
*/
int
tpstat_read( struct server_ctx* ctx );
#ifdef __cpluspplus
}
#endif
#endif /* UDPXY_CTX_H_0111081738 */
/* __EOF__ */