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.

qspn.h 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 QSPN_H
  19. #define QSPN_H
  20. #include "gmap.h"
  21. #define QSPN_WAIT_ROUND 32 /*This is a crucial value. It is the number of
  22. seconds to be waited before the next qspn_round
  23. can be sent */
  24. #define QSPN_WAIT_ROUND_MS QSPN_WAIT_ROUND*1000
  25. #define QSPN_WAIT_DELTA_MS 64 /*If a qspn_round is sent while
  26. qspn_round_left() < QSPN_WAIT_DELTA_MS,
  27. then it is acceptable */
  28. #ifdef DEBUG
  29. #undef QSPN_WAIT_ROUND
  30. #define QSPN_WAIT_ROUND 8
  31. #endif
  32. /*Wait time bound to a specific level: y = (w/2)*x + w/(x+1) */
  33. #define QSPN_WAIT_ROUND_LVL(level) ((level)*(QSPN_WAIT_ROUND/2) + \
  34. QSPN_WAIT_ROUND/((level)+1))
  35. #define QSPN_WAIT_ROUND_MS_LVL(level) (QSPN_WAIT_ROUND_LVL(level)*1000)
  36. /* The delta grows in this way: y = x*(w/2) + 2*w*x + w; */
  37. #define QSPN_WAIT_DELTA_MS_LVL(level) ((level)*(QSPN_WAIT_DELTA_MS/2) + \
  38. 2*QSPN_WAIT_DELTA_MS*(level) + QSPN_WAIT_DELTA_MS)
  39. /* This list keeps tracks of the qspn_pkts sent or
  40. * received by our rnodes*/
  41. struct qspn_buffer {
  42. LLIST_HDR(struct qspn_buffer);
  43. map_node *rnode; /* the rnode this buf is referring to */
  44. u_int replies; /* How many replies we forwarded/sent
  45. to `rnode' */
  46. u_char *replier; /* Who has sent these replies (qspn_sub_id) */
  47. u_short *flags;
  48. };
  49. /*
  50. * * * Global vars * * *
  51. */
  52. struct qspn_buffer **qspn_b; /*It is sizeof(struct qspn_buffer *)*levels big */
  53. int *qspn_send_mutex; /*It is sizeof(int)*levels big. */
  54. #define GCOUNT_LEVELS (MAX_LEVELS-ZERO_LEVEL+UNITY_LEVEL)
  55. /*
  56. * qspn_gnode_count[x] is the number of nodes present in the gnode
  57. * me.cur_quadg.gnode[x], it is updated at each qspn_round.
  58. * Use the _EL() macro!
  59. */
  60. u_int qspn_gnode_count[GCOUNT_LEVELS];
  61. /* gcount of the previous qspn_round */
  62. u_int qspn_old_gcount[GCOUNT_LEVELS];
  63. /*
  64. * * Functions declaration * *
  65. */
  66. void qspn_time_reset(int start_level, int end_level, int levels);
  67. void qspn_reset_counters(u_char levels);
  68. void qspn_reset(u_char levels);
  69. void qspn_init(u_char levels);
  70. void qspn_free(void);
  71. void qspn_set_map_vars(u_char level, map_node ** map,
  72. map_node ** root_node, int *root_node_pos,
  73. map_gnode ** gmap);
  74. void qspn_b_clean(u_char level);
  75. int qspn_b_add(struct qspn_buffer *qb, u_char replier, u_short flags);
  76. int qspn_b_find_reply(struct qspn_buffer *qb, int sub_id);
  77. struct qspn_buffer *qspn_b_find_rnode(struct qspn_buffer *qb,
  78. map_node * rnode);
  79. int qspn_b_del_dead_rnodes(struct qspn_buffer **qb, map_node * root_node);
  80. void qspn_b_del_all_dead_rnodes(void);
  81. int qspn_round_left(u_char level);
  82. void update_qspn_time(u_char level, u_int new_qspn_time);
  83. void qspn_inc_gcount(u_int * gcount, int level, int inc);
  84. void qspn_dec_gcount(u_int * gcount, int level, int dec);
  85. void qspn_reset_gcount(u_int * gcount, int level, int value);
  86. void qspn_backup_gcount(u_int * old_gcount, int *gcount);
  87. void qspn_new_round(u_char level, int new_qspn_id, u_int new_qspn_time);
  88. int qspn_send(u_char level);
  89. int qspn_close(PACKET rpkt);
  90. int qspn_open(PACKET rpkt);
  91. #endif /*QSPN_H */