Ignore:
Timestamp:
Aug 12, 2009 11:03:23 AM (15 years ago)
Author:
bennylp
Message:

Ticket #866: Allow application to specify more than one STUN servers for more robustness, and continue application startup if STUN resolution fails

PJSUA-LIB:

  • New fields in pjsua_config to specify more than one STUN servers (the stun_srv_cnt and stun_srv array)
  • The existing stun_host and stun_domain fields are deprecated, but backward compatibility is maintained. If stun_srv_cnt is zero, the library will import the entries from stun_host and stun_domain
  • The library will now resolve the STUN server entries one by one and test it before using it
  • New auxiliary API pjsua_resolve_stun_servers() to perform resolution and test against array of STUN servers

pjsua application:

  • The "stun-srv" command line options can now be specified more than once
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r2859 r2864  
    892892 
    893893    /** 
     894     * Warning: deprecated, please use \a stun_srv field instead. To maintain 
     895     * backward compatibility, if \a stun_srv_cnt is zero then the value of 
     896     * this field will be copied to \a stun_srv field, if present. 
     897     * 
    894898     * Specify domain name to be resolved with DNS SRV resolution to get the 
    895899     * address of the STUN server. Alternatively application may specify 
     
    902906 
    903907    /** 
     908     * Warning: deprecated, please use \a stun_srv field instead. To maintain 
     909     * backward compatibility, if \a stun_srv_cnt is zero then the value of 
     910     * this field will be copied to \a stun_srv field, if present. 
     911     * 
    904912     * Specify STUN server to be used, in "HOST[:PORT]" format. If port is 
    905913     * not specified, default port 3478 will be used. 
    906914     */ 
    907915    pj_str_t        stun_host; 
     916 
     917    /** 
     918     * Number of STUN server entries in \a stun_srv array. 
     919     */ 
     920    unsigned        stun_srv_cnt; 
     921 
     922    /** 
     923     * Array of STUN servers to try. The library will try to resolve and 
     924     * contact each of the STUN server entry until it finds one that is 
     925     * usable. Each entry may be a domain name, host name, IP address, and 
     926     * it may contain an optional port number. For example: 
     927     *  - "pjsip.org" (domain name) 
     928     *  - "sip.pjsip.org" (host name) 
     929     *  - "pjsip.org:33478" (domain name and a non-standard port number) 
     930     *  - "10.0.0.1:3478" (IP address and port number) 
     931     * 
     932     * When nameserver is configured in the \a pjsua_config.nameserver field, 
     933     * if entry is not an IP address, it will be resolved with DNS SRV  
     934     * resolution first, and it will fallback to use DNS A resolution if this 
     935     * fails. Port number may be specified even if the entry is a domain name, 
     936     * in case the DNS SRV resolution should fallback to a non-standard port. 
     937     * 
     938     * When nameserver is not configured, entries will be resolved with 
     939     * #pj_gethostbyname() if it's not an IP address. Port number may be 
     940     * specified if the server is not listening in standard STUN port. 
     941     */ 
     942    pj_str_t        stun_srv[8]; 
     943 
     944    /** 
     945     * This specifies if the library startup should ignore failure with the 
     946     * STUN servers. If this is set to PJ_FALSE, the library will refuse to 
     947     * start if it fails to resolve or contact any of the STUN servers. 
     948     * 
     949     * Default: PJ_TRUE 
     950     */ 
     951    pj_bool_t       stun_ignore_failure; 
    908952 
    909953    /** 
     
    12141258 * 
    12151259 */ 
     1260 
     1261/** 
     1262 * This structure is used to represent the result of the STUN server  
     1263 * resolution and testing, the #pjsua_resolve_stun_servers() function. 
     1264 * This structure will be passed in #pj_stun_resolve_cb callback. 
     1265 */ 
     1266typedef struct pj_stun_resolve_result 
     1267{ 
     1268    /** 
     1269     * Arbitrary data that was passed to #pjsua_resolve_stun_servers() 
     1270     * function. 
     1271     */ 
     1272    void            *token; 
     1273 
     1274    /** 
     1275     * This will contain PJ_SUCCESS if at least one usable STUN server 
     1276     * is found, otherwise it will contain the last error code during 
     1277     * the operation. 
     1278     */ 
     1279    pj_status_t      status; 
     1280 
     1281    /** 
     1282     * The server name that yields successful result. This will only 
     1283     * contain value if status is successful. 
     1284     */ 
     1285    pj_str_t         name; 
     1286 
     1287    /** 
     1288     * The server IP address. This will only contain value if status  
     1289     * is successful. 
     1290     */ 
     1291    pj_sockaddr      addr; 
     1292 
     1293} pj_stun_resolve_result; 
     1294 
     1295 
     1296/** 
     1297 * Typedef of callback to be registered to #pjsua_resolve_stun_servers(). 
     1298 */ 
     1299typedef void (*pj_stun_resolve_cb)(const pj_stun_resolve_result *result); 
    12161300 
    12171301/** 
     
    12511335 */ 
    12521336PJ_DECL(pj_status_t) pjsua_get_nat_type(pj_stun_nat_type *type); 
     1337 
     1338 
     1339/** 
     1340 * Auxiliary function to resolve and contact each of the STUN server 
     1341 * entries (sequentially) to find which is usable. The #pjsua_init() must 
     1342 * have been called before calling this function. 
     1343 * 
     1344 * @param count         Number of STUN server entries to try. 
     1345 * @param srv           Array of STUN server entries to try. Please see 
     1346 *                      the \a stun_srv field in the #pjsua_config  
     1347 *                      documentation about the format of this entry. 
     1348 * @param wait          Specify non-zero to make the function block until 
     1349 *                      it gets the result. In this case, the function 
     1350 *                      will block while the resolution is being done, 
     1351 *                      and the callback will be called before this function 
     1352 *                      returns. 
     1353 * @param token         Arbitrary token to be passed back to application 
     1354 *                      in the callback. 
     1355 * @param cb            Callback to be called to notify the result of 
     1356 *                      the function. 
     1357 * 
     1358 * @return              If \a wait parameter is non-zero, this will return 
     1359 *                      PJ_SUCCESS if one usable STUN server is found. 
     1360 *                      Otherwise it will always return PJ_SUCCESS, and 
     1361 *                      application will be notified about the result in 
     1362 *                      the callback. 
     1363 */ 
     1364PJ_DECL(pj_status_t) pjsua_resolve_stun_servers(unsigned count, 
     1365                                                pj_str_t srv[], 
     1366                                                pj_bool_t wait, 
     1367                                                void *token, 
     1368                                                pj_stun_resolve_cb cb); 
     1369 
     1370/** 
     1371 * Cancel pending STUN resolution which match the specified token.  
     1372 * 
     1373 * @param token         The token to match. This token was given to  
     1374 *                      #pjsua_resolve_stun_servers() 
     1375 * @param notify_cb     Boolean to control whether the callback should 
     1376 *                      be called for cancelled resolutions. When the 
     1377 *                      callback is called, the status in the result 
     1378 *                      will be set as PJ_ECANCELLED. 
     1379 * 
     1380 * @return              PJ_SUCCESS if there is at least one pending STUN 
     1381 *                      resolution cancelled, or PJ_ENOTFOUND if there is 
     1382 *                      no matching one, or other error. 
     1383 */ 
     1384PJ_DECL(pj_status_t) pjsua_cancel_stun_resolution(void *token, 
     1385                                                  pj_bool_t notify_cb); 
    12531386 
    12541387 
Note: See TracChangeset for help on using the changeset viewer.