Bug 1626278: Stop requiring additional dispatches to STS for ICE ctx teardown. r=mjf

Also some improvements in discipline wrt bare pointers.

Differential Revision: https://phabricator.services.mozilla.com/D97016
This commit is contained in:
Byron Campen [:bwc] 2020-11-19 19:08:30 +00:00
Родитель d9e2987cba
Коммит 7a97aae8de
6 изменённых файлов: 46 добавлений и 71 удалений

Просмотреть файл

@ -193,8 +193,7 @@ static bool Matches(const nr_ice_media_stream* stream, const std::string& ufrag,
NrIceMediaStream::NrIceMediaStream(NrIceCtx* ctx, const std::string& id,
const std::string& name, size_t components)
: state_(ICE_CONNECTING),
ctx_(ctx->ctx()),
ctx_peer_(ctx->peer()),
ctx_(ctx),
name_(name),
components_(components),
stream_(nullptr),
@ -229,7 +228,7 @@ nsresult NrIceMediaStream::ConnectToPeer(
}
nr_ice_media_stream* peer_stream;
if (nr_ice_peer_ctx_find_pstream(ctx_peer_, stream_, &peer_stream)) {
if (nr_ice_peer_ctx_find_pstream(ctx_->peer(), stream_, &peer_stream)) {
// No peer yet
std::vector<char*> attributes_in;
attributes_in.reserve(attributes.size());
@ -240,7 +239,8 @@ nsresult NrIceMediaStream::ConnectToPeer(
// Still need to call nr_ice_ctx_parse_stream_attributes.
int r = nr_ice_peer_ctx_parse_stream_attributes(
ctx_peer_, stream_, attributes_in.empty() ? nullptr : &attributes_in[0],
ctx_->peer(), stream_,
attributes_in.empty() ? nullptr : &attributes_in[0],
attributes_in.size());
if (r) {
MOZ_MTLOG(ML_ERROR,
@ -269,7 +269,7 @@ nsresult NrIceMediaStream::SetIceCredentials(const std::string& ufrag,
std::string name(name_ + " - " + ufrag + ":" + pwd);
int r = nr_ice_add_media_stream(ctx_, name.c_str(), ufrag.c_str(),
int r = nr_ice_add_media_stream(ctx_->ctx(), name.c_str(), ufrag.c_str(),
pwd.c_str(), components_, &stream_);
if (r) {
MOZ_MTLOG(ML_ERROR, "Couldn't create ICE media stream for '"
@ -292,12 +292,12 @@ nsresult NrIceMediaStream::ParseTrickleCandidate(const std::string& candidate,
return NS_ERROR_FAILURE;
}
MOZ_MTLOG(ML_INFO, "NrIceCtx(" << ctx_->label << ")/STREAM(" << name()
MOZ_MTLOG(ML_INFO, "NrIceCtx(" << ctx_->ctx()->label << ")/STREAM(" << name()
<< ") : parsing trickle candidate "
<< candidate);
int r = nr_ice_peer_ctx_parse_trickle_candidate(
ctx_peer_, stream, const_cast<char*>(candidate.c_str()),
ctx_->peer(), stream, const_cast<char*>(candidate.c_str()),
mdns_addr.c_str());
if (r) {
@ -333,8 +333,8 @@ nsresult NrIceMediaStream::GetActivePair(int component,
return NS_ERROR_NOT_AVAILABLE;
}
r = nr_ice_media_stream_get_active(ctx_peer_, stream_, component, &local_int,
&remote_int);
r = nr_ice_media_stream_get_active(ctx_->peer(), stream_, component,
&local_int, &remote_int);
// If result is R_REJECTED then component is unpaired or disabled.
if (r == R_REJECTED) return NS_ERROR_NOT_AVAILABLE;
@ -360,14 +360,14 @@ nsresult NrIceMediaStream::GetCandidatePairs(
}
// If we haven't at least started checking then there is nothing to report
if (ctx_peer_->state != NR_ICE_PEER_STATE_PAIRED) {
if (ctx_->peer()->state != NR_ICE_PEER_STATE_PAIRED) {
return NS_OK;
}
// Get the check_list on the peer stream (this is where the check_list
// actually lives, not in stream_)
nr_ice_media_stream* peer_stream;
int r = nr_ice_peer_ctx_find_pstream(ctx_peer_, stream_, &peer_stream);
int r = nr_ice_peer_ctx_find_pstream(ctx_->peer(), stream_, &peer_stream);
if (r != 0) {
return NS_ERROR_FAILURE;
}
@ -562,12 +562,12 @@ nsresult NrIceMediaStream::GetRemoteCandidates(
}
// If we haven't at least started checking then there is nothing to report
if (ctx_peer_->state != NR_ICE_PEER_STATE_PAIRED) {
if (ctx_->peer()->state != NR_ICE_PEER_STATE_PAIRED) {
return NS_OK;
}
nr_ice_media_stream* peer_stream;
int r = nr_ice_peer_ctx_find_pstream(ctx_peer_, stream_, &peer_stream);
int r = nr_ice_peer_ctx_find_pstream(ctx_->peer(), stream_, &peer_stream);
if (r != 0) {
return NS_ERROR_FAILURE;
}
@ -592,7 +592,7 @@ nsresult NrIceMediaStream::GetConsentStatus(int component_id, bool* can_send,
if (!stream_) return NS_ERROR_FAILURE;
nr_ice_media_stream* peer_stream;
int r = nr_ice_peer_ctx_find_pstream(ctx_peer_, stream_, &peer_stream);
int r = nr_ice_peer_ctx_find_pstream(ctx_->peer(), stream_, &peer_stream);
if (r) {
MOZ_MTLOG(ML_ERROR, "Failed to find peer stream for '"
<< name_ << "':" << component_id);
@ -623,7 +623,7 @@ nsresult NrIceMediaStream::SendPacket(int component_id,
return NS_ERROR_FAILURE;
}
int r = nr_ice_media_stream_send(ctx_peer_, stream, component_id,
int r = nr_ice_media_stream_send(ctx_->peer(), stream, component_id,
const_cast<unsigned char*>(data), len);
if (r) {
MOZ_MTLOG(ML_ERROR, "Couldn't send media on '" << name_ << "'");
@ -671,11 +671,12 @@ void NrIceMediaStream::Close() {
CloseStream(&old_stream_);
CloseStream(&stream_);
ctx_ = nullptr;
}
void NrIceMediaStream::CloseStream(nr_ice_media_stream** stream) {
if (*stream) {
int r = nr_ice_remove_media_stream(ctx_, stream);
int r = nr_ice_remove_media_stream(ctx_->ctx(), stream);
if (r) {
MOZ_ASSERT(false, "Failed to remove stream");
MOZ_MTLOG(ML_ERROR, "Failed to remove stream, error=" << r);
@ -698,13 +699,13 @@ nr_ice_media_stream* NrIceMediaStream::GetStreamForRemoteUfrag(
nr_ice_media_stream* peer_stream = nullptr;
if (!nr_ice_peer_ctx_find_pstream(ctx_peer_, stream_, &peer_stream) &&
if (!nr_ice_peer_ctx_find_pstream(ctx_->peer(), stream_, &peer_stream) &&
aUfrag == peer_stream->ufrag) {
return stream_;
}
if (old_stream_ &&
!nr_ice_peer_ctx_find_pstream(ctx_peer_, old_stream_, &peer_stream) &&
!nr_ice_peer_ctx_find_pstream(ctx_->peer(), old_stream_, &peer_stream) &&
aUfrag == peer_stream->ufrag) {
return old_stream_;
}

Просмотреть файл

@ -213,8 +213,7 @@ class NrIceMediaStream {
nr_ice_media_stream* GetStreamForRemoteUfrag(const std::string& ufrag);
State state_;
nr_ice_ctx* ctx_;
nr_ice_peer_ctx* ctx_peer_;
RefPtr<NrIceCtx> ctx_;
const std::string name_;
const size_t components_;
nr_ice_media_stream* stream_;

Просмотреть файл

@ -62,7 +62,6 @@ static int nr_ice_fetch_stun_servers(int ct, nr_ice_stun_server **out);
#ifdef USE_TURN
static int nr_ice_fetch_turn_servers(int ct, nr_ice_turn_server **out);
#endif /* USE_TURN */
static void nr_ice_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg);
static int nr_ice_ctx_pair_new_trickle_candidates(nr_ice_ctx *ctx, nr_ice_candidate *cand);
static int no_op(void **obj) {
return 0;
@ -416,20 +415,31 @@ int nr_ice_ctx_create(char *label, UINT4 flags, nr_ice_ctx **ctxp)
_status=0;
abort:
if(_status && ctx)
nr_ice_ctx_destroy_cb(0,0,ctx);
if (_status && ctx) nr_ice_ctx_destroy(&ctx);
return(_status);
}
static void nr_ice_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg)
{
nr_ice_ctx *ctx=cb_arg;
void nr_ice_ctx_add_flags(nr_ice_ctx* ctx, UINT4 flags) {
ctx->flags |= flags;
}
void nr_ice_ctx_remove_flags(nr_ice_ctx* ctx, UINT4 flags) {
ctx->flags &= ~flags;
}
void nr_ice_ctx_destroy(nr_ice_ctx** ctxp) {
if (!ctxp || !*ctxp) return;
nr_ice_ctx* ctx = *ctxp;
nr_ice_foundation *f1,*f2;
nr_ice_media_stream *s1,*s2;
int i;
nr_ice_stun_id *id1,*id2;
ctx->done_cb = 0;
ctx->trickle_cb = 0;
STAILQ_FOREACH_SAFE(s1, &ctx->streams, entry, s2){
STAILQ_REMOVE(&ctx->streams,s1,nr_ice_media_stream_,entry);
nr_ice_media_stream_destroy(&s1);
@ -466,31 +476,8 @@ static void nr_ice_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg)
nr_socket_factory_destroy(&ctx->socket_factory);
RFREE(ctx);
}
void nr_ice_ctx_add_flags(nr_ice_ctx *ctx, UINT4 flags)
{
ctx->flags |= flags;
}
void nr_ice_ctx_remove_flags(nr_ice_ctx *ctx, UINT4 flags)
{
ctx->flags &= ~flags;
}
int nr_ice_ctx_destroy(nr_ice_ctx **ctxp)
{
if(!ctxp || !*ctxp)
return(0);
(*ctxp)->done_cb=0;
(*ctxp)->trickle_cb=0;
NR_ASYNC_SCHEDULE(nr_ice_ctx_destroy_cb,*ctxp);
*ctxp=0;
return(0);
}
void nr_ice_gather_finished_cb(NR_SOCKET s, int h, void *cb_arg)

Просмотреть файл

@ -174,7 +174,7 @@ int nr_ice_ctx_create_with_credentials(char *label, UINT4 flags, char* ufrag, ch
void nr_ice_ctx_add_flags(nr_ice_ctx *ctx, UINT4 flags);
void nr_ice_ctx_remove_flags(nr_ice_ctx *ctx, UINT4 flags);
int nr_ice_ctx_destroy(nr_ice_ctx **ctxp);
void nr_ice_ctx_destroy(nr_ice_ctx** ctxp);
int nr_ice_set_local_addresses(nr_ice_ctx *ctx, nr_local_addr* stun_addrs, int stun_addr_ct);
int nr_ice_set_target_for_default_local_address_lookup(nr_ice_ctx *ctx, const char *target_ip, UINT2 target_port);
int nr_ice_gather(nr_ice_ctx *ctx, NR_async_cb done_cb, void *cb_arg);

Просмотреть файл

@ -42,7 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "async_timer.h"
#include "ice_reg.h"
static void nr_ice_peer_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg);
static void nr_ice_peer_ctx_parse_stream_attributes_int(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, nr_ice_media_stream *pstream, char **attrs, int attr_ct);
static int nr_ice_ctx_parse_candidate(nr_ice_peer_ctx *pctx, nr_ice_media_stream *pstream, char *candidate, int trickled, const char *mdns_addr);
static void nr_ice_peer_ctx_start_trickle_timer(nr_ice_peer_ctx *pctx);
@ -81,7 +80,7 @@ int nr_ice_peer_ctx_create(nr_ice_ctx *ctx, nr_ice_handler *handler,char *label,
_status = 0;
abort:
if(_status){
nr_ice_peer_ctx_destroy_cb(0,0,pctx);
nr_ice_peer_ctx_destroy(&pctx);
}
return(_status);
}
@ -476,11 +475,15 @@ int nr_ice_peer_ctx_disable_component(nr_ice_peer_ctx *pctx, nr_ice_media_stream
return(_status);
}
static void nr_ice_peer_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg)
{
nr_ice_peer_ctx *pctx=cb_arg;
void nr_ice_peer_ctx_destroy(nr_ice_peer_ctx** pctxp) {
if (!pctxp || !*pctxp) return;
nr_ice_peer_ctx* pctx = *pctxp;
nr_ice_media_stream *str1,*str2;
/* Stop calling the handler */
pctx->handler = 0;
NR_async_timer_cancel(pctx->connected_cb_timer);
RFREE(pctx->label);
@ -498,25 +501,10 @@ static void nr_ice_peer_ctx_destroy_cb(NR_SOCKET s, int how, void *cb_arg)
}
RFREE(pctx);
}
int nr_ice_peer_ctx_destroy(nr_ice_peer_ctx **pctxp)
{
if(!pctxp || !*pctxp)
return(0);
/* Stop calling the handler */
(*pctxp)->handler = 0;
NR_ASYNC_SCHEDULE(nr_ice_peer_ctx_destroy_cb,*pctxp);
*pctxp=0;
return(0);
}
/* Start the checks for the first media stream (S 5.7)
The rest remain FROZEN */
int nr_ice_peer_ctx_start_checks(nr_ice_peer_ctx *pctx)

Просмотреть файл

@ -70,7 +70,7 @@ struct nr_ice_peer_ctx_ {
typedef STAILQ_HEAD(nr_ice_peer_ctx_head_, nr_ice_peer_ctx_) nr_ice_peer_ctx_head;
int nr_ice_peer_ctx_create(nr_ice_ctx *ctx, nr_ice_handler *handler,char *label, nr_ice_peer_ctx **pctxp);
int nr_ice_peer_ctx_destroy(nr_ice_peer_ctx **pctxp);
void nr_ice_peer_ctx_destroy(nr_ice_peer_ctx** pctxp);
int nr_ice_peer_ctx_parse_stream_attributes(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, char **attrs, int attr_ct);
int nr_ice_peer_ctx_find_pstream(nr_ice_peer_ctx *pctx, nr_ice_media_stream *stream, nr_ice_media_stream **pstreamp);
int nr_ice_peer_ctx_remove_pstream(nr_ice_peer_ctx *pctx, nr_ice_media_stream **pstreamp);