Revision da5dade7 transmissionHandler.h

View differences:

transmissionHandler.h
196 196
#define MSG_HEADER_SIZE 23
197 197
#pragma pack(pop)   /* restore original alignment from stack */
198 198

  
199

  
200
/**
201
 * The init method needs to be called to initialise the transmissionHandler
202
 * @param recv_data_cb This is a boolean that decides how an upper layer receives data. When the boolean is set to true data is received via callback. When it is set to false the upper layer has to poll with the recv_data function. 
203
 * @param timeout_value A timeout value for the data receival
204
 * @param port A port that will be used to create a new UDP socket 
205
 * @param ipaddr An ipaddress that will be used to create a new UDP socket. If left NULL th
206
e messaging layer binds it to localhost. 
207
 * @param stun_port The port of the stun server.
208
 * @param stun_ipaddr The ip address of the stun server. 
209
 * @param local_socketID_cb A callback from the type receive_localsocketID_cb that is envoke once the socketID is ready to use.
210
 * @param arg A void pointer that is used in this implementation to handover the libevent pointer. 
211
 */
212
void init_transmissionHandler(bool recv_data_cb,struct timeval timeout_value,const int port,const char *ipaddr,const int stun_port,const char *stun_ipaddr,receive_localsocketID_cb local_socketID_cb,void *arg);
213

  
214
/**
215
 * create a socket: returns a socketID handle  
216
 * A socketID handle is a pointer to the opague data structre
217
 * @param port A port that will be used to create a new UDP socket
218
 * @param ipaddr An ipaddress that will be used to create a new UDP socket. If left NULL the messaging layer binds it to localhost. 
219
 */
220
void create_socket(const int port,const char *ipaddr);
221

  
222
/**
223
 * destroys a socket 
224
 * @param socketID The socketID handle to the socket ID that shall be destroyed.
225
 */
226
void close_socket(socketID_handle socketID);
227

  
228
/**
229
 * opens a connection between two socketIDs
230
 * @param local_socketID The local socketID
231
 * @param external_socketID The remote socketID
232
 * @param connectionID A pointer to an int. The connectionID will be stored in that int. 
233
 * @param connection_cb  A function pointer to a callback function from the type receive_connection_cb
234
 * @param arg A void pointer that is returned via the callback.
235
 * @return returnValue the connectionId, < 0 for a failure.
236
 */
237
int open_connection(socketID_handle external_socketID,receive_connection_cb connection_cb,void *arg);
238

  
239
/**
240
 * destroys a connections
241
 * @param connectionID 
242
 */
243
void close_connection(const int connectionID);
244

  
245

  
246
/**
247
  * Send a NAT traversal keep alive
248
  * @param connectionID
249
  */
250
void keep_connection_alive(const int connectionID);
251

  
252
/**
253
 * send all data
254
 * @param connectionID The connection the data should be send to.
255
 * @param container A container for several buffer pointer and length pairs from type send_all_data_container
256
 * @param nr_entries The number of buffer pointer and length pairs in the container. The maximum nr is 5.  
257
 * @param msgtype The message type.
258
 * @param sParams A pointer to a send_params struct.
259
 * @return 0 if a problem occured, 1 if everything was alright. 
260
 */
261
int send_all_data(const int connectionID,send_all_data_container *container,int nr_entries,unsigned char msgtype,send_params *sParams);
262

  
263
/**
264
 * send data  
265
 * @param connectionID The connection the data should be send to. 
266
 * @param sendbuf A pointer to the send buffer. 
267
 * @param bufsize The buffersize of the send buffer. 
268
 * @param msgtype The message type. 
269
 * @param sParams A pointer to a send_params struct. 
270
 */
271
void send_data(const int connectionID,char *sendbuf,int bufsize,int msgtype,send_params *sParams);
272

  
273
void send_msg(int con_id, int msg_type, char* msg, int msg_len, bool truncable, send_params * sparam);
274
/**
275
 * receive data  
276
 * @param connectionID The connection the data came from. 
277
 * @param recvbuf A pointer to a buffer the data will be stored in. 
278
 * @param bufsize A pointer to an int that tells the size of the received data. 
279
 * @param rParams A pointer to a recv_params struct. 
280
 */
281
int recv_data(const int connectionID,char *recvbuf,int *bufsize,recv_params *rParams);
282

  
283
/**
284
 * set the stun server  
285
 * @param port The port of the stun server. 
286
 * @param ipaddr The ip address of the stun server. 
287
 */
