From fd21eafe26a7b72fd3eee575c42654a5219abee3 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Mon, 29 Mar 2021 13:14:10 +0200 Subject: [PATCH] Fix cyclic reference in DTLS --- plugins/ice/src/transport_parameters.vala | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/ice/src/transport_parameters.vala b/plugins/ice/src/transport_parameters.vala index 5b6431c2..2db1ab1b 100644 --- a/plugins/ice/src/transport_parameters.vala +++ b/plugins/ice/src/transport_parameters.vala @@ -65,10 +65,7 @@ public class Dino.Plugins.Ice.TransportParameters : JingleIceUdp.IceUdpTransport this.agent = agent; if (this.peer_fingerprint != null || !incoming) { - dtls_srtp = DtlsSrtp.setup(); - dtls_srtp.send_data.connect((data) => { - agent.send(stream_id, 1, data); - }); + dtls_srtp = setup_dtls(this); this.own_fingerprint = dtls_srtp.get_own_fingerprint(GnuTLS.DigestAlgorithm.SHA256); if (incoming) { dtls_srtp.set_peer_fingerprint(this.peer_fingerprint); @@ -105,6 +102,16 @@ public class Dino.Plugins.Ice.TransportParameters : JingleIceUdp.IceUdpTransport agent.gather_candidates(stream_id); } + private static DtlsSrtp setup_dtls(TransportParameters tp) { + var weak_self = new WeakRef(tp); + DtlsSrtp dtls_srtp = DtlsSrtp.setup(); + dtls_srtp.send_data.connect((data) => { + TransportParameters self = (TransportParameters) weak_self.get(); + if (self != null) self.agent.send(self.stream_id, 1, data); + }); + return dtls_srtp; + } + private void on_candidate_gathering_done(uint stream_id) { if (stream_id != this.stream_id) return; debug("on_candidate_gathering_done in %u", stream_id);