blob: 9eba6c77f39b05a27697d1849a797c0fcbf4892d [file] [log] [blame]
James Kuszmaul871d0712021-01-17 11:30:43 -08001/**
2 * @file re_ice.h Interface to Interactive Connectivity Establishment (ICE)
3 *
4 * Copyright (C) 2010 Creytiv.com
5 */
6
7
8/** ICE Configuration */
9struct trice_conf {
10 enum ice_nomination nom; /**< Nomination algorithm */
11 bool debug; /**< Enable ICE debugging */
12 bool trace; /**< Enable tracing of Connectivity
13 checks */
14 bool ansi; /**< Enable ANSI colors for debug
15 output */
16 bool enable_prflx; /**< Enable Peer-Reflexive candidates */
17 bool optimize_loopback_pairing;/**< Reduce candidate pairs when
18 using loopback addresses */
19};
20
21struct trice;
22struct ice_lcand;
23struct ice_candpair;
24struct stun_conf;
25
26
27typedef bool (ice_cand_recv_h)(struct ice_lcand *lcand,
28 int proto, void *sock, const struct sa *src,
29 struct mbuf *mb, void *arg);
30
31
32/** Local candidate */
33struct ice_lcand {
34 struct ice_cand_attr attr; /**< Base class (inheritance) */
35 struct le le; /**< List element */
36
37 /* Base-address only set for SRFLX, PRFLX, RELAY */
38 struct sa base_addr; /* IP-address of "base" candidate (optional) */
39
40 struct udp_sock *us;
41 struct udp_helper *uh;
42 struct tcp_sock *ts; /* TCP for simultaneous-open or passive. */
43 char ifname[32]; /**< Network interface, for diagnostics */
44 int layer;
45 ice_cand_recv_h *recvh;
46 void *arg;
47
48 // todo: remove
49 struct trice *icem; /* parent */
50
51 struct {
52 size_t n_tx;
53 size_t n_rx;
54 } stats;
55};
56
57/** Remote candidate */
58struct ice_rcand {
59 struct ice_cand_attr attr; /**< Base class (inheritance) */
60 struct le le; /**< List element */
61};
62
63
64/** Defines a candidate pair */
65struct ice_candpair {
66 struct le le; /**< List element */
67 struct ice_lcand *lcand; /**< Local candidate */
68 struct ice_rcand *rcand; /**< Remote candidate */
69 enum ice_candpair_state state;/**< Candidate pair state */
70 uint64_t pprio; /**< Pair priority */
71 //bool def; /**< Default flag */
72 bool valid; /**< Valid flag */
73 bool nominated; /**< Nominated flag */
74 bool estab;
75 bool trigged;
76 int err; /**< Saved error code, if failed */
77 uint16_t scode; /**< Saved STUN code, if failed */
78
79 struct tcp_conn *tc;
80
81 struct ice_tcpconn *conn; /* the TCP-connection used */
82};
83
84
85typedef void (trice_estab_h)(struct ice_candpair *pair,
86 const struct stun_msg *msg, void *arg);
87
88
89typedef void (trice_failed_h)(int err, uint16_t scode,
90 struct ice_candpair *pair, void *arg);
91
92
93int trice_alloc(struct trice **icemp, const struct trice_conf *conf,
94 enum ice_role role, const char *lufrag, const char *lpwd);
95int trice_set_remote_ufrag(struct trice *icem, const char *rufrag);
96int trice_set_remote_pwd(struct trice *icem, const char *rpwd);
97int trice_set_software(struct trice *icem, const char *sw);
98int trice_set_role(struct trice *trice, enum ice_role role);
99enum ice_role trice_local_role(const struct trice *icem);
100int trice_debug(struct re_printf *pf, const struct trice *icem);
101struct trice_conf *trice_conf(struct trice *icem);
102
103
104/* Candidates (common) */
105int trice_cand_print(struct re_printf *pf, const struct ice_cand_attr *cand);
106enum ice_tcptype ice_tcptype_reverse(enum ice_tcptype type);
107const char *ice_tcptype_name(enum ice_tcptype tcptype);
108enum ice_cand_type ice_cand_type_base(enum ice_cand_type type);
109
110
111/* Local candidates */
112int trice_lcand_add(struct ice_lcand **lcandp, struct trice *icem,
113 unsigned compid, int proto, uint32_t prio,
114 const struct sa *addr, const struct sa *base_addr,
115 enum ice_cand_type type, const struct sa *rel_addr,
116 enum ice_tcptype tcptype,
117 void *sock, int layer);
118struct list *trice_lcandl(const struct trice *icem);
119struct ice_lcand *trice_lcand_find(struct trice *icem,
120 enum ice_cand_type type,
121 unsigned compid, int proto,
122 const struct sa *addr);
123struct ice_lcand *trice_lcand_find2(const struct trice *icem,
124 enum ice_cand_type type, int af);
125void *trice_lcand_sock(struct trice *icem, const struct ice_lcand *lcand);
126void trice_lcand_recv_packet(struct ice_lcand *lcand,
127 const struct sa *src, struct mbuf *mb);
128
129
130/* Remote candidate */
131struct list *trice_rcandl(const struct trice *icem);
132int trice_rcand_add(struct ice_rcand **rcandp, struct trice *icem,
133 unsigned compid, const char *foundation, int proto,
134 uint32_t prio, const struct sa *addr,
135 enum ice_cand_type type, enum ice_tcptype tcptype);
136struct ice_rcand *trice_rcand_find(struct trice *icem, unsigned compid,
137 int proto, const struct sa *addr);
138
139
140/* ICE Candidate pairs */
141struct list *trice_checkl(const struct trice *icem);
142struct list *trice_validl(const struct trice *icem);
143struct ice_candpair *trice_candpair_find_state(const struct list *lst,
144 enum ice_candpair_state state);
145int trice_candpair_debug(struct re_printf *pf, const struct ice_candpair *cp);
146int trice_candpairs_debug(struct re_printf *pf, bool ansi_output,
147 const struct list *list);
148
149
150/* ICE checklist */
151void trice_checklist_set_waiting(struct trice *icem);
152int trice_checklist_start(struct trice *icem, struct stun *stun,
153 uint32_t interval,
154 trice_estab_h *estabh, trice_failed_h *failh,
155 void *arg);
156void trice_checklist_stop(struct trice *icem);
157bool trice_checklist_isrunning(const struct trice *icem);
158bool trice_checklist_iscompleted(const struct trice *icem);
159
160
161/* ICE Conncheck */
162int trice_conncheck_send(struct trice *icem, struct ice_candpair *pair,
163 bool use_cand);
164
165/* Port range */
166int trice_set_port_range(struct trice *trice,
167 uint16_t min_port, uint16_t max_port);