Changeset 3128
- Timestamp:
- Mar 30, 2010 11:13:59 AM (15 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r3119 r3128 190 190 puts (" May be specified multiple times"); 191 191 puts (" --reg-timeout=SEC Optional registration interval (default 55)"); 192 puts (" --rereg-delay=SEC Optional auto retry registration interval (default 300)"); 192 193 puts (" --realm=string Set realm"); 193 194 puts (" --username=string Set authentication username"); … … 485 486 OPT_BOUND_ADDR, OPT_CONTACT_PARAMS, OPT_CONTACT_URI_PARAMS, 486 487 OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD, 488 OPT_REG_RETRY_INTERVAL, 487 489 OPT_MWI, OPT_NAMESERVER, OPT_STUN_SRV, 488 490 OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE, … … 551 553 { "username", 1, 0, OPT_USERNAME}, 552 554 { "password", 1, 0, OPT_PASSWORD}, 555 { "rereg-delay",1, 0, OPT_REG_RETRY_INTERVAL}, 553 556 { "nameserver", 1, 0, OPT_NAMESERVER}, 554 557 { "stun-srv", 1, 0, OPT_STUN_SRV}, … … 960 963 break; 961 964 965 case OPT_REG_RETRY_INTERVAL: 966 cur_acc->reg_retry_interval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); 967 break; 968 962 969 case OPT_NEXT_CRED: /* next credential */ 963 970 cur_acc->cred_count++; -
pjproject/trunk/pjsip/include/pjsip-ua/sip_regc.h
r2855 r3128 95 95 int interval; /**< Registration interval (seconds). */ 96 96 int next_reg; /**< Time until next registration (seconds). */ 97 pjsip_transport *transport; /**< Last transport used. */ 97 98 }; 98 99 -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h
r3110 r3128 1866 1866 1867 1867 /** 1868 * Default auto retry re-registration interval, in seconds. Set to 0 1869 * to disable this. Application can set the timer on per account basis 1870 * by setting the pjsua_acc_config.reg_retry_interval field instead. 1871 * 1872 * Default: 300 (5 minutes) 1873 */ 1874 #ifndef PJSUA_REG_RETRY_INTERVAL 1875 # define PJSUA_REG_RETRY_INTERVAL 300 1876 #endif 1877 1878 1879 /** 1868 1880 * This structure describes account configuration to be specified when 1869 1881 * adding a new account with #pjsua_acc_add(). Application MUST initialize … … 2116 2128 int srtp_secure_signaling; 2117 2129 #endif 2130 2131 /** 2132 * Specify interval of auto registration retry upon registration failure 2133 * (including caused by transport problem), in second. Set to 0 to 2134 * disable auto re-registration. 2135 * 2136 * Default: #PJSUA_REG_RETRY_INTERVAL 2137 */ 2138 unsigned reg_retry_interval; 2139 2140 /** 2141 * Specify whether calls of the configured account should be dropped 2142 * after registration failure and an attempt of re-registration has 2143 * also failed. 2144 * 2145 * Default: PJ_FALSE (disabled) 2146 */ 2147 pj_bool_t drop_calls_on_reg_fail; 2118 2148 2119 2149 } pjsua_acc_config; -
pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h
r3119 r3128 129 129 int reg_last_code; /**< Last status last register. */ 130 130 131 struct { 132 pj_bool_t active; /**< Flag of reregister status. */ 133 pj_timer_entry timer; /**< Timer for reregistration. */ 134 void *reg_tp; /**< Transport for registration. */ 135 unsigned attempt_cnt; /**< Attempt counter. */ 136 } auto_rereg; /**< Reregister/reconnect data. */ 137 131 138 pj_timer_entry ka_timer; /**< Keep-alive timer for UDP. */ 132 139 pjsip_transport *ka_transport; /**< Transport for keep-alive. */ -
pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c
r3105 r3128 204 204 info->auto_reg = regc->auto_reg; 205 205 info->interval = regc->expires; 206 info->transport = regc->last_transport; 206 207 207 208 if (regc->has_tsx) … … 1203 1204 regc->current_op = REGC_REGISTERING; 1204 1205 1206 /* Prevent deletion of tdata, e.g: when something wrong in sending, 1207 * we need tdata to retrieve the transport. 1208 */ 1209 pjsip_tx_data_add_ref(tdata); 1210 1205 1211 status = pjsip_endpt_send_request(regc->endpt, tdata, REGC_TSX_TIMEOUT, 1206 1212 regc, &tsx_callback); … … 1209 1215 } 1210 1216 1217 /* Get last transport used and add reference to it */ 1218 if (tdata->tp_info.transport != regc->last_transport) { 1219 if (regc->last_transport) { 1220 pjsip_transport_dec_ref(regc->last_transport); 1221 regc->last_transport = NULL; 1222 } 1223 1224 if (tdata->tp_info.transport) { 1225 regc->last_transport = tdata->tp_info.transport; 1226 pjsip_transport_add_ref(regc->last_transport); 1227 } 1228 } 1229 1230 /* Release tdata */ 1231 pjsip_tx_data_dec_ref(tdata); 1232 1211 1233 pj_lock_release(regc->lock); 1212 1234 -
pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
r3119 r3128 178 178 return; 179 179 180 /* Prevent immediate transport destroy by application, as transport 181 * state notification callback may be stacked and transport instance 182 * must remain valid at any point in the callback. 183 */ 184 pjsip_transport_add_ref(&tcp->base); 185 180 186 /* Notify application of transport disconnected state */ 181 187 state_cb = pjsip_tpmgr_get_status_cb(tcp->base.tpmgr); … … 194 200 */ 195 201 pjsip_transport_shutdown(&tcp->base); 202 203 /* Now, it is ok to destroy the transport. */ 204 pjsip_transport_dec_ref(&tcp->base); 196 205 } 197 206 -
pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c
r3119 r3128 185 185 return; 186 186 187 /* Prevent immediate transport destroy by application, as transport 188 * state notification callback may be stacked and transport instance 189 * must remain valid at any point in the callback. 190 */ 191 pjsip_transport_add_ref(&tls->base); 192 187 193 /* Notify application of transport disconnected state */ 188 194 state_cb = pjsip_tpmgr_get_status_cb(tls->base.tpmgr); … … 201 207 */ 202 208 pjsip_transport_shutdown(&tls->base); 209 210 /* Now, it is ok to destroy the transport. */ 211 pjsip_transport_dec_ref(&tls->base); 203 212 } 204 213 … … 518 527 { 519 528 struct tls_transport *tls; 520 const pj_str_t ka_pkt = PJSIP_T CP_KEEP_ALIVE_DATA;529 const pj_str_t ka_pkt = PJSIP_TLS_KEEP_ALIVE_DATA; 521 530 pj_status_t status; 522 531 … … 579 588 sockaddr_to_host_port(pool, &tls->base.local_name, 580 589 (pj_sockaddr_in*)&tls->base.local_addr); 581 sockaddr_to_host_port(pool, &tls->base.remote_name, remote); 590 if (tls->remote_name.slen) { 591 tls->base.remote_name.host = tls->remote_name; 592 tls->base.remote_name.port = pj_sockaddr_in_get_port(remote); 593 } else { 594 sockaddr_to_host_port(pool, &tls->base.remote_name, remote); 595 } 582 596 583 597 tls->base.endpt = listener->endpt; … … 1076 1090 } else { 1077 1091 /* Start keep-alive timer */ 1078 if (PJSIP_T CP_KEEP_ALIVE_INTERVAL) {1079 pj_time_val delay = {PJSIP_T CP_KEEP_ALIVE_INTERVAL, 0};1092 if (PJSIP_TLS_KEEP_ALIVE_INTERVAL) { 1093 pj_time_val delay = {PJSIP_TLS_KEEP_ALIVE_INTERVAL, 0}; 1080 1094 pjsip_endpt_schedule_timer(listener->endpt, 1081 1095 &tls->ka_timer, … … 1508 1522 1509 1523 /* Start keep-alive timer */ 1510 if (PJSIP_T CP_KEEP_ALIVE_INTERVAL) {1511 pj_time_val delay = { PJSIP_T CP_KEEP_ALIVE_INTERVAL, 0 };1524 if (PJSIP_TLS_KEEP_ALIVE_INTERVAL) { 1525 pj_time_val delay = { PJSIP_TLS_KEEP_ALIVE_INTERVAL, 0 }; 1512 1526 pjsip_endpt_schedule_timer(tls->base.endpt, &tls->ka_timer, 1513 1527 &delay); … … 1541 1555 PJ_TIME_VAL_SUB(now, tls->last_activity); 1542 1556 1543 if (now.sec > 0 && now.sec < PJSIP_T CP_KEEP_ALIVE_INTERVAL) {1557 if (now.sec > 0 && now.sec < PJSIP_TLS_KEEP_ALIVE_INTERVAL) { 1544 1558 /* There has been activity, so don't send keep-alive */ 1545 delay.sec = PJSIP_T CP_KEEP_ALIVE_INTERVAL - now.sec;1559 delay.sec = PJSIP_TLS_KEEP_ALIVE_INTERVAL - now.sec; 1546 1560 delay.msec = 0; 1547 1561 … … 1571 1585 1572 1586 /* Register next keep-alive */ 1573 delay.sec = PJSIP_T CP_KEEP_ALIVE_INTERVAL;1587 delay.sec = PJSIP_TLS_KEEP_ALIVE_INTERVAL; 1574 1588 delay.msec = 0; 1575 1589 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c
r3096 r3128 25 25 26 26 27 static void schedule_reregistration(pjsua_acc *acc); 28 27 29 /* 28 30 * Get number of current accounts. … … 442 444 443 445 PJSUA_LOCK(); 446 447 /* Cancel any re-registration timer */ 448 pjsua_cancel_timer(&pjsua_var.acc[acc_id].auto_rereg.timer); 444 449 445 450 /* Delete registration */ … … 1032 1037 } else if (PJSIP_IS_STATUS_IN_CLASS(param->code, 200)) { 1033 1038 1039 /* Update auto registration flag */ 1040 acc->auto_rereg.active = PJ_FALSE; 1041 acc->auto_rereg.attempt_cnt = 0; 1042 1034 1043 if (param->expiration < 1) { 1035 1044 pjsip_regc_destroy(acc->regc); … … 1082 1091 if (pjsua_var.ua_cfg.cb.on_reg_state) 1083 1092 (*pjsua_var.ua_cfg.cb.on_reg_state)(acc->index); 1093 1094 /* Check if we need to auto retry registration. Basically, registration 1095 * failure codes triggering auto-retry are those of temporal failures 1096 * considered to be recoverable in relatively short term. 1097 */ 1098 if (acc->cfg.reg_retry_interval && 1099 (param->code == PJSIP_SC_REQUEST_TIMEOUT || 1100 param->code == PJSIP_SC_INTERNAL_SERVER_ERROR || 1101 param->code == PJSIP_SC_BAD_GATEWAY || 1102 param->code == PJSIP_SC_SERVICE_UNAVAILABLE || 1103 param->code == PJSIP_SC_SERVER_TIMEOUT || 1104 PJSIP_IS_STATUS_IN_CLASS(param->code, 600))) /* Global failure */ 1105 { 1106 schedule_reregistration(acc); 1107 } 1084 1108 1085 1109 PJSUA_UNLOCK(); … … 1221 1245 PJSUA_LOCK(); 1222 1246 1247 /* Cancel any re-registration timer */ 1248 pjsua_cancel_timer(&pjsua_var.acc[acc_id].auto_rereg.timer); 1249 1250 /* Reset pointer to registration transport */ 1251 pjsua_var.acc[acc_id].auto_rereg.reg_tp = NULL; 1252 1223 1253 if (renew) { 1224 1254 if (pjsua_var.acc[acc_id].regc == NULL) { … … 1274 1304 //pjsua_process_msg_data(tdata, NULL); 1275 1305 status = pjsip_regc_send( pjsua_var.acc[acc_id].regc, tdata ); 1306 } 1307 1308 /* Update pointer to registration transport */ 1309 if (status == PJ_SUCCESS) { 1310 pjsip_regc_info reg_info; 1311 1312 pjsip_regc_get_info(pjsua_var.acc[acc_id].regc, ®_info); 1313 pjsua_var.acc[acc_id].auto_rereg.reg_tp = reg_info.transport; 1276 1314 } 1277 1315 … … 1926 1964 } 1927 1965 1966 1967 /* Auto re-registration timeout callback */ 1968 static void auto_rereg_timer_cb(pj_timer_heap_t *th, pj_timer_entry *te) 1969 { 1970 pjsua_acc *acc; 1971 pj_status_t status; 1972 1973 PJ_UNUSED_ARG(th); 1974 acc = (pjsua_acc*) te->user_data; 1975 pj_assert(acc); 1976 1977 PJSUA_LOCK(); 1978 1979 if (!acc->valid || !acc->auto_rereg.active) 1980 goto on_return; 1981 1982 /* Start re-registration */ 1983 acc->auto_rereg.attempt_cnt++; 1984 status = pjsua_acc_set_registration(acc->index, PJ_TRUE); 1985 if (status != PJ_SUCCESS) 1986 schedule_reregistration(acc); 1987 1988 /* If configured, disconnect calls of this account after the first 1989 * reregistration attempt failed. 1990 */ 1991 if (acc->cfg.drop_calls_on_reg_fail && acc->auto_rereg.attempt_cnt > 1) 1992 { 1993 unsigned i, cnt; 1994 1995 for (i = 0, cnt = 0; i < pjsua_var.ua_cfg.max_calls; ++i) { 1996 if (pjsua_var.calls[i].acc_id == acc->index) { 1997 pjsua_call_hangup(i, 0, NULL, NULL); 1998 ++cnt; 1999 } 2000 } 2001 2002 if (cnt) { 2003 PJ_LOG(3, (THIS_FILE, "Disconnecting %d call(s) of account #%d " 2004 "after reregistration attempt failed", 2005 cnt, acc->index)); 2006 } 2007 } 2008 2009 on_return: 2010 2011 PJSUA_UNLOCK(); 2012 } 2013 2014 2015 /* Schedule reregistration for specified account. Note that the first 2016 * re-registration after a registration failure will be done immediately. 2017 * Also note that this function should be called within PJSUA mutex. 2018 */ 2019 static void schedule_reregistration(pjsua_acc *acc) 2020 { 2021 pj_time_val delay; 2022 2023 pj_assert(acc && acc->valid && acc->cfg.reg_retry_interval); 2024 2025 /* Cancel any re-registration timer */ 2026 pjsua_cancel_timer(&acc->auto_rereg.timer); 2027 2028 /* Update re-registration flag */ 2029 acc->auto_rereg.active = PJ_TRUE; 2030 2031 /* Set up timer for reregistration */ 2032 acc->auto_rereg.timer.cb = &auto_rereg_timer_cb; 2033 acc->auto_rereg.timer.user_data = acc; 2034 2035 /* Reregistration attempt. The first attempt will be done immediately. */ 2036 delay.sec = acc->auto_rereg.attempt_cnt? acc->cfg.reg_retry_interval : 0; 2037 delay.msec = 0; 2038 pjsua_schedule_timer(&acc->auto_rereg.timer, &delay); 2039 } 2040 2041 2042 /* Internal function to perform auto-reregistration on transport 2043 * connection/disconnection events. 2044 */ 2045 void pjsua_acc_on_tp_state_changed(pjsip_transport *tp, 2046 pjsip_transport_state state, 2047 const pjsip_transport_state_info *info) 2048 { 2049 unsigned i; 2050 2051 PJ_UNUSED_ARG(info); 2052 2053 /* Only care for transport disconnection events */ 2054 if (state != PJSIP_TP_STATE_DISCONNECTED) 2055 return; 2056 2057 /* Shutdown this transport, to make sure that the transport manager 2058 * will create a new transport for reconnection. 2059 */ 2060 pjsip_transport_shutdown(tp); 2061 2062 PJSUA_LOCK(); 2063 2064 /* Enumerate accounts using this transport and perform actions 2065 * based on the transport state. 2066 */ 2067 for (i = 0; i < PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 2068 pjsua_acc *acc = &pjsua_var.acc[i]; 2069 2070 /* Skip if this account is not valid OR auto re-registration 2071 * feature is disabled OR this transport is not used by this account. 2072 */ 2073 if (!acc->valid || !acc->cfg.reg_retry_interval || 2074 tp != acc->auto_rereg.reg_tp) 2075 { 2076 continue; 2077 } 2078 2079 /* Schedule reregistration for this account */ 2080 schedule_reregistration(acc); 2081 } 2082 2083 PJSUA_UNLOCK(); 2084 } -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r3119 r3128 177 177 cfg->srtp_secure_signaling = pjsua_var.ua_cfg.srtp_secure_signaling; 178 178 #endif 179 cfg->reg_retry_interval = PJSUA_REG_RETRY_INTERVAL; 179 180 } 180 181 … … 1526 1527 } 1527 1528 1529 void pjsua_acc_on_tp_state_changed(pjsip_transport *tp, 1530 pjsip_transport_state state, 1531 const pjsip_transport_state_info *info); 1532 1528 1533 /* Callback to receive transport state notifications */ 1529 1534 static void on_tp_state_callback(pjsip_transport *tp, … … 1537 1542 (*pjsua_var.old_tp_cb)(tp, state, info); 1538 1543 } 1544 pjsua_acc_on_tp_state_changed(tp, state, info); 1539 1545 } 1540 1546
Note: See TracChangeset
for help on using the changeset viewer.