Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

helpercon.c File Reference

contains defintions for functions to help with a peer connection More...

#include <string.h>
#include "helperfsm.h"
#include "helpercon.h"
#include <unistd.h>
#include <pthread.h>
#include "debug.h"
#include "def.h"
#include "util.h"

Go to the source code of this file.

Functions

errorcode create_new_handler (connlist_t *list, observed_data_t *data, sock_t sd)
 creates a new detached thread to handle a peer connection
void * run_helper_fsm_thread (void *arg)
 a wrapper function for the helper fsm entry point
errorcode get_buddy (connlist_t *list, connlist_item_t *item, connlist_item_t **found_buddy)
 finds and returns buddy info from the thread-shared list
errorcode wait_for_buddy_port_alloc (helper_conn_info_t *buddy)
 returns success once the buddy's port allocation method has been set. timeouts out after WAIT_FOR_BUDDY_PORT_ALLOC_TIMEOUT
errorcode wait_for_buddy_port_known (helper_conn_info_t *buddy)
 returns success once the buddy's external port has been set. timeouts out after WAIT_FOR_BUDDY_PORT_KNOWN_TIMEOUT
errorcode wait_for_buddy_bday_port (helper_conn_info_t *buddy)
 returns success once the buddy's external port has been set through the birthday paradox. timeouts out after WAIT_FOR_BUDDY_BDAY_PORT_TIMEOUT
errorcode wait_for_buddy_syn_seq_num (helper_conn_info_t *buddy)
 returns success once the buddy's SYN sequence number has been set. timeouts out after WAIT_FOR_BUDDY_SEQ_NUM_TIMEOUT
errorcode wait_for_buddy_syn_flood (helper_conn_info_t *buddy)
 returns success once the buddy's SYN sequence number has been set. timeouts out after WAIT_FOR_BUDDY_SYN_FLOOD_TIMEOUT
errorcode find_conn2 (connlist_t *list, observed_data_t *find_data, connlist_item_t **found_item)
 finds a second connection, timing out if it takes too long


Detailed Description

contains defintions for functions to help with a peer connection

Author:
Daniel Ferullo (ferullo@cmu.edu)

Definition in file helpercon.c.


Function Documentation

errorcode create_new_handler connlist_t list,
observed_data_t data,
sock_t  sd
 

creates a new detached thread to handle a peer connection

Parameters:
list a pointer to the list to share data with other threads thru
data a pointer to the observed connection data, a copy of this data is made.
sd the socket descriptor for the connection
Returns:
SUCCESS, errorcode on failure

Definition at line 34 of file helpercon.c.

References CHECK_NOT_NULL, connlist_item_t, connlist_t, ERROR_NULL_ARG_1, ERROR_NULL_ARG_2, errorcode, helper_fsm_thread_arg_t, connlist_item::info, helper_fsm_thread_arg::item, helper_fsm_thread_arg::list, connlist_item::obs_data, observed_data_t, helper_sock_desc::peer, run_helper_fsm_thread(), safe_free(), and helper_conn_info::socks.

Referenced by natblaster_server().

errorcode find_conn2 connlist_t list,
observed_data_t find_data,
connlist_item_t **  found_item
 

finds a second connection, timing out if it takes too long

timeout id FIND_CONN2_TIMEOUT

Parameters:
list pointer to the list to look in
find_data the data to match on when searching
found_item pointer to a pointer to set to the found item
Returns:
SUCCESS, errorcode on timeout or failure

Definition at line 207 of file helpercon.c.

References CHECK_NOT_NULL, connlist_find(), connlist_find_pred_port(), connlist_item_t, connlist_t, DEC_UNTIL_ZERO(), ERROR_NULL_ARG_1, ERROR_NULL_ARG_2, errorcode, FAILED, and observed_data_t.

Referenced by helper_fsm_conn2().

errorcode get_buddy connlist_t list,
connlist_item_t item,
connlist_item_t **  found_buddy
 

finds and returns buddy info from the thread-shared list

This function looks for FIND_BUDDY_TIMEOUT seconds, and then gives up

Parameters:
list pointer to the connlist_t structure to find the buddy in
item pointer to the item for the looking peer info
found_buddy pointer pointer to fill in with buddy info
Returns:
SUCCESS, errorcode on failure or timeout

Definition at line 97 of file helpercon.c.

References helper_conn_info::buddy, CHECK_NOT_NULL, connlist_find(), connlist_find_buddy(), connlist_item_t, connlist_t, DBG_BUDDY, DEBUG, DEC_UNTIL_ZERO(), ERROR_NULL_ARG_1, ERROR_NULL_ARG_2, ERROR_NULL_ARG_3, errorcode, FAILED, and connlist_item::info.

Referenced by helper_fsm_buddy_alloc().

void* run_helper_fsm_thread void *  arg  ) 
 

a wrapper function for the helper fsm entry point

This pthread should be started detacted, but it returns errorcodes just in case.

