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

helpercon.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright 2005 Daniel Ferullo                                             *
00003  *                                                                           *
00004  * Licensed under the Apache License, Version 2.0 (the "License");           *
00005  * you may not use this file except in compliance with the License.          *
00006  * You may obtain a copy of the License at                                   *
00007  *                                                                           *
00008  *    http://www.apache.org/licenses/LICENSE-2.0                             *
00009  *                                                                           *
00010  * Unless required by applicable law or agreed to in writing, software       *
00011  * distributed under the License is distributed on an "AS IS" BASIS,         *
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
00013  * See the License for the specific language governing permissions and       *
00014  * limitations under the License.                                            *
00015  *                                                                           *
00016  *****************************************************************************/
00017 
00018 /**
00019  * @file helpercon.h
00020  * @author Daniel Ferullo (ferullo@cmu.edu)
00021  *
00022  * @brief contains prototypes for functions for a peer connection from a helper
00023  */
00024 
00025 #ifndef __HELPERCON_H__
00026 #define __HELPERCON_H__
00027 
00028 #include "helperdef.h"
00029 #include "connlist.h"
00030 #include "errorcodes.h"
00031 #include "def.h"
00032 
00033 /** @brief structure to hold data passed into a helper_fsm thread */
00034 struct helper_fsm_thread_arg {
00035         /** @brief the connection list */
00036         connlist_t *list;
00037         /** @brief the connection info */
00038         connlist_item_t *item;
00039 } __attribute__((packed));
00040 
00041 /** @brief typedef for the helper_fsm_thread_arg structure */
00042 typedef struct helper_fsm_thread_arg helper_fsm_thread_arg_t;
00043 
00044 /**
00045  * @brief creates a new detached thread to handle a peer connection
00046  *
00047  * @param list a pointer to the list to share data with other threads thru
00048  * @param data a pointer to the observed connection data, a copy of this data
00049  *        is made.
00050  * @param sd the socket descriptor for the connection
00051  *
00052  * @return SUCCESS, errorcode on failure
00053  */
00054 errorcode create_new_handler(connlist_t *list, observed_data_t *data,
00055                              sock_t sd);
00056 
00057 /**
00058  * @brief a wrapper function for the helper fsm entry point
00059  *
00060  * This pthread should be started detacted, but it returns errorcodes just
00061  * in case.
00062  *
00063  * @param arg the sole void * pthread argument.  This arugment will be cast to
00064  *        a helper_fsm_thread_arg_t in the function.  THIS ARGUMENT MUST BE
00065  *        ALLOCATED ON THE HEAP WITH MALLOC, AS IT WILL BE FREED.
00066  * @return SUCCESS, errorcode on failure
00067  */
00068 void *run_helper_fsm_thread(void *arg);
00069 
00070 /**
00071  * @brief finds and returns buddy info from the thread-shared list
00072  *
00073  * This function looks for FIND_BUDDY_TIMEOUT seconds, and then gives up
00074  *
00075  * @param list pointer to the connlist_t structure to find the buddy in
00076  * @param item pointer to the item for the looking peer info
00077  * @param found_buddy pointer pointer to fill in with buddy info
00078  *
00079  * @return SUCCESS, errorcode on failure or timeout
00080  */
00081 errorcode get_buddy(connlist_t *list, connlist_item_t *item,
00082                         connlist_item_t **found_buddy);
00083 /**
00084  * @brief returns success once the buddy's port allocation method has been
00085  *        set.  timeouts out after WAIT_FOR_BUDDY_PORT_ALLOC_TIMEOUT
00086  *
00087  * @param buddy pointer to the buddy's helper_conn_info_t structure
00088  *
00089  * @return SUCCESS when alloc method set, errorcode on error or timeout
00090  */
00091 errorcode wait_for_buddy_port_alloc(helper_conn_info_t *buddy);
00092 
00093 /**
00094  * @brief returns success once the buddy's external port has been set.
00095  *        timeouts out after WAIT_FOR_BUDDY_PORT_KNOWN_TIMEOUT
00096  *
00097  * @param buddy pointer to the buddy's helper_conn_info_t structure
00098  *
00099  * @return SUCCESS when port known is set, errorcode on error or timeout
00100  */
00101 errorcode wait_for_buddy_port_known(helper_conn_info_t *buddy);
00102 
00103 /**
00104  * @brief returns success once the buddy's external port has been set through
00105  *        the birthday paradox.  timeouts out after
00106  *        WAIT_FOR_BUDDY_BDAY_PORT_TIMEOUT
00107  *
00108  * @param buddy pointer to the buddy's helper_conn_info_t structure
00109  *
00110  * @return SUCCESS when port known is set, errorcode on error or timeout
00111  */
00112 errorcode wait_for_buddy_bday_port(helper_conn_info_t *buddy);
00113 
00114 
00115 /**
00116  * @brief returns success once the buddy's SYN sequence number has been set.
00117  *        timeouts out after WAIT_FOR_BUDDY_SEQ_NUM_TIMEOUT
00118  *
00119  * @param buddy pointer to the buddy's helper_conn_info_t structure
00120  *
00121  * @return SUCCESS when seq num flag is set, errorcode on error or timeout
00122  */
00123 errorcode wait_for_buddy_syn_seq_num(helper_conn_info_t *buddy);
00124 
00125 /**
00126  * @brief returns success once the buddy's SYN sequence number has been set.
00127  *        timeouts out after WAIT_FOR_BUDDY_SYN_FLOOD_TIMEOUT
00128  *
00129  * @param buddy pointer to the buddy's helper_conn_info_t structure
00130  *
00131  * @return SUCCESS when seq num flag is set, errorcode on error or timeout
00132  */
00133 errorcode wait_for_buddy_syn_flood(helper_conn_info_t *buddy);
00134 
00135 /**
00136  * @brief finds a second connection, timing out if it takes too long
00137  *
00138  * timeout id FIND_CONN2_TIMEOUT
00139  *
00140  * @param list pointer to the list to look in
00141  * @param find_data the data to match on when searching
00142  * @param found_item pointer to a pointer to set to the found item
00143  *
00144  * @return SUCCESS, errorcode on timeout or failure
00145  */
00146 errorcode find_conn2(connlist_t *list, observed_data_t *find_data,
00147                                 connlist_item_t **found_item);
00148 
00149 #endif /* __HELPERCON_H__ */

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