00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PJNATH_ICE_STRANS_H__
00021 #define __PJNATH_ICE_STRANS_H__
00022
00023
00028 #include <pjnath/ice_session.h>
00029 #include <pjnath/stun_sock.h>
00030 #include <pjnath/turn_sock.h>
00031 #include <pjlib-util/resolver.h>
00032 #include <pj/ioqueue.h>
00033 #include <pj/timer.h>
00034
00035
00036 PJ_BEGIN_DECL
00037
00038
00117 typedef struct pj_ice_strans pj_ice_strans;
00118
00120 typedef enum pj_ice_strans_op
00121 {
00123 PJ_ICE_STRANS_OP_INIT,
00124
00126 PJ_ICE_STRANS_OP_NEGOTIATION,
00127
00131 PJ_ICE_STRANS_OP_KEEP_ALIVE
00132
00133 } pj_ice_strans_op;
00134
00139 typedef struct pj_ice_strans_cb
00140 {
00153 void (*on_rx_data)(pj_ice_strans *ice_st,
00154 unsigned comp_id,
00155 void *pkt, pj_size_t size,
00156 const pj_sockaddr_t *src_addr,
00157 unsigned src_addr_len);
00158
00166 void (*on_ice_complete)(pj_ice_strans *ice_st,
00167 pj_ice_strans_op op,
00168 pj_status_t status);
00169
00170 } pj_ice_strans_cb;
00171
00172
00178 typedef struct pj_ice_strans_cfg
00179 {
00184 int af;
00185
00194 pj_stun_config stun_cfg;
00195
00202 pj_dns_resolver *resolver;
00203
00209 pj_ice_sess_options opt;
00210
00216 struct {
00221 pj_stun_sock_cfg cfg;
00222
00229 unsigned max_host_cands;
00230
00236 pj_bool_t loop_addr;
00237
00258 pj_str_t server;
00259
00270 pj_uint16_t port;
00271
00272 } stun;
00273
00277 struct {
00283 pj_turn_sock_cfg cfg;
00284
00302 pj_str_t server;
00303
00314 pj_uint16_t port;
00315
00321 pj_turn_tp_type conn_type;
00322
00329 pj_stun_auth_cred auth_cred;
00330
00335 pj_turn_alloc_param alloc_param;
00336
00337 } turn;
00338
00345 struct {
00354 pj_qos_type qos_type;
00355
00363 pj_qos_params qos_params;
00364
00365 } comp[PJ_ICE_MAX_COMP];
00366
00367 } pj_ice_strans_cfg;
00368
00369
00373 typedef enum pj_ice_strans_state
00374 {
00378 PJ_ICE_STRANS_STATE_NULL,
00379
00383 PJ_ICE_STRANS_STATE_INIT,
00384
00389 PJ_ICE_STRANS_STATE_READY,
00390
00394 PJ_ICE_STRANS_STATE_SESS_READY,
00395
00399 PJ_ICE_STRANS_STATE_NEGO,
00400
00405 PJ_ICE_STRANS_STATE_RUNNING,
00406
00410 PJ_ICE_STRANS_STATE_FAILED
00411
00412 } pj_ice_strans_state;
00413
00414
00420 PJ_DECL(void) pj_ice_strans_cfg_default(pj_ice_strans_cfg *cfg);
00421
00422
00430 PJ_DECL(void) pj_ice_strans_cfg_copy(pj_pool_t *pool,
00431 pj_ice_strans_cfg *dst,
00432 const pj_ice_strans_cfg *src);
00433
00434
00451 PJ_DECL(pj_status_t) pj_ice_strans_create(const char *name,
00452 const pj_ice_strans_cfg *cfg,
00453 unsigned comp_cnt,
00454 void *user_data,
00455 const pj_ice_strans_cb *cb,
00456 pj_ice_strans **p_ice_st);
00457
00465 PJ_DECL(pj_ice_strans_state) pj_ice_strans_get_state(pj_ice_strans *ice_st);
00466
00467
00475 PJ_DECL(const char*) pj_ice_strans_state_name(pj_ice_strans_state state);
00476
00477
00487 PJ_DECL(pj_status_t) pj_ice_strans_destroy(pj_ice_strans *ice_st);
00488
00489
00497 PJ_DECL(void*) pj_ice_strans_get_user_data(pj_ice_strans *ice_st);
00498
00499
00509 PJ_DECL(pj_status_t) pj_ice_strans_get_options(pj_ice_strans *ice_st,
00510 pj_ice_sess_options *opt);
00511
00522 PJ_DECL(pj_status_t) pj_ice_strans_set_options(pj_ice_strans *ice_st,
00523 const pj_ice_sess_options *opt);
00524
00525
00543 PJ_DECL(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
00544 pj_ice_sess_role role,
00545 const pj_str_t *local_ufrag,
00546 const pj_str_t *local_passwd);
00547
00557 PJ_DECL(pj_bool_t) pj_ice_strans_has_sess(pj_ice_strans *ice_st);
00558
00559
00568 PJ_DECL(pj_bool_t) pj_ice_strans_sess_is_running(pj_ice_strans *ice_st);
00569
00570
00579 PJ_DECL(pj_bool_t) pj_ice_strans_sess_is_complete(pj_ice_strans *ice_st);
00580
00581
00593 PJ_DECL(unsigned) pj_ice_strans_get_running_comp_cnt(pj_ice_strans *ice_st);
00594
00595
00622 PJ_DECL(pj_status_t) pj_ice_strans_get_ufrag_pwd(pj_ice_strans *ice_st,
00623 pj_str_t *loc_ufrag,
00624 pj_str_t *loc_pwd,
00625 pj_str_t *rem_ufrag,
00626 pj_str_t *rem_pwd);
00627
00628
00637 PJ_DECL(unsigned) pj_ice_strans_get_cands_count(pj_ice_strans *ice_st,
00638 unsigned comp_id);
00639
00653 PJ_DECL(pj_status_t) pj_ice_strans_enum_cands(pj_ice_strans *ice_st,
00654 unsigned comp_id,
00655 unsigned *count,
00656 pj_ice_sess_cand cand[]);
00657
00670 PJ_DECL(pj_status_t) pj_ice_strans_get_def_cand(pj_ice_strans *ice_st,
00671 unsigned comp_id,
00672 pj_ice_sess_cand *cand);
00673
00682 PJ_DECL(pj_ice_sess_role) pj_ice_strans_get_role(pj_ice_strans *ice_st);
00683
00684
00697 PJ_DECL(pj_status_t) pj_ice_strans_change_role(pj_ice_strans *ice_st,
00698 pj_ice_sess_role new_role);
00699
00700
00723 PJ_DECL(pj_status_t) pj_ice_strans_start_ice(pj_ice_strans *ice_st,
00724 const pj_str_t *rem_ufrag,
00725 const pj_str_t *rem_passwd,
00726 unsigned rcand_cnt,
00727 const pj_ice_sess_cand rcand[]);
00728
00740 PJ_DECL(const pj_ice_sess_check*)
00741 pj_ice_strans_get_valid_pair(const pj_ice_strans *ice_st,
00742 unsigned comp_id);
00743
00766 PJ_DECL(pj_status_t) pj_ice_strans_stop_ice(pj_ice_strans *ice_st);
00767
00768
00790 PJ_DECL(pj_status_t) pj_ice_strans_sendto(pj_ice_strans *ice_st,
00791 unsigned comp_id,
00792 const void *data,
00793 pj_size_t data_len,
00794 const pj_sockaddr_t *dst_addr,
00795 int dst_addr_len);
00796
00797
00803 PJ_END_DECL
00804
00805
00806
00807 #endif
00808