Parameters:
arg the sole void * pthread argument. This arugment will be cast to a helper_fsm_thread_arg_t in the function. THIS ARGUMENT MUST BE ALLOCATED ON THE HEAP WITH MALLOC, AS IT WILL BE FREED.
Returns:
SUCCESS, errorcode on failure

Definition at line 77 of file helpercon.c.

References CHECK_NOT_NULL, ERROR_NULL_ARG_1, FAILED, helper_fsm_start(), helper_fsm_thread_arg_t, helper_fsm_thread_arg::item, helper_fsm_thread_arg::list, and safe_free().

Referenced by create_new_handler().

errorcode wait_for_buddy_bday_port helper_conn_info_t buddy  ) 
 

returns success once the buddy's external port has been set through the birthday paradox. timeouts out after WAIT_FOR_BUDDY_BDAY_PORT_TIMEOUT

Parameters:
buddy pointer to the buddy's helper_conn_info_t structure
Returns:
SUCCESS when port known is set, errorcode on error or timeout

Definition at line 164 of file helpercon.c.

References helper_conn_info::bday, CHECK_FAILED, CHECK_NOT_NULL, ERROR_CALLED_FUNCTION, ERROR_NULL_ARG_1, errorcode, FLAG_SET, helper_conn_info_t, bday_helper::port_set, WAIT_FOR_BUDDY_BDAY_PORT_TIMEOUT, and wait_for_flag().

Referenced by helper_fsm_end_buddy_bday().

errorcode wait_for_buddy_port_alloc helper_conn_info_t buddy  ) 
 

returns success once the buddy's port allocation method has been set. timeouts out after WAIT_FOR_BUDDY_PORT_ALLOC_TIMEOUT

Parameters:
buddy pointer to the buddy's helper_conn_info_t structure
Returns:
SUCCESS when alloc method set, errorcode on error or timeout

Definition at line 136 of file helpercon.c.

References CHECK_FAILED, CHECK_NOT_NULL, ERROR_CALLED_FUNCTION, ERROR_NULL_ARG_1, errorcode, FLAG_SET, helper_conn_info_t, port_alloc::method_set, helper_conn_info::port_alloc, WAIT_FOR_BUDDY_PORT_ALLOC_TIMEOUT, and wait_for_flag().

Referenced by helper_fsm_buddy_alloc().

errorcode wait_for_buddy_port_known helper_conn_info_t buddy  ) 
 

returns success once the buddy's external port has been set. timeouts out after WAIT_FOR_BUDDY_PORT_KNOWN_TIMEOUT

Parameters:
buddy pointer to the buddy's helper_conn_info_t structure
Returns:
SUCCESS when port known is set, errorcode on error or timeout

Definition at line 150 of file helpercon.c.

References CHECK_FAILED, CHECK_NOT_NULL, ERROR_CALLED_FUNCTION, ERROR_NULL_ARG_1, errorcode, port_alloc::ext_port_set, FLAG_SET, helper_conn_info_t, helper_conn_info::port_alloc, WAIT_FOR_BUDDY_PORT_KNOWN_TIMEOUT, and wait_for_flag().

Referenced by helper_fsm_buddy_port().

errorcode wait_for_buddy_syn_flood helper_conn_info_t buddy  ) 
 

returns success once the buddy's SYN sequence number has been set. timeouts out after WAIT_FOR_BUDDY_SYN_FLOOD_TIMEOUT

Parameters:
buddy pointer to the buddy's helper_conn_info_t structure
Returns:
SUCCESS when seq num flag is set, errorcode on error or timeout

Definition at line 193 of file helpercon.c.

References helper_conn_info::bday, CHECK_FAILED, CHECK_NOT_NULL, ERROR_CALLED_FUNCTION, ERROR_NULL_ARG_1, errorcode, FLAG_SET, helper_conn_info_t, bday_helper::seq_num_set, WAIT_FOR_BUDDY_SYN_FLOOD_TIMEOUT, and wait_for_flag().

Referenced by helper_fsm_start_buddy_bday().

errorcode wait_for_buddy_syn_seq_num helper_conn_info_t buddy  ) 
 

returns success once the buddy's SYN sequence number has been set. timeouts out after WAIT_FOR_BUDDY_SEQ_NUM_TIMEOUT

Parameters:
buddy pointer to the buddy's helper_conn_info_t structure
Returns:
SUCCESS when seq num flag is set, errorcode on error or timeout

Definition at line 178 of file helpercon.c.

References helper_conn_info::buddy_syn, CHECK_FAILED, CHECK_NOT_NULL, ERROR_CALLED_FUNCTION, ERROR_NULL_ARG_1, errorcode, FLAG_SET, helper_conn_info_t, buddy_syn_seq_num::seq_num_set, WAIT_FOR_BUDDY_SEQ_NUM_TIMEOUT, and wait_for_flag().

Referenced by helper_fsm_start_direct_conn().


Generated on Wed Mar 30 23:20:48 2005 for NATBLASTER by  doxygen 1.3.9.1