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                              rminternals.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 RMINTERNALS_H
33 #define RMINTERNALS_H
34 
35 #define NUM_TIMERS 5  /* number of timers used by the program */
36 
37 #define RECEIVE             'R'
38 #define SEND                'S'
39 #define RECEIVE_AND_LOSE    'L'
40 
41 #include "rmstruct.h"
42 #include <stdio.h>
43 #include <sys/types.h>
44 #include <netinet/in.h>
45 #include <arpa/inet.h>
46 #include <sys/utsname.h>
47 #include <netdb.h>
48 #include <sys/socket.h>
49 #include <sys/time.h>
50 #include <time.h>
51 #include <string.h>
52 #include <stdlib.h>
53 #include <unistd.h>
54 #include <math.h>
55 #include "rmmsgpckt.h"
56 #include "rmevent.h"
57 #include "rmcache.h"
58 #include "rmmsg.h"
59 
60 #define FOREVER while(1)
61 
62 void *rmcastHandleSignals( void *arg );
63 
64 int   rmcastCreateSocket( int port );
65 
66 void  rmcastSetTTLValue( int soc, int ttl );
67 void  rmcastSetLoopBack( int soc, int loop );
68 
69 void  rmcastJoinGroup( int soc, char *group_addr );
70 int   rmcastLeaveGroup( int soc, char *group_addr );
71 
72 int   rmcastSendPacket( int soc, BYTE *message, int message_size );
73 void  *rmcastReceivePackets( void *soc );
74 
75 int   rmcastCatchEvents( int i );
76 
77 /****************************************************************************************************/
78 
79 /* Routines To Facilitate the Interface with the Event List and the Cache */
80 
81 int    rmcastRemoveEvent( PACKET_INFO *packt, int event_type );
82 int    rmcastFindEvent( PACKET_INFO *packt, int event_type );
83 int    rmcastCacheContains( PACKET_INFO *packt );
84 int    rmcastInsertEvent( PACKET_INFO *packt, int event_type );
85 void   rmcastProcessDataPacket( PACKET_INFO pckt_info );
86 void   rmcastProcessRefreshPacket( PACKET_INFO pckt_info );
87 double generate_uniform( void );
88 
89 void lock_eventlist_and_cache();
90 void unlock_eventlist_and_cache();
91 
92 void showLogMsg( char type, PACKET_INFO *pckt_info );
93 
94 /****************************************************************************************************/
95 
96 #define MAX_HOSTS 10 /* Maximum number of hosts which timers will be stored */
97 
98 struct SHOSTS_DELAYS
99 {
100     char IP[IP_STRING_SIZE];   /* Host IP */
101     int estimated_delay;       /* Estimated one-way delay to host */
102 };
103 
104 typedef struct SHOSTS_DELAYS HOSTS_DELAYS;
105 
106 struct SGLOBAL_OPTIONS
107 {
108 
109     int        *pipe;
110     char       tcp_ip[ IP_STRING_SIZE ];
111     int        tcp_port;
112     void       (*shut_down_routine)(void);
113     int        cur_state_server_is_up;
114     char       dest_ip[IP_STRING_SIZE]; /* this is the destination ip used in the connection to the multicast group (or unicast destination host) */
115     int        dest_port;
116     int        ttl;
117     unsigned int microsleep;
118     int        hosts_identified;
119     int        timer_distribution;
120     int        max_nak; /* max number of NAKs that can be sent for each sn */
121 /*
122  * We will be able to retransmit the last max_member_cache_size packets from each member of the multicast group,
123  * i.e., we will store the last max_member_cache_size packets from each member of the multicast group in the cache.
124  */
125     int        max_member_cache_size;
126     int        version;
127     int        transmission_mode;
128     char       log_file[ 255 ];
129     int        new_member_support;
130     int        statistics;
131     int        refresh_timer;
132     float      loss_prob;
133     int        leave_group_wait_time;
134     int        rcv_buffer_size;
135     HOSTS_DELAYS hosts_delays[ MAX_HOSTS ];
136     int        timer_paramA;
137     int        timer_paramB;
138     int        timer_paramC;
139     int        timer_paramD;
140     int        timer_paramE;
141     int        timer_paramF;
142 };
143 
144 typedef struct SGLOBAL_OPTIONS GLOBAL_OPTIONS;
145 
146 /****************************************************************************************************/
147 
148 struct SUSER_INFO
149 {
150 	struct TIMER
151 	{
152 		int min,max;
153 	} timer[ NUM_TIMERS ];
154 
155 	struct GROUP_ID
156 	{
157 		char ip[ IP_STRING_SIZE ]; /* ip address and... */
158 		int port;    /* port of the group  */
159 	} group_id;
160 
161 	MEMBER_ID member_id;
162 	int cache_size;
163 	int sn;
164 	int socket;
165 };
166 
167 typedef struct SUSER_INFO USER_INFO;
168 
169 /****************************************************************************************************/
170 
171 #endif
172