288
void setStunServer(const int port,const char *ipaddr);
289

  
290
/**
291
 * unset the stun server
292
 */
293
void unsetStunServer();
294

  
295
/**
296
 * checks whether a stun server was defined
297
 * @returns true if a stun serve rwas defined
298
 */
299
bool isStunDefined();
300

  
301
/**
302
 * set recv timeout  
303
 * @param timeout_value The timeout value for receiving data. 
304
 */
305
void setRecvTimeout(struct timeval timeout_value);
306

  
307
/**
308
  * create a message for the connection establishment
309
  * @param *msgbuf A buffer for the message
310
  * @param bufsize The buffersize 
311
  * @param local_connectionID The local connectionID
312
  * @param local_socketID The local socketID
313
  * @param command_type The command type
314
  * @return -1 for failure otherwise the size of the allocated control message buffer
315
  */
316

  
317
int
318
create_conn_msg(int pmtusize,int local_connectionID, socketID_handle local_socketID, con_msg_types command_type);
319

  
320
/**
321
  * send a connect message to another peer
322
  * @param connectionID the connectionID
323
  * @param *msgbuf A pointer to the message buffer
324
  * @param bufsize The buffersize
325
  */
326
void send_conn_msg(const int connectionID,int bufsize, int command);
327

  
328
/**
329
  * process an incoming conenction message
330
  * @param local_socketID
331
  * @param bufsize
332
  */
333
void recv_conn_msg(struct msg_header *msg_h,char *msgbuf,int bufsize);
334

  
335
/**
336
  * process an incoming message
337
  * @param fd A file descriptor
338
  * @param event A libevent event 
339
  * @param arg An arg pointer
340
  */
341
void recv_pkg(int fd, short event, void *arg);
342

  
343
/**
344
  * receive a stun message
345
  * @param *msgbuf A pointer to a message buffer
346
  * @param recvSize The buffersize
347
  */
348
void recv_stun_msg(char *msgbuf,int recvSize);
349

  
350
/**
351
  * process an incoming data message
352
  * @param *msgbuf A pointer to a message buffer
353
  * @param bufsize The buffersize
354
  * @param ttl The ttl value of the packet
355
  */
356
void recv_data_msg(struct msg_header *msg_h, char *msgbuf, int bufsize);
357

  
358
/**
359
  * A receive timeout callback for the connections
360
  * @param fd A file descriptor
361
  * @param event A libevent event 
362
  * @param arg An arg pointer          
363
  */
364
void recv_timeout_cb(int fd,short event,void *arg);
365

  
366
/**
367
  * A pmtu timeout callback
368
  * @param fd A file descriptor
369
  * @param event A libevent event 
370
  * @param arg An arg pointer
371
  */
372
void pmtu_timeout_cb(int fd,short event,void *arg);
373

  
374
/**
375
  * A function to decrement the pmtu value
376
  * @param pmtusize A pmtusize 
377
  */
378
pmtu pmtu_decrement(pmtu pmtusize);
379

  
380
/**
381
  * A pmtu error callback
382
  * @param *msg A pointer to a message buffer
383
  * @param msglen The buffersize
384
  */
385
void pmtu_error_cb_th(char *msg,int msglen);
386

  
387
/**
388
 * Compare two socket IDs and check if the external IPaddresses match
389
 * @param sock1 The first socketID                                                                
390
 * @param sock2 The second socketID                                                               
391
 * @return 0 if they match, otherwise 1
392
 */
393
int compare_external_address_socketIDs(socketID_handle sock1,socketID_handle sock2);
394

  
395
/**
396
  * Compare two socket IDs
397
  * @param sock1 The first socketID
398
  * @param sock2 The second socketID
399
  * @return 0 if they match, otherwise 1
400
  */
401
int compare_socketIDs(socketID_handle sock1,socketID_handle sock2);
402

  
403
/**
404
  * A NAT traversal timeout callback
405
  * @param fd A file descriptor
406
  * @param event A libevent event 
407
  * @param arg An arg pointer
408
  */
409
void nat_traversal_timeout(int fd, short event, void *arg);
410

  
411
/**
412
 * A function that returns the standard TTL value the operating system places i
413
n every IP packet                                                              
414
 * @param socketID A local socketID   
415
 * @param ttl A pointer to an integer 
416
 * @return 0 if everything went well and -1 if an error occured
417
 */
