1 /* 2 * Copyright (C) 2002-2009, Edmundo Albuquerque de Souza e Silva. 3 * 4 * This file may be distributed under the terms of the Q Public License 5 * as defined by Trolltech AS of Norway and appearing in the file 6 * LICENSE.QPL included in the packaging of this file. 7 * 8 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 9 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 10 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 11 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 12 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 13 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 14 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * 16 */ 17 18 /*************************************************************************** 19 rmstruct.h 20 ------------------- 21 begin : May 2001 22 Authors : Jorge Allyson Azevedo 23 Milena Scanferla 24 Daniel Sadoc 25 email : {allyson,milena,sadoc}@land.ufrj.br 26 ***************************************************************************/ 27 28 #ifdef HAVE_CONFIG_H 29 #include "../config.h" 30 #endif 31 32 #ifndef MSTRUCT_H 33 34 #include <stdio.h> 35 #include <sys/time.h> 36 #include <unistd.h> 37 38 #ifdef SOLARIS 39 #include <strings.h> 40 #endif 41 42 #ifndef SOLARIS 43 #define SOCKLEN_TYPE (socklen_t*) 44 #else 45 #define SOCKLEN_TYPE 46 #endif 47 48 #define MSTRUCT_H 49 50 #ifdef SINGLE_NACK 51 #define MAX_WINDOW_SIZE 64 52 #endif 53 54 /* Transmission modes */ 55 #define MULTICAST 0 56 #define UNICAST 1 57 58 /* Packet types */ 59 #define DATA_PACKET_TYPE 1 60 #define RETRANSM_PACKET_TYPE 2 61 #define NAK_PACKET_TYPE 3 62 #define REFRESH_PACKET_TYPE 4 63 #define JOIN_REQUEST_PACKET_TYPE 5 64 #define JOIN_ACCEPT_PACKET_TYPE 6 65 #define LEAVE_GROUP_PACKET_TYPE 7 66 67 #define IP_STRING_SIZE 16 68 69 /* Member status in the cache */ 70 #define CACHE_STATUS_DEACTIVE 0 71 #define CACHE_STATUS_ACTIVE 1 72 #define CACHE_STATUS_ANY 2 73 74 #ifndef TRUE 75 76 #define TRUE 1 77 #define FALSE 0 78 79 #endif 80 81 #ifdef RANDOM_TIMERS 82 /* Distributions available for the random timers */ 83 #define UNIFORM 0 84 #define EXPONENTIAL 1 85 #endif 86 87 typedef unsigned char BYTE; 88 89 90 /*************** members info *****************************************/ 91 92 struct SMEMBER_ID 93 { 94 char ip[IP_STRING_SIZE]; /* ip address and... */ 95 int pid; /* process id of the member */ 96 97 }; 98 99 typedef struct SMEMBER_ID MEMBER_ID; 100 101 struct SMEMBER_STATUS 102 { 103 int first_rcv; /* first packet received from a specific member */ 104 int last_rcv; /* last packet received from a specific member */ 105 int last_seq_rcv; /* last packet received in the correct order 106 from a specific member. Please, note that this 107 is also used as the base for the sliding window 108 used to restrict the sending of NACKs. 109 See documentation for more details. */ 110 int last_identified; /* last packet received, or to which a nack was sent */ 111 112 #ifdef SINGLE_NACK 113 int window_size; 114 int window_mask[MAX_WINDOW_SIZE]; 115 int window_ini; 116 #endif 117 118 }; 119 120 typedef struct SMEMBER_STATUS MEMBER_STATUS; 121 122 123 /************** session member information ***************************/ 124 125 struct SSM_INFO 126 { 127 MEMBER_ID member_id; 128 MEMBER_STATUS member_status; 129 }; 130 131 typedef struct SSM_INFO SM_INFO ; 132 133 134 /**************** data packet info *************************************/ 135 136 struct SDATA_PACKET 137 { 138 int sn; /* sequence number */ 139 int data_size; /* number of data bytes */ 140 BYTE *data; /* data to be sent or data received */ 141 }; 142 143 typedef struct SDATA_PACKET DATA_PACKET; 144 145 146 /**************** cache info ******************************************/ 147 148 struct SCACHE_NODE 149 { 150 DATA_PACKET data_pckt; 151 struct SCACHE_NODE *next, *previous; /* pointers to next and previous nodes */ 152 153 }; 154 155 typedef struct SCACHE_NODE CACHE_NODE; 156 157 struct SNAK_LIST 158 { 159 int sn; 160 int counter; 161 struct SNAK_LIST *previous; 162 struct SNAK_LIST *next; 163 }; 164 165 typedef struct SNAK_LIST NAK_LIST; 166 167 struct SCACHE 168 { 169 int number_of_nodes; /* number of nodes currently stored for a specific member */ 170 171 int active; /* active == 0 means the member has left the multicast group */ 172 173 SM_INFO sm_info; 174 175 CACHE_NODE *first, /* pointer to the first of the packets stored for a specific member */ 176 *last, /* pointer to the last of the packets stored for a specific member */ 177 *last_inserted; /* pointer to the last of the packets inserted for a specific member */ 178 179 NAK_LIST *nak_list; /* Pointer to nak list */ 180 181 struct SCACHE *next; 182 183 }; 184 185 typedef struct SCACHE CACHE; 186 187 /*************** events information**************************************/ 188 189 struct SEVENT_LIST 190 { 191 MEMBER_ID *member_id; 192 193 char action; /* action to be executed */ 194 195 long timer_value; /* time when this action will be executed */ 196 197 int sn; /* sequence number */ 198 199 struct timeval last_update_time; /* Last time when the timer was updated */ 200 201 struct SEVENT_LIST *next; 202 }; 203 204 typedef struct SEVENT_LIST EVENT_LIST; 205 206 /*************** packet information**************************************/ 207 208 struct SRETRANSM_PACKET 209 { 210 MEMBER_ID original_sender_id; 211 DATA_PACKET data_packet; 212 }; 213 214 typedef struct SRETRANSM_PACKET RETRANSM_PACKET; 215 216 217 struct SNAK_PACKET 218 { 219 MEMBER_ID requested_member_id; 220 int sn; 221 #ifdef SINGLE_NACK 222 int base_sn; 223 int window_size; 224 int hmask, lmask; /* higher and lower parts of the mask, respectively */ 225 #endif 226 }; 227 228 typedef struct SNAK_PACKET NAK_PACKET; 229 230 231 232 struct SREFRESH_PACKET 233 { 234 int sn_of_last_msg_sent; /* sequence number of last message sent */ 235 }; 236 237 238 typedef struct SREFRESH_PACKET REFRESH_PACKET; 239 240 241 242 struct SJOIN_ACCEPT_PACKET 243 { 244 int port; 245 }; 246 247 248 typedef struct SJOIN_ACCEPT_PACKET JOIN_ACCEPT_PACKET; 249 250 251 struct SPACKET_INFO 252 { 253 char type; /* the type of the packet */ 254 255 BYTE flags; /* flags field */ 256 257 MEMBER_ID sender_id; /* id of the sender of the packet */ 258 259 int packet_size; /* the size, in bytes, of the packet */ 260 261 union PACKET_DATA 262 { 263 DATA_PACKET data_packet; 264 RETRANSM_PACKET retransm_packet; 265 NAK_PACKET nak_packet; 266 REFRESH_PACKET refresh_packet; 267 JOIN_ACCEPT_PACKET join_accept_packet; 268 } packet_data; 269 }; 270 271 typedef struct SPACKET_INFO PACKET_INFO; 272 273 /************************************************************************/ 274 275 #endif 276 277 278