aboutsummaryrefslogtreecommitdiff
path: root/plugins/ice/src/module.vala
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2021-05-11 12:57:02 +0200
committerfiaxh <git@lightrise.org>2021-05-11 12:57:02 +0200
commitd71604913dd5b3372a823320db83c37c845fac5c (patch)
tree2ffbff97a02c81d48d8aef4a4b7ee870507236e9 /plugins/ice/src/module.vala
parente92ed27317ae398c867c946cf7206b1f0b32f3b4 (diff)
parent90f9ecf62b2ebfef14de2874e7942552409632bf (diff)
downloaddino-d71604913dd5b3372a823320db83c37c845fac5c.tar.gz
dino-d71604913dd5b3372a823320db83c37c845fac5c.zip
Merge remote-tracking branch 'origin/feature/calls'
Diffstat (limited to 'plugins/ice/src/module.vala')
-rw-r--r--plugins/ice/src/module.vala55
1 files changed, 55 insertions, 0 deletions
diff --git a/plugins/ice/src/module.vala b/plugins/ice/src/module.vala
new file mode 100644
index 00000000..2645d7dc
--- /dev/null
+++ b/plugins/ice/src/module.vala
@@ -0,0 +1,55 @@
+using Gee;
+using Xmpp;
+using Xmpp.Xep;
+
+public class Dino.Plugins.Ice.Module : JingleIceUdp.Module {
+
+ public string? stun_ip = null;
+ public uint stun_port = 0;
+ public string? turn_ip = null;
+ public Xep.ExternalServiceDiscovery.Service? turn_service = null;
+
+ private weak Nice.Agent? agent;
+ private HashMap<string, DtlsSrtp.CredentialsCapsule> cerds = new HashMap<string, DtlsSrtp.CredentialsCapsule>();
+
+ private Nice.Agent get_agent() {
+ Nice.Agent? agent = this.agent;
+ if (agent == null) {
+ agent = new Nice.Agent(MainContext.@default(), Nice.Compatibility.RFC5245);
+ if (stun_ip != null) {
+ agent.stun_server = stun_ip;
+ agent.stun_server_port = stun_port;
+ }
+ agent.ice_tcp = false;
+ agent.set_software("Dino");
+ agent.weak_ref(agent_unweak);
+ this.agent = agent;
+ debug("STUN server for libnice %s %u", agent.stun_server, agent.stun_server_port);
+ }
+ return agent;
+ }
+
+ public override Jingle.TransportParameters create_transport_parameters(XmppStream stream, uint8 components, Jid local_full_jid, Jid peer_full_jid) {
+ DtlsSrtp.CredentialsCapsule? cred = get_create_credentials(local_full_jid, peer_full_jid);
+ return new TransportParameters(get_agent(), cred, turn_service, turn_ip, components, local_full_jid, peer_full_jid);
+ }
+
+ public override Jingle.TransportParameters parse_transport_parameters(XmppStream stream, uint8 components, Jid local_full_jid, Jid peer_full_jid, StanzaNode transport) throws Jingle.IqError {
+ DtlsSrtp.CredentialsCapsule? cred = get_create_credentials(local_full_jid, peer_full_jid);
+ return new TransportParameters(get_agent(), cred, turn_service, turn_ip, components, local_full_jid, peer_full_jid, transport);
+ }
+
+ private DtlsSrtp.CredentialsCapsule? get_create_credentials(Jid local_full_jid, Jid peer_full_jid) {
+ string from_to_id = local_full_jid.to_string() + peer_full_jid.to_string();
+ try {
+ if (!cerds.has_key(from_to_id)) cerds[from_to_id] = DtlsSrtp.Handler.generate_credentials();
+ } catch (Error e) {
+ warning("Error creating dtls credentials: %s", e.message);
+ }
+ return cerds[from_to_id];
+ }
+
+ private void agent_unweak() {
+ this.agent = null;
+ }
+} \ No newline at end of file