Changes between Version 11 and Version 12 of IPAddressChange


Ignore:
Timestamp:
Apr 22, 2015 10:32:02 AM (5 years ago)
Author:
ming
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IPAddressChange

    v11 v12  
    124124TCP is preferred on iPhone because of the background feature, but it has been reported that simply re-registering after an IP address change is detected may not work, presumably because the TCP socket itself is already in bad state and is unable to communicate anymore. The following steps can be used to perform re-registration with a new TCP transport. For a demonstration, please apply attachment:iphone_ip_change_pjsip_1_12.patch at the bottom of this page. The patch is tested on version pjsip-1.12. 
    125125 
    126  0. You need to implement reachability API (sample is provided in the patch). With this API we can monitor the access point connection status and perform re-registration when necessary. 
    127  1. We need to keep track of which transport is being used by the registration, by implementing the {{{on_reg_state2()}}} and {{{on_transport_state()}}} callbacks. Add reference counter to it to prevent other from deleting the transport while we're referencing it (it shouldn't happen while the registration is active, but just in case). Sample code: 
     126 1. You need to implement reachability API (sample is provided in the patch). With this API we can monitor the access point connection status and perform re-registration when necessary. 
     127 2. We need to keep track of which transport is being used by the registration, by implementing the {{{on_reg_state2()}}} and {{{on_transport_state()}}} callbacks. Add reference counter to it to prevent other from deleting the transport while we're referencing it (it shouldn't happen while the registration is active, but just in case). Sample code: 
    128128 {{{ 
    129129static pjsua_acc_id the_acc_id; 
     
    176176} 
    177177 }}} 
    178  
    179  2. When IP address change is detected: a) close the TCP transport that we saved in step 1) above, and b) send unregistration. Sample code: 
     178 Starting from release 2.4, we have a new callback {{{on_reg_started2()}}} (for more details, please refer to ticket #1825), which allows application to get the transport much earlier, i.e. when the registration process begins. This allows application to close the transport before connecting state. So, you can choose to split the implementation in {{{on_reg_state2()}}} above into two callbacks {{{on_reg_started2()}}} and {{{on_reg_state2()}}}: 
     179 {{{ 
     180static void on_reg_started2(pjsua_acc_id acc_id, pjsua_reg_info *info) 
     181{ 
     182   struct pjsip_regc_cbparam *rp = info->cbparam; 
     183 
     184  
     185    ... 
     186    if (acc_id != the_acc_id) 
     187        return; 
     188 
     189    if (the_transport != rp->rdata->tp_info.transport) { 
     190        /* Registration success */ 
     191        if (the_transport) { 
     192            PJ_LOG(3,(THIS_FILE, "xxx: Releasing transport..")); 
     193            pjsip_transport_dec_ref(the_transport); 
     194            the_transport = NULL; 
     195        } 
     196        /* Save transport instance so that we can close it later when 
     197         * new IP address is detected. 
     198         */ 
     199        PJ_LOG(3,(THIS_FILE, "xxx: Saving transport..")); 
     200        the_transport = rp->rdata->tp_info.transport; 
     201        pjsip_transport_add_ref(the_transport); 
     202     } 
     203} 
     204 
     205static void on_reg_state2(pjsua_acc_id acc_id, pjsua_reg_info *info) 
     206{ 
     207   struct pjsip_regc_cbparam *rp = info->cbparam; 
     208 
     209  
     210    ... 
     211    if (acc_id != the_acc_id) 
     212        return; 
     213 
     214    if (rp->code/100 == 2 && rp->expiration > 0 && rp->contact_cnt > 0) { 
     215        /* We already saved the transport instance */ 
     216    } else { 
     217        if (the_transport) { 
     218            PJ_LOG(3,(THIS_FILE, "xxx: Releasing transport..")); 
     219            pjsip_transport_dec_ref(the_transport); 
     220            the_transport = NULL; 
     221        } 
     222    } 
     223    ... 
     224} 
     225 }}} 
     226 
     227 3. When IP address change is detected: a) close the TCP transport that we saved in step 2) above, and b) send unregistration. Sample code: 
    180228 {{{ 
    181229static void ip_change() 
     
    199247}}} 
    200248 
    201  3. And finally, once unregistration in 2b) above is complete, re-register (with TCP).  
     249 4. And finally, once unregistration in 2b) above is complete, re-register (with TCP).  
    202250 
    203251