You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

accept.h 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef ACCEPT_H
  19. #define ACCEPT_H
  20. #define MAX_CONNECTIONS 512
  21. #define MAX_ACCEPTS 16
  22. #define FREE_ACCEPT_TIME 4 /*in seconds */
  23. /*
  24. * This struct keep tracks of single connection to the server.
  25. * The thread_daemon who handle the connection knows the connection
  26. * position in the accept_tbl.
  27. */
  28. struct accept_table {
  29. inet_prefix ip; /*Ip of the node connected */
  30. unsigned char accepts; /*Number of connection from this node */
  31. pid_t *pid; /*The pid of each child that have accepted the conn */
  32. unsigned char *closed; /*Each element of this array is 1 or 0. It indicates if the connection has
  33. been closed */
  34. time_t *acp_t; /*The time when the connection was accepted. The "accepts" counter
  35. will decrement when one of the acp_t+FREE_ACCEPT_TIME will
  36. be <= current_time AND (the relative pid will be non existent OR
  37. the relative closed element will be == 1)
  38. */
  39. struct request_tbl rqtbl; /*The request table */
  40. };
  41. /* This struct keeps all the info regarding each node connected */
  42. struct accept_table *accept_tbl;
  43. /*
  44. * accept_idx is the position of the accept_tbl of a thread.
  45. * accept_sidx is the second index, it is used for example in pid[accept_sidx]
  46. * note: this var are used only in the child and the child doesn't need to modify them!
  47. */
  48. int accept_idx, accept_sidx;
  49. pthread_mutex_t mtx_acpt_idx, mtx_acpt_sidx;
  50. int update_accept_tbl_mutex;
  51. int max_connections, max_accepts_per_host, free_accept_time;
  52. void init_accept_tbl(int startups, int accepts, int time);
  53. void destroy_accept_tbl(void);
  54. void update_accept_tbl(void);
  55. int find_ip_acpt(inet_prefix ip);
  56. int find_first_free(void);
  57. int is_ip_acpt_free(inet_prefix ip, int *index);
  58. int find_free_acp_t(int idx);
  59. int new_accept(int idx, inet_prefix ip);
  60. int add_accept(inet_prefix ip, int replace);
  61. void del_accept(int idx, int *sidx);
  62. int close_accept(int idx, int sidx);
  63. void add_accept_pid(pid_t pid, int idx, int sidx);
  64. #endif /*ACCEPT_H */