- Timestamp:
- Feb 3, 2007 8:31:33 PM (18 years ago)
- Location:
- pjproject/branches/iceproject/pjlib-util
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/iceproject/pjlib-util/build/pjlib_util.dsp
r913 r929 208 208 # Begin Source File 209 209 210 SOURCE="..\include\pjlib-util\stun_doc.h" 211 # End Source File 212 # Begin Source File 213 210 214 SOURCE="..\include\pjlib-util\stun_endpoint.h" 211 215 # End Source File … … 213 217 214 218 SOURCE="..\include\pjlib-util\stun_msg.h" 219 # End Source File 220 # Begin Source File 221 222 SOURCE="..\include\pjlib-util\stun_server.h" 215 223 # End Source File 216 224 # Begin Source File -
pjproject/branches/iceproject/pjlib-util/include/pjlib-util/stun_endpoint.h
r913 r929 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org> … … 21 21 22 22 /** 23 * @file stun_ msg.h24 * @brief STUN message components.23 * @file stun_endpoint.h 24 * @brief STUN endpoint. 25 25 */ 26 26 -
pjproject/branches/iceproject/pjlib-util/include/pjlib-util/stun_msg.h
r913 r929 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org> … … 28 28 #include <pj/sock.h> 29 29 30 /**31 * @defgroup PJLIB_UTIL_STUN Simple Traversal Underneath NAT (STUN)32 * @ingroup PJLIB_UTIL33 */34 30 35 31 PJ_BEGIN_DECL -
pjproject/branches/iceproject/pjlib-util/include/pjlib-util/stun_simple.h
r913 r929 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org> … … 28 28 #include <pj/sock.h> 29 29 30 /**31 * @defgroup PJLIB_UTIL_STUN_CLIENT Mini/Tiny STUN Client32 * @ingroup PJLIB_UTIL33 * @{34 */35 30 36 31 PJ_BEGIN_DECL 37 32 38 /* *33 /* 39 34 * This enumeration describes STUN message types. 40 35 */ … … 50 45 51 46 52 /* *47 /* 53 48 * This enumeration describes STUN attribute types. 54 49 */ … … 69 64 70 65 71 /* *66 /* 72 67 * This structre describes STUN message header. 73 68 */ … … 80 75 81 76 82 /* *77 /* 83 78 * This structre describes STUN attribute header. 84 79 */ … … 90 85 91 86 92 /* *87 /* 93 88 * This structre describes STUN MAPPED-ADDR attribute. 94 89 */ … … 147 142 PJ_DECL(void*) pj_stun_msg_find_attr( pj_stun_msg *msg, pj_stun_attr_type t); 148 143 144 145 /** 146 * @defgroup PJLIB_UTIL_STUN_CLIENT Simple STUN Helper 147 * @ingroup PJLIB_UTIL_STUN 148 * @brief A simple and small footprint STUN resolution helper 149 * @{ 150 * 151 * This is the older implementation of STUN client, with only one function 152 * provided (pj_stun_get_mapped_addr()) to retrieve the public IP address 153 * of multiple sockets. 154 */ 149 155 150 156 /** -
pjproject/branches/iceproject/pjlib-util/include/pjlib-util/stun_transaction.h
r913 r929 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org> … … 38 38 * @ingroup PJLIB_UTIL_STUN 39 39 * @{ 40 * 41 The @ref PJLIB_UTIL_STUN_TRANSACTION is used to manage outgoing STUN request, 42 for example to retransmit the request and to notify application about the 43 completion of the request. 44 45 The @ref PJLIB_UTIL_STUN_TRANSACTION does not use any networking operations, 46 but instead application must supply the transaction with a callback to 47 be used by the transaction to send outgoing requests. This way the STUN 48 transaction is made more generic and can work with different types of 49 networking codes in application. 50 51 40 52 */ 41 53 … … 50 62 typedef struct pj_stun_tsx_cb 51 63 { 64 /** 65 * This callback is called when the STUN transaction completed. 66 * 67 * @param tsx The STUN transaction. 68 * @param status Status of the transaction. Status PJ_SUCCESS 69 * means that the request has received a successful 70 * response. 71 * @param response The STUN response, which value may be NULL if 72 * \a status is not PJ_SUCCESS. 73 */ 52 74 void (*on_complete)(pj_stun_client_tsx *tsx, 53 75 pj_status_t status, 54 76 pj_stun_msg *response); 77 78 /** 79 * This callback is called by the STUN transaction when it wants to send 80 * outgoing message. 81 * 82 * @param tsx The STUN transaction instance. 83 * @param stun_pkt The STUN packet to be sent. 84 * @param pkt_size Size of the STUN packet. 85 * 86 * @return If return value of the callback is not PJ_SUCCESS, 87 * the transaction will fail. 88 */ 55 89 pj_status_t (*on_send_msg)(pj_stun_client_tsx *tsx, 56 90 const void *stun_pkt, … … 62 96 63 97 /** 64 * Create a STUN client transaction. 98 * Create an instance of STUN client transaction. The STUN client 99 * transaction is used to transmit outgoing STUN request and to 100 * ensure the reliability of the request by periodically retransmitting 101 * the request, if necessary. 102 * 103 * @param endpt The STUN endpoint, which will be used to retrieve 104 * various settings for the transaction. 105 * @param cb Callback structure, to be used by the transaction 106 * to send message and to notify the application about 107 * the completion of the transaction. 108 * @param p_tsx Pointer to receive the transaction instance. 109 * 110 * @return PJ_SUCCESS on success, or the appropriate error code. 65 111 */ 66 112 PJ_DECL(pj_status_t) pj_stun_client_tsx_create( pj_stun_endpoint *endpt, … … 69 115 70 116 /** 71 * . 117 * Destroy a STUN client transaction. 118 * 119 * @param tsx The STUN transaction. 120 * 121 * @return PJ_SUCCESS on success, or the appropriate error code. 72 122 */ 73 123 PJ_DECL(pj_status_t) pj_stun_client_tsx_destroy(pj_stun_client_tsx *tsx); … … 75 125 76 126 /** 77 * . 127 * Associate an arbitrary data with the STUN transaction. This data 128 * can be then retrieved later from the transaction, by using 129 * pj_stun_client_tsx_get_data() function. 130 * 131 * @param tsx The STUN client transaction. 132 * @param data Application data to be associated with the 133 * STUN transaction. 134 * 135 * @return PJ_SUCCESS on success. 78 136 */ 79 137 PJ_DECL(pj_status_t) pj_stun_client_tsx_set_data(pj_stun_client_tsx *tsx, … … 82 140 83 141 /** 84 * . 142 * Get the user data that was previously associated with the STUN 143 * transaction. 144 * 145 * @param tsx The STUN client transaction. 146 * 147 * @return The user data. 85 148 */ 86 149 PJ_DECL(void*) pj_stun_client_tsx_get_data(pj_stun_client_tsx *tsx); … … 88 151 89 152 /** 90 * . 153 * Start the STUN client transaction by sending STUN request using 154 * this transaction. If reliable transport such as TCP or TLS is used, 155 * the retransmit flag should be set to PJ_FALSE because reliablity 156 * will be assured by the transport layer. 157 * 158 * @param tsx The STUN client transaction. 159 * @param retransmit Should this message be retransmitted by the 160 * STUN transaction. 161 * @param msg The STUN message. 162 * 163 * @return PJ_SUCCESS on success or the appropriate error code. 91 164 */ 92 165 PJ_DECL(pj_status_t) pj_stun_client_tsx_send_msg(pj_stun_client_tsx *tsx, 166 pj_bool_t retransmit, 93 167 const pj_stun_msg *msg); 94 168 95 169 96 170 /** 97 * . 171 * Notify the STUN transaction about the arrival of STUN response. 172 * If the STUN response contains a final error (300 and greater), the 173 * transaction will be terminated and callback will be called. If the 174 * STUN response contains response code 100-299, retransmission 175 * will cease, but application must still call this function again 176 * with a final response later to allow the transaction to complete. 177 * 178 * @param tsx The STUN client transaction instance. 179 * @param packet The incoming packet. 180 * @param pkt_size Size of the incoming packet. 181 * @param parsed_len Optional pointer to receive the number of bytes 182 * that have been parsed from the incoming packet 183 * for the STUN message. This is useful if the 184 * STUN transaction is running over stream oriented 185 * socket such as TCP or TLS. 186 * 187 * @return PJ_SUCCESS on success or the appropriate error code. 98 188 */ 99 189 PJ_DECL(pj_status_t) pj_stun_client_tsx_on_rx_msg(pj_stun_client_tsx *tsx, -
pjproject/branches/iceproject/pjlib-util/src/pjlib-util/stun_endpoint.c
r913 r929 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org> -
pjproject/branches/iceproject/pjlib-util/src/pjlib-util/stun_msg.c
r913 r929 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org> -
pjproject/branches/iceproject/pjlib-util/src/pjlib-util/stun_transaction.c
r913 r929 1 /* $Id */1 /* $Id$ */ 2 2 /* 3 3 * Copyright (C) 2003-2005 Benny Prijono <benny@prijono.org> … … 39 39 pj_uint32_t tsx_id[4]; 40 40 41 pj_bool_t require_retransmit; 41 42 pj_timer_entry timer; 42 43 unsigned transmit_count; … … 109 110 110 111 /* 111 * .112 * Set user data. 112 113 */ 113 114 PJ_DEF(pj_status_t) pj_stun_client_tsx_set_data(pj_stun_client_tsx *tsx, … … 121 122 122 123 /* 123 * .124 * Get the user data 124 125 */ 125 126 PJ_DEF(void*) pj_stun_client_tsx_get_data(pj_stun_client_tsx *tsx) … … 139 140 PJ_ASSERT_RETURN(tsx->timer.id == 0, PJ_EBUSY); 140 141 141 /* Calculate retransmit/timeout delay */ 142 if (tsx->transmit_count == 0) { 143 tsx->retransmit_time.sec = 0; 144 tsx->retransmit_time.msec = tsx->endpt->rto_msec; 145 146 } else if (tsx->transmit_count < PJ_STUN_MAX_RETRANSMIT_COUNT) { 147 unsigned msec; 148 149 msec = PJ_TIME_VAL_MSEC(tsx->retransmit_time); 150 msec = (msec >> 1) + 100; 151 tsx->retransmit_time.sec = msec / 1000; 152 tsx->retransmit_time.msec = msec % 100; 153 154 } else { 155 tsx->retransmit_time.sec = PJ_STUN_TIMEOUT_VALUE / 1000; 156 tsx->retransmit_time.msec = PJ_STUN_TIMEOUT_VALUE % 1000; 157 } 158 159 /* Schedule timer first because when send_msg() failed we can 160 * cancel it (as opposed to when schedule_timer() failed we cannot 161 * cancel transmission). 162 */ 163 status = pj_timer_heap_schedule(tsx->endpt->timer_heap, &tsx->timer, 164 &tsx->retransmit_time); 165 if (status != PJ_SUCCESS) { 166 tsx->timer.id = 0; 167 return status; 142 if (tsx->require_retransmit) { 143 /* Calculate retransmit/timeout delay */ 144 if (tsx->transmit_count == 0) { 145 tsx->retransmit_time.sec = 0; 146 tsx->retransmit_time.msec = tsx->endpt->rto_msec; 147 148 } else if (tsx->transmit_count < PJ_STUN_MAX_RETRANSMIT_COUNT) { 149 unsigned msec; 150 151 msec = PJ_TIME_VAL_MSEC(tsx->retransmit_time); 152 msec = (msec >> 1) + 100; 153 tsx->retransmit_time.sec = msec / 1000; 154 tsx->retransmit_time.msec = msec % 100; 155 156 } else { 157 tsx->retransmit_time.sec = PJ_STUN_TIMEOUT_VALUE / 1000; 158 tsx->retransmit_time.msec = PJ_STUN_TIMEOUT_VALUE % 1000; 159 } 160 161 /* Schedule timer first because when send_msg() failed we can 162 * cancel it (as opposed to when schedule_timer() failed we cannot 163 * cancel transmission). 164 */ 165 status = pj_timer_heap_schedule(tsx->endpt->timer_heap, &tsx->timer, 166 &tsx->retransmit_time); 167 if (status != PJ_SUCCESS) { 168 tsx->timer.id = 0; 169 return status; 170 } 168 171 } 169 172 … … 172 175 status = tsx->cb.on_send_msg(tsx, tsx->last_pkt, tsx->last_pkt_size); 173 176 if (status != PJ_SUCCESS) { 174 pj_timer_heap_cancel(tsx->endpt->timer_heap, &tsx->timer); 175 tsx->timer.id = 0; 177 if (tsx->timer.id != 0) { 178 pj_timer_heap_cancel(tsx->endpt->timer_heap, &tsx->timer); 179 tsx->timer.id = 0; 180 } 176 181 stun_perror(tsx, "STUN error sending message", status); 177 182 return status; … … 185 190 } 186 191 187 /* 188 * . 192 193 /* 194 * Send outgoing message and start STUN transaction. 189 195 */ 190 196 PJ_DEF(pj_status_t) pj_stun_client_tsx_send_msg(pj_stun_client_tsx *tsx, 197 pj_bool_t retransmit, 191 198 const pj_stun_msg *msg) 192 199 { … … 208 215 pj_memcpy(&tsx->tsx_id[1], msg->hdr.tsx_id, 12); 209 216 217 /* Update STUN retransmit flag */ 218 tsx->require_retransmit = retransmit; 219 220 /* Send the message */ 210 221 return tsx_transmit_msg(tsx); 211 222 } … … 243 254 244 255 /* 245 * 256 * Notify the STUN transaction about the arrival of STUN response. 246 257 */ 247 258 PJ_DEF(pj_status_t) pj_stun_client_tsx_on_rx_msg(pj_stun_client_tsx *tsx, … … 292 303 err_attr = (pj_stun_error_code_attr*) 293 304 pj_stun_msg_find_attr(msg, PJ_STUN_ATTR_ERROR_CODE, 0); 294 if (err_attr->err_class == 1) { 305 306 if (err_attr && err_attr->err_class <= 2) { 307 /* draft-ietf-behave-rfc3489bis-05.txt Section 8.3.2: 308 * Any response between 100 and 299 MUST result in the cessation 309 * of request retransmissions, but otherwise is discarded. 310 */ 295 311 PJ_LOG(4,(tsx->obj_name, 296 312 "STUN rx_msg() error: received provisional %d code (%.*s)", … … 301 317 } 302 318 303 if (err_attr ==NULL || err_attr->err_class == 2) {319 if (err_attr == NULL) { 304 320 status = PJ_SUCCESS; 305 321 } else {
Note: See TracChangeset
for help on using the changeset viewer.