418
int get_standard_ttl(socketID_handle socketID,uint8_t *ttl);
419

  
420
/**
421
 * A funtion that returns a handle for the local socketID
422
 * @param errorstatus Returns 0 if the socketID is operational and 2 if the NAT traversal failed
423
 * @return A socketID handle
424
 */
425
socketID_handle get_local_socketID(int *errorstatus);
426

  
427
/**
428
 * A funtion that returns the external IP from the local socketID
429
 * @param external_addr A pointer to a char buffer that holds the externall address
430
 * @return -1 if an error occurred and 0 if it succeded
431
 */
432
int get_external_IP(char* external_addr);
433

  
434
/**
435
 * A funtion that returns a string from a socketID handler
436
 * @param socketID
437
 * @param socketID_string
438
 * @param len size of socketID_string buffer
439
 * @return -1 if an error occurred and 0 if it succeded
440
 */
441
int socketID_to_String(socketID_handle socketID,char* socketID_string, size_t len);
442

  
443
/**
444
 * A funtion that returns a socketID handler from a string
445
 * @param socketID A socketID in string format
446
 * @return a pointer to a socketID
447
 */
448
int string_to_socketID(const char* socketID_string, socketID_handle socketID);
449

  
450
/**
451
 * A funtion that returns the whenever a connection is ready to use or not. 
452
 * @param connectionID The connectionID of the connection that is queried.
453
 * @return the status or -1 if the connectionID does not exist
454
 */
455
int get_connection_status(int connectionID);
456

  
457
/**
458
 * A funtion that returns the whenever a connection is ready to use or not.
459
 * @param socketID A remote socketID to which the connection has been established.
460
 * @param ready if true,return the connID for READY connections only
461
 * @return -1 if the connection does not exist and the connection ID if it exists.
462
 */
463
int connection_exist(socketID_handle socketID,bool ready);
464

  
465
/**
466
 * Resolve a hostname to an unsigned long ready to be loaded into struct in_addr.s_addr
467
 * @param ipaddr the ip addr in a textual format
468
 * @return the resolved address, in network byte ordering
469
 */
