Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | Copyright (c) 2007, Adobe Systems, Incorporated |
michael@0 | 3 | All rights reserved. |
michael@0 | 4 | |
michael@0 | 5 | Redistribution and use in source and binary forms, with or without |
michael@0 | 6 | modification, are permitted provided that the following conditions are |
michael@0 | 7 | met: |
michael@0 | 8 | |
michael@0 | 9 | * Redistributions of source code must retain the above copyright |
michael@0 | 10 | notice, this list of conditions and the following disclaimer. |
michael@0 | 11 | |
michael@0 | 12 | * Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | notice, this list of conditions and the following disclaimer in the |
michael@0 | 14 | documentation and/or other materials provided with the distribution. |
michael@0 | 15 | |
michael@0 | 16 | * Neither the name of Adobe Systems, Network Resonance nor the names of its |
michael@0 | 17 | contributors may be used to endorse or promote products derived from |
michael@0 | 18 | this software without specific prior written permission. |
michael@0 | 19 | |
michael@0 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
michael@0 | 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
michael@0 | 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
michael@0 | 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
michael@0 | 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
michael@0 | 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
michael@0 | 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
michael@0 | 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
michael@0 | 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
michael@0 | 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | */ |
michael@0 | 32 | |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | #ifndef _ice_ctx_h |
michael@0 | 36 | #define _ice_ctx_h |
michael@0 | 37 | #ifdef __cplusplus |
michael@0 | 38 | using namespace std; |
michael@0 | 39 | extern "C" { |
michael@0 | 40 | #endif /* __cplusplus */ |
michael@0 | 41 | |
michael@0 | 42 | /* Not good practice but making includes simpler */ |
michael@0 | 43 | #include "transport_addr.h" |
michael@0 | 44 | #include "nr_socket.h" |
michael@0 | 45 | #include "nr_resolver.h" |
michael@0 | 46 | #include "nr_interface_prioritizer.h" |
michael@0 | 47 | #include "stun_client_ctx.h" |
michael@0 | 48 | #include "stun_server_ctx.h" |
michael@0 | 49 | #include "turn_client_ctx.h" |
michael@0 | 50 | |
michael@0 | 51 | #define NR_ICE_STUN_SERVER_TYPE_ADDR 1 |
michael@0 | 52 | #define NR_ICE_STUN_SERVER_TYPE_DNSNAME 2 |
michael@0 | 53 | |
michael@0 | 54 | typedef struct nr_ice_stun_server_ { |
michael@0 | 55 | int type; |
michael@0 | 56 | union { |
michael@0 | 57 | nr_transport_addr addr; |
michael@0 | 58 | struct { |
michael@0 | 59 | char host[256]; /* Limit from RFC 1034, plus a 0 byte */ |
michael@0 | 60 | UINT2 port; |
michael@0 | 61 | } dnsname; |
michael@0 | 62 | } u; |
michael@0 | 63 | int index; |
michael@0 | 64 | } nr_ice_stun_server; |
michael@0 | 65 | |
michael@0 | 66 | typedef struct nr_ice_turn_server_ { |
michael@0 | 67 | nr_ice_stun_server turn_server; |
michael@0 | 68 | int transport; |
michael@0 | 69 | char *username; |
michael@0 | 70 | Data *password; |
michael@0 | 71 | } nr_ice_turn_server; |
michael@0 | 72 | |
michael@0 | 73 | typedef struct nr_ice_foundation_ { |
michael@0 | 74 | int index; |
michael@0 | 75 | |
michael@0 | 76 | nr_transport_addr addr; |
michael@0 | 77 | int type; |
michael@0 | 78 | nr_ice_stun_server *stun_server; |
michael@0 | 79 | |
michael@0 | 80 | STAILQ_ENTRY(nr_ice_foundation_) entry; |
michael@0 | 81 | } nr_ice_foundation; |
michael@0 | 82 | |
michael@0 | 83 | typedef STAILQ_HEAD(nr_ice_foundation_head_,nr_ice_foundation_) nr_ice_foundation_head; |
michael@0 | 84 | |
michael@0 | 85 | typedef TAILQ_HEAD(nr_ice_candidate_head_,nr_ice_candidate_) nr_ice_candidate_head; |
michael@0 | 86 | typedef TAILQ_HEAD(nr_ice_cand_pair_head_,nr_ice_cand_pair_) nr_ice_cand_pair_head; |
michael@0 | 87 | typedef struct nr_ice_component_ nr_ice_component; |
michael@0 | 88 | typedef struct nr_ice_media_stream_ nr_ice_media_stream; |
michael@0 | 89 | typedef struct nr_ice_ctx_ nr_ice_ctx; |
michael@0 | 90 | typedef struct nr_ice_peer_ctx_ nr_ice_peer_ctx; |
michael@0 | 91 | typedef struct nr_ice_candidate_ nr_ice_candidate; |
michael@0 | 92 | typedef struct nr_ice_cand_pair_ nr_ice_cand_pair; |
michael@0 | 93 | typedef void (*nr_ice_trickle_candidate_cb) (void *cb_arg, |
michael@0 | 94 | nr_ice_ctx *ctx, nr_ice_media_stream *stream, int component_id, |
michael@0 | 95 | nr_ice_candidate *candidate); |
michael@0 | 96 | |
michael@0 | 97 | #include "ice_socket.h" |
michael@0 | 98 | #include "ice_component.h" |
michael@0 | 99 | #include "ice_media_stream.h" |
michael@0 | 100 | #include "ice_candidate.h" |
michael@0 | 101 | #include "ice_candidate_pair.h" |
michael@0 | 102 | #include "ice_handler.h" |
michael@0 | 103 | #include "ice_peer_ctx.h" |
michael@0 | 104 | |
michael@0 | 105 | typedef struct nr_ice_stun_id_ { |
michael@0 | 106 | UCHAR id[12]; |
michael@0 | 107 | |
michael@0 | 108 | STAILQ_ENTRY(nr_ice_stun_id_) entry; |
michael@0 | 109 | } nr_ice_stun_id; |
michael@0 | 110 | |
michael@0 | 111 | typedef STAILQ_HEAD(nr_ice_stun_id_head_,nr_ice_stun_id_) nr_ice_stun_id_head; |
michael@0 | 112 | |
michael@0 | 113 | struct nr_ice_ctx_ { |
michael@0 | 114 | UINT4 flags; |
michael@0 | 115 | int state; |
michael@0 | 116 | #define NR_ICE_STATE_CREATED 1 |
michael@0 | 117 | #define NR_ICE_STATE_INITIALIZING 2 |
michael@0 | 118 | #define NR_ICE_STATE_INITIALIZED 3 |
michael@0 | 119 | char *label; |
michael@0 | 120 | |
michael@0 | 121 | char *ufrag; |
michael@0 | 122 | char *pwd; |
michael@0 | 123 | |
michael@0 | 124 | UINT4 Ta; |
michael@0 | 125 | |
michael@0 | 126 | nr_ice_stun_server *stun_servers; /* The list of stun servers */ |
michael@0 | 127 | int stun_server_ct; |
michael@0 | 128 | nr_ice_turn_server *turn_servers; /* The list of turn servers */ |
michael@0 | 129 | int turn_server_ct; |
michael@0 | 130 | nr_local_addr *local_addrs; /* The list of available local addresses and corresponding interface information */ |
michael@0 | 131 | int local_addr_ct; |
michael@0 | 132 | |
michael@0 | 133 | nr_resolver *resolver; /* The resolver to use */ |
michael@0 | 134 | nr_interface_prioritizer *interface_prioritizer; /* Priority decision logic */ |
michael@0 | 135 | |
michael@0 | 136 | nr_ice_foundation_head foundations; |
michael@0 | 137 | |
michael@0 | 138 | nr_ice_media_stream_head streams; /* Media streams */ |
michael@0 | 139 | int stream_ct; |
michael@0 | 140 | nr_ice_socket_head sockets; /* The sockets we're using */ |
michael@0 | 141 | int uninitialized_candidates; |
michael@0 | 142 | |
michael@0 | 143 | UINT4 gather_rto; |
michael@0 | 144 | UINT4 stun_delay; |
michael@0 | 145 | |
michael@0 | 146 | nr_ice_peer_ctx_head peers; |
michael@0 | 147 | nr_ice_stun_id_head ids; |
michael@0 | 148 | |
michael@0 | 149 | NR_async_cb done_cb; |
michael@0 | 150 | void *cb_arg; |
michael@0 | 151 | |
michael@0 | 152 | nr_ice_trickle_candidate_cb trickle_cb; |
michael@0 | 153 | void *trickle_cb_arg; |
michael@0 | 154 | }; |
michael@0 | 155 | |
michael@0 | 156 | int nr_ice_ctx_create(char *label, UINT4 flags, nr_ice_ctx **ctxp); |
michael@0 | 157 | #define NR_ICE_CTX_FLAGS_OFFERER 1 |
michael@0 | 158 | #define NR_ICE_CTX_FLAGS_ANSWERER (1<<1) |
michael@0 | 159 | #define NR_ICE_CTX_FLAGS_AGGRESSIVE_NOMINATION (1<<2) |
michael@0 | 160 | #define NR_ICE_CTX_FLAGS_LITE (1<<3) |
michael@0 | 161 | |
michael@0 | 162 | int nr_ice_ctx_destroy(nr_ice_ctx **ctxp); |
michael@0 | 163 | int nr_ice_initialize(nr_ice_ctx *ctx, NR_async_cb done_cb, void *cb_arg); |
michael@0 | 164 | int nr_ice_add_candidate(nr_ice_ctx *ctx, nr_ice_candidate *cand); |
michael@0 | 165 | void nr_ice_initialize_finished_cb(NR_SOCKET s, int h, void *cb_arg); |
michael@0 | 166 | int nr_ice_add_media_stream(nr_ice_ctx *ctx,char *label,int components, nr_ice_media_stream **streamp); |
michael@0 | 167 | int nr_ice_get_global_attributes(nr_ice_ctx *ctx,char ***attrsp, int *attrctp); |
michael@0 | 168 | int nr_ice_ctx_deliver_packet(nr_ice_ctx *ctx, nr_ice_component *comp, nr_transport_addr *source_addr, UCHAR *data, int len); |
michael@0 | 169 | int nr_ice_ctx_is_known_id(nr_ice_ctx *ctx, UCHAR id[12]); |
michael@0 | 170 | int nr_ice_ctx_remember_id(nr_ice_ctx *ctx, nr_stun_message *msg); |
michael@0 | 171 | int nr_ice_ctx_finalize(nr_ice_ctx *ctx, nr_ice_peer_ctx *pctx); |
michael@0 | 172 | int nr_ice_ctx_set_stun_servers(nr_ice_ctx *ctx,nr_ice_stun_server *servers, int ct); |
michael@0 | 173 | int nr_ice_ctx_set_turn_servers(nr_ice_ctx *ctx,nr_ice_turn_server *servers, int ct); |
michael@0 | 174 | int nr_ice_ctx_set_resolver(nr_ice_ctx *ctx, nr_resolver *resolver); |
michael@0 | 175 | int nr_ice_ctx_set_interface_prioritizer(nr_ice_ctx *ctx, nr_interface_prioritizer *prioritizer); |
michael@0 | 176 | int nr_ice_ctx_set_trickle_cb(nr_ice_ctx *ctx, nr_ice_trickle_candidate_cb cb, void *cb_arg); |
michael@0 | 177 | |
michael@0 | 178 | #define NR_ICE_MAX_ATTRIBUTE_SIZE 256 |
michael@0 | 179 | |
michael@0 | 180 | extern int LOG_ICE; |
michael@0 | 181 | |
michael@0 | 182 | #ifdef __cplusplus |
michael@0 | 183 | } |
michael@0 | 184 | #endif /* __cplusplus */ |
michael@0 | 185 | #endif |
michael@0 | 186 |