The Netsukuku Project  0.0.9
An Alternative routing method
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
accept.h
Go to the documentation of this file.
1 /* This file is part of Netsukuku
2  * (c) Copyright 2004 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3  *
4  * This source code is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * This source code is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  * Please refer to the GNU Public License for more details.
13  *
14  * You should have received a copy of the GNU Public License along with
15  * this source code; if not, write to:
16  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18 
19 #ifndef ACCEPT_H
20 #define ACCEPT_H
21 
22 #define MAX_CONNECTIONS 512
23 
24 #define MAX_ACCEPTS 16
25 #define FREE_ACCEPT_TIME 4 /*in seconds*/
26 
27 /*
28  * This struct keep tracks of single connection to the server.
29  * The thread_daemon who handle the connection knows the connection
30  * position in the accept_tbl.
31  */
33 {
34  inet_prefix ip; /*Ip of the node connected*/
35  unsigned char accepts; /*Number of connection from this node*/
36  pid_t *pid; /*The pid of each child that have accepted the conn*/
37  unsigned char *closed; /*Each element of this array is 1 or 0. It indicates if the connection has
38  been closed*/
39  time_t *acp_t; /*The time when the connection was accepted. The "accepts" counter
40  will decrement when one of the acp_t+FREE_ACCEPT_TIME will
41  be <= current_time AND (the relative pid will be non existent OR
42  the relative closed element will be == 1)
43  */
44  struct request_tbl rqtbl; /*The request table*/
45 };
46 
47 /* This struct keeps all the info regarding each node connected */
49 
50 /*
51  * accept_idx is the position of the accept_tbl of a thread.
52  * accept_sidx is the second index, it is used for example in pid[accept_sidx]
53  * note: this var are used only in the child and the child doesn't need to modify them!
54  */
56 pthread_mutex_t mtx_acpt_idx, mtx_acpt_sidx;
57 
59 
61 
62 void init_accept_tbl(int startups, int accepts, int time);
63 void destroy_accept_tbl(void);
64 void update_accept_tbl(void);
66 int find_first_free(void);
67 int is_ip_acpt_free(inet_prefix ip, int *index);
68 int find_free_acp_t(int idx);
69 int new_accept(int idx, inet_prefix ip);
70 int add_accept(inet_prefix ip, int replace);
71 void del_accept(int idx, int *sidx);
72 int close_accept(int idx, int sidx);
73 void add_accept_pid(pid_t pid, int idx, int sidx);
74 
75 #endif /*ACCEPT_H*/
int close_accept(int idx, int sidx)
Definition: accept.c:256
int add_accept(inet_prefix ip, int replace)
Definition: accept.c:211
int max_accepts_per_host
Definition: accept.h:60
int is_ip_acpt_free(inet_prefix ip, int *index)
Definition: accept.c:156
int find_ip_acpt(inet_prefix ip)
Definition: accept.c:134
pthread_mutex_t mtx_acpt_idx
Definition: accept.h:56
int accept_idx
Definition: accept.h:55
unsigned char accepts
Definition: accept.h:35
void destroy_accept_tbl(void)
Definition: accept.c:67
int accept_sidx
Definition: accept.h:55
Definition: request.h:145
Definition: inet.h:73
int free_accept_time
Definition: accept.h:60
void init_accept_tbl(int startups, int accepts, int time)
Definition: accept.c:38
struct request_tbl rqtbl
Definition: accept.h:44
struct accept_table * accept_tbl
Definition: accept.h:48
inet_prefix ip
Definition: accept.h:34
int find_free_acp_t(int idx)
Definition: accept.c:176
void del_accept(int idx, int *sidx)
Definition: accept.c:239
Definition: accept.h:32
void add_accept_pid(pid_t pid, int idx, int sidx)
Definition: accept.c:267
int new_accept(int idx, inet_prefix ip)
Definition: accept.c:188
int max_connections
Definition: accept.h:60
time_t * acp_t
Definition: accept.h:39
void update_accept_tbl(void)
Definition: accept.c:86
pid_t * pid
Definition: accept.h:36
pthread_mutex_t mtx_acpt_sidx
Definition: accept.h:56
unsigned char * closed
Definition: accept.h:37
int find_first_free(void)
Definition: accept.c:146
int update_accept_tbl_mutex
Definition: accept.h:58