470
unsigned long resolve(const char *ipaddr);
471

  
472
int get_path_mtu(int ConnectionId);
199
//
200
///**
201
// * The init method needs to be called to initialise the transmissionHandler
202
// * @param recv_data_cb This is a boolean that decides how an upper layer receives data. When the boolean is set to true data is received via callback. When it is set to false the upper layer has to poll with the recv_data function.
203
// * @param timeout_value A timeout value for the data receival
204
// * @param port A port that will be used to create a new UDP socket
205
// * @param ipaddr An ipaddress that will be used to create a new UDP socket. If left NULL th
206
//e messaging layer binds it to localhost.
207
// * @param stun_port The port of the stun server.
208
// * @param stun_ipaddr The ip address of the stun server.
209
// * @param local_socketID_cb A callback from the type receive_localsocketID_cb that is envoke once the socketID is ready to use.
210
// * @param arg A void pointer that is used in this implementation to handover the libevent pointer.
211
// */
212
//void init_transmissionHandler(bool recv_data_cb,struct timeval timeout_value,const int port,const char *ipaddr,const int stun_port,const char *stun_ipaddr,receive_localsocketID_cb local_socketID_cb,void *arg);
213
//
214
///**
215
// * create a socket: returns a socketID handle
216
// * A socketID handle is a pointer to the opague data structre
217
// * @param port A port that will be used to create a new UDP socket
218
// * @param ipaddr An ipaddress that will be used to create a new UDP socket. If left NULL the messaging layer binds it to localhost.
219
// */
220
//void create_socket(const int port,const char *ipaddr);
221
//
222
///**
223
// * destroys a socket
224
// * @param socketID The socketID handle to the socket ID that shall be destroyed.
225
// */
226
//void close_socket(socketID_handle socketID);
227
//
228
///**
229
// * opens a connection between two socketIDs
230
// * @param local_socketID The local socketID
231
// * @param external_socketID The remote socketID
232
// * @param connectionID A pointer to an int. The connectionID will be stored in that int.
233
// * @param connection_cb  A function pointer to a callback function from the type receive_connection_cb
234
// * @param arg A void pointer that is returned via the callback.
235
// * @return returnValue the connectionId, < 0 for a failure.
236
// */
237
//int open_connection(socketID_handle external_socketID,receive_connection_cb connection_cb,void *arg);
238
//
239
///**
240
// * destroys a connections
241
// * @param connectionID
242
// */
243
//void close_connection(const int connectionID);
244
//
245
//
246
///**
247
//  * Send a NAT traversal keep alive
248
//  * @param connectionID
249
//  */
250
//void keep_connection_alive(const int connectionID);
251
//
252
///**
253
// * send all data
254
// * @param connectionID The connection the data should be send to.
255
// * @param container A container for several buffer pointer and length pairs from type send_all_data_container
256
// * @param nr_entries The number of buffer pointer and length pairs in the container. The maximum nr is 5.
257
// * @param msgtype The message type.
258
// * @param sParams A pointer to a send_params struct.
259
// * @return 0 if a problem occured, 1 if everything was alright.
260
// */
261
//int send_all_data(const int connectionID,send_all_data_container *container,int nr_entries,unsigned char msgtype,send_params *sParams);
262
//
263
///**
264
// * send data
265
// * @param connectionID The connection the data should be send to.
266
// * @param sendbuf A pointer to the send buffer.
267
// * @param bufsize The buffersize of the send buffer.
268
// * @param msgtype The message type.
269
// * @param sParams A pointer to a send_params struct.
270
// */
271
//void send_data(const int connectionID,char *sendbuf,int bufsize,int msgtype,send_params *sParams);
272
//
273
//void send_msg(int con_id, int msg_type, char* msg, int msg_len, bool truncable, send_params * sparam);
274
///**
275
// * receive data
276
// * @param connectionID The connection the data came from.
277
// * @param recvbuf A pointer to a buffer the data will be stored in.
278
// * @param bufsize A pointer to an int that tells the size of the received data.
279
// * @param rParams A pointer to a recv_params struct.
280
// */
281
//int recv_data(const int connectionID,char *recvbuf,int *bufsize,recv_params *rParams);
282
//
283
///**
284
// * set the stun server
285
// * @param port The port of the stun server.
286
// * @param ipaddr The ip address of the stun server.
287
// */
288
//void setStunServer(const int port,const char *ipaddr);
289
//
290
///**
291
// * unset the stun server
292
// */
293
//void unsetStunServer();
294
//
295
///**
296
// * checks whether a stun server was defined
297
// * @returns true if a stun serve rwas defined
298
// */
299
//bool isStunDefined();
300
//
301
///**
302
// * set recv timeout
303
// * @param timeout_value The timeout value for receiving data.
304
// */
305
//void setRecv1Timeout(struct timeval timeout_value);
306
//
307
///**
308
//  * create a message for the connection establishment
309
//  * @param *msgbuf A buffer for the message
310
//  * @param bufsize The buffersize
311
//  * @param local_connectionID The local connectionID
312
//  * @param local_socketID The local socketID
313
//  * @param command_type The command type
314
//  * @return -1 for failure otherwise the size of the allocated control message buffer
315
//  */
316
//
317
//int
318
//create_conn_msg(int pmtusize,int local_connectionID, socketID_handle local_socketID, con_msg_types command_type);
319
//
320
///**
321
//  * send a connect message to another peer
322
//  * @param connectionID the connectionID
323
//  * @param *msgbuf A pointer to the message buffer
324
//  * @param bufsize The buffersize
325
//  */
326
//void send_conn_msg(const int connectionID,int bufsize, int command);
327
//
328
///**
329
//  * process an incoming conenction message
330
//  * @param local_socketID
331
//  * @param bufsize
332
//  */
333
//void recv_conn_msg(struct msg_header *msg_h,char *msgbuf,int bufsize);
334
//
335
///**
336
//  * process an incoming message
337
//  * @param fd A file descriptor
338
//  * @param event A libevent event
339
//  * @param arg An arg pointer
340
//  */
341
//void recv_pkg(int fd, short event, void *arg);
342
//
343
///**
344
//  * receive a stun message
345
//  * @param *msgbuf A pointer to a message buffer
346
//  * @param recvSize The buffersize
347
//  */
348
//void recv_stun_msg(char *msgbuf,int recvSize);
349
//
350
///**
351
//  * process an incoming data message
352
//  * @param *msgbuf A pointer to a message buffer
353
//  * @param bufsize The buffersize
354
//  * @param ttl The ttl value of the packet
355
//  */
356
//void recv_data_msg(struct msg_header *msg_h, char *msgbuf, int bufsize);
357
//
358
///**
359
//  * A receive timeout callback for the connections
360
//  * @param fd A file descriptor
361
//  * @param event A libevent event
362
//  * @param arg An arg pointer
363
//  */
364
//void recv_timeout_cb(int fd,short event,void *arg);
365
//
366
///**
367
//  * A pmtu timeout callback
368
//  * @param fd A file descriptor
369
//  * @param event A libevent event
370
//  * @param arg An arg pointer
371
//  */
372
//void pmtu_timeout_cb(int fd,short event,void *arg);
373
//
374
///**
375
//  * A function to decrement the pmtu value
376
//  * @param pmtusize A pmtusize
377
//  */
378
//pmtu pmtu_decrement(pmtu pmtusize);
379
//
380
///**
381
//  * A pmtu error callback
382
//  * @param *msg A pointer to a message buffer
383
//  * @param msglen The buffersize
384
//  */
385
//void pmtu_error_cb_th(char *msg,int msglen);
386
//
387
///**
388
// * Compare two socket IDs and check if the external IPaddresses match
389
// * @param sock1 The first socketID
390
// * @param sock2 The second socketID
391
// * @return 0 if they match, otherwise 1
392
// */
393
//int compare_external_address_socketIDs(socketID_handle sock1,socketID_handle sock2);
394
//
395
///**
396
//  * Compare two socket IDs
397
//  * @param sock1 The first socketID
398
//  * @param sock2 The second socketID
399
//  * @return 0 if they match, otherwise 1
400
//  */
401
//int mlCompareSocketIDs(socketID_handle sock1,socketID_handle sock2);
402
//
403
///**
404
//  * A NAT traversal timeout callback
405
//  * @param fd A file descriptor
406
//  * @param event A libevent event
407
//  * @param arg An arg pointer
408
//  */
409
//void nat_traversal_timeout(int fd, short event, void *arg);
410
//
411
///**
412
// * A function that returns the standard TTL value the operating system places i
413
//n every IP packet
414
// * @param socketID A local socketID
415
// * @param ttl A pointer to an integer
416
// * @return 0 if everything went well and -1 if an error occured
417
// */
418
//int get_standard_ttl(socketID_handle socketID,uint8_t *ttl);
419
//
420
///**
421
// * A funtion that returns a handle for the local socketID
422
// * @param errorstatus Returns 0 if the socketID is operational and 2 if the NAT traversal failed
423
// * @return A socketID handle
424
// */
425
//socketID_handle get_local_socketID(int *errorstatus);
426
//
427
///**
428
// * A funtion that returns the external IP from the local socketID
429
// * @param external_addr A pointer to a char buffer that holds the externall address
430
// * @return -1 if an error occurred and 0 if it succeded
431
// */
432
//int get_external_IP(char* external_addr);
433
//
434
///**
435
// * A funtion that returns a string from a socketID handler
436
// * @param socketID
437
// * @param socketID_string
438
// * @param len size of socketID_string buffer
439
// * @return -1 if an error occurred and 0 if it succeded
440
// */
441
//int mlSoc2ketIDToString(socketID_handle socketID,char* socketID_string, size_t len);
442
//
443
///**
444
// * A funtion that returns a socketID handler from a string
445
// * @param socketID A socketID in string format
446
// * @return a pointer to a socketID
447
// */
448
//int string_to_socketID(const char* socketID_string, socketID_handle socketID);
449
//
450
///**
451
// * A funtion that returns the whenever a connection is ready to use or not.
452
// * @param connectionID The connectionID of the connection that is queried.
453
// * @return the status or -1 if the connectionID does not exist
454
// */
455
//int get_connection_status(int connectionID);
456
//
457
///**
458
// * A funtion that returns the whenever a connection is ready to use or not.
459
// * @param socketID A remote socketID to which the connection has been established.
460
// * @param ready if true,return the connID for READY connections only
461
// * @return -1 if the connection does not exist and the connection ID if it exists.
462
// */
463
//int connection_exist(socketID_handle socketID,bool ready);
464
//
465
///**
466
// * Resolve a hostname to an unsigned long ready to be loaded into struct in_addr.s_addr
467
// * @param ipaddr the ip addr in a textual format
468
// * @return the resolved address, in network byte ordering
469
// */
470
//unsigned long resolve(const char *ipaddr);
471
//
472
//int get_path_mtu(int ConnectionId);
473 473

  
474 474

  
475 475
#endif

Also available in: Unified diff