From cd0d992b9b5d3ea29c7d4a3aab76ad53319ea162 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sat, 3 Oct 2026 13:22:02 +0200 Subject: Move ICE into libdino --- plugins/ice/meson.build | 25 -- plugins/ice/src/module.vala | 57 ---- plugins/ice/src/plugin.vala | 104 -------- plugins/ice/src/register_plugin.vala | 3 - plugins/ice/src/transport_parameters.vala | 391 ---------------------------- plugins/ice/src/util.vala | 18 -- plugins/ice/vapi/metadata/Nice-0.1.metadata | 11 - plugins/ice/vapi/nice.vapi | 386 --------------------------- 8 files changed, 995 deletions(-) delete mode 100644 plugins/ice/meson.build delete mode 100644 plugins/ice/src/module.vala delete mode 100644 plugins/ice/src/plugin.vala delete mode 100644 plugins/ice/src/register_plugin.vala delete mode 100644 plugins/ice/src/transport_parameters.vala delete mode 100644 plugins/ice/src/util.vala delete mode 100644 plugins/ice/vapi/metadata/Nice-0.1.metadata delete mode 100644 plugins/ice/vapi/nice.vapi (limited to 'plugins/ice') diff --git a/plugins/ice/meson.build b/plugins/ice/meson.build deleted file mode 100644 index 19030259..00000000 --- a/plugins/ice/meson.build +++ /dev/null @@ -1,25 +0,0 @@ -dependencies = [ - dep_dino, - dep_gee, - dep_gio, - dep_glib, - dep_gmodule, - dep_nice, - dep_xmpp_vala, -] -sources = files( - 'src/module.vala', - 'src/plugin.vala', - 'src/transport_parameters.vala', - 'src/util.vala', - 'src/register_plugin.vala', -) -c_args = vala_c_args + [ - '-DG_LOG_DOMAIN="ice"', -] -vala_args = [ - '--vapidir', meson.current_source_dir() / 'vapi', -] -lib_ice = shared_library('ice', sources, name_prefix: '', c_args: c_args, vala_args: vala_args, include_directories: include_directories('src'), dependencies: dependencies, install: true, install_dir: get_option('libdir') / get_option('plugindir'), install_rpath: default_install_rpath) -dep_ice = declare_dependency(link_with: lib_ice, include_directories: include_directories('.')) -summary('Peer-to-peer communication (ice)', dep_ice.found(), bool_yn: true, section: 'Plugins') diff --git a/plugins/ice/src/module.vala b/plugins/ice/src/module.vala deleted file mode 100644 index c3c92124..00000000 --- a/plugins/ice/src/module.vala +++ /dev/null @@ -1,57 +0,0 @@ -using Gee; - -using Dino.Crypto; -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 cerds = new HashMap(); - - 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.generate_credentials(); - } catch (GLib.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 diff --git a/plugins/ice/src/plugin.vala b/plugins/ice/src/plugin.vala deleted file mode 100644 index d1655a74..00000000 --- a/plugins/ice/src/plugin.vala +++ /dev/null @@ -1,104 +0,0 @@ -using Gee; -using Dino.Entities; -using Xmpp; -using Xmpp.Xep; - -private extern const size_t NICE_ADDRESS_STRING_LEN; - -public class Dino.Plugins.Ice.Plugin : RootInterface, Object { - private HashMap timeouts = new HashMap(Account.hash_func, Account.equals_func); - - public Dino.Application app; - - public void registered(Dino.Application app) { - Nice.debug_enable(true); - this.app = app; - app.stream_interactor.module_manager.initialize_account_modules.connect((account, list) => { - list.add(new Module()); - }); - app.stream_interactor.stream_attached_modules.connect((account, stream) => { - if (stream.get_module(Socks5Bytestreams.Module.IDENTITY) != null) { - stream.get_module(Socks5Bytestreams.Module.IDENTITY).set_local_ip_address_handler(get_local_ip_addresses); - } - if (stream.get_module(JingleRawUdp.Module.IDENTITY) != null) { - stream.get_module(JingleRawUdp.Module.IDENTITY).set_local_ip_address_handler(get_local_ip_addresses); - } - }); - app.stream_interactor.stream_negotiated.connect(external_discovery_refresh_services); - } - - private async void external_discovery_refresh_services(Account account, XmppStream stream) { - Module? ice_udp_module = stream.get_module(JingleIceUdp.Module.IDENTITY) as Module; - if (ice_udp_module == null) return; - - Gee.List services = yield ExternalServiceDiscovery.request_services(stream); - foreach (Xep.ExternalServiceDiscovery.Service service in services) { - if (service.transport == "udp" && (service.ty == "stun" || service.ty == "turn")) { - InetAddress? ip = yield lookup_ipv4_addess(service.host); - if (ip == null) continue; - - if (ip.is_any || ip.is_link_local || ip.is_loopback || ip.is_multicast || ip.is_site_local) { - warning("Ignoring STUN/TURN server at %s", service.host); - continue; - } - - if (service.ty == "stun") { - debug("Server offers STUN server: %s:%u, resolved to %s", service.host, service.port, ip.to_string()); - ice_udp_module.stun_ip = ip.to_string(); - ice_udp_module.stun_port = service.port; - } else if (service.ty == "turn") { - debug("Server offers TURN server: %s:%u, resolved to %s", service.host, service.port, ip.to_string()); - ice_udp_module.turn_ip = ip.to_string(); - ice_udp_module.turn_service = service; - } - } - } - if (ice_udp_module.stun_ip == null) { - InetAddress ip = yield lookup_ipv4_addess("stun.dino.im"); - if (ip == null) return; - - debug("Using fallback STUN server: stun.dino.im:7886, resolved to %s", ip.to_string()); - - ice_udp_module.stun_ip = ip.to_string(); - ice_udp_module.stun_port = 7886; - } - - // Refresh TURN credentials before they expire - if (ice_udp_module.turn_service != null) { - DateTime? expires = ice_udp_module.turn_service.expires; - if (expires != null) { - uint refresh_delay = (uint) (expires.to_unix() - new DateTime.now_utc().to_unix()) / 2; - - if (refresh_delay >= 300 && refresh_delay <= (int64) uint.MAX) { // 5 min < refetch < max - debug("Re-fetching TURN credentials in %u sec", refresh_delay); - - timeouts.unset(account); - timeouts[account] = Timeout.add_seconds((uint) refresh_delay, () => { - external_discovery_refresh_services.begin(account, stream); - return false; - }); - } else { - warning("TURN credentials' expiry time = %u, *not* re-fetching", refresh_delay); - } - } - } - } - - public void shutdown() { - // Nothing to do - } - - private async InetAddress? lookup_ipv4_addess(string host) { - try { - Resolver resolver = Resolver.get_default(); - GLib.List? ips = yield resolver.lookup_by_name_async(host); - foreach (GLib.InetAddress ina in ips) { - if (ina.get_family() != SocketFamily.IPV4) continue; - return ina; - } - } catch (Error e) { - warning("Failed looking up IP address of %s", host); - } - return null; - } -} \ No newline at end of file diff --git a/plugins/ice/src/register_plugin.vala b/plugins/ice/src/register_plugin.vala deleted file mode 100644 index b2ed56c1..00000000 --- a/plugins/ice/src/register_plugin.vala +++ /dev/null @@ -1,3 +0,0 @@ -public Type register_plugin(Module module) { - return typeof (Dino.Plugins.Ice.Plugin); -} diff --git a/plugins/ice/src/transport_parameters.vala b/plugins/ice/src/transport_parameters.vala deleted file mode 100644 index 122207c5..00000000 --- a/plugins/ice/src/transport_parameters.vala +++ /dev/null @@ -1,391 +0,0 @@ -using Gee; - -using Dino.Crypto; -using Xmpp; -using Xmpp.Xep; - - -public class Dino.Plugins.Ice.TransportParameters : JingleIceUdp.IceUdpTransportParameters { - private Nice.Agent agent; - private uint stream_id; - private bool we_want_connection; - private bool remote_credentials_set; - private Map connections = new HashMap(); - private DtlsSrtp.Handler? dtls_srtp_handler; - private MainContext thread_context; - private MainLoop thread_loop; - - private class DatagramConnection : Jingle.DatagramConnection { - private Nice.Agent agent; - private DtlsSrtp.Handler? dtls_srtp_handler; - private uint stream_id; - private string? error; - private ulong datagram_received_id; - - public DatagramConnection(Nice.Agent agent, DtlsSrtp.Handler? dtls_srtp_handler, uint stream_id, uint8 component_id) { - this.agent = agent; - this.dtls_srtp_handler = dtls_srtp_handler; - this.stream_id = stream_id; - this.component_id = component_id; - this.datagram_received_id = this.datagram_received.connect((datagram) => { - bytes_received += datagram.length; - }); - } - - public override async void terminate(bool we_terminated, string? reason_string = null, string? reason_text = null) { - yield base.terminate(we_terminated, reason_string, reason_text); - this.disconnect(datagram_received_id); - agent = null; - dtls_srtp_handler = null; - } - - public override void send_datagram(Bytes datagram) { - if (this.agent != null && is_component_ready(agent, stream_id, component_id)) { - try { - if (dtls_srtp_handler != null) { - uint8[] encrypted_data = dtls_srtp_handler.process_outgoing_data(component_id, datagram.get_data()); - if (encrypted_data == null) return; - GLib.OutputVector vector = { encrypted_data, encrypted_data.length }; - GLib.OutputVector[] vectors = { vector }; - Nice.OutputMessage message = { vectors }; - Nice.OutputMessage[] messages = { message }; - agent.send_messages_nonblocking(stream_id, component_id, messages); - } else { - GLib.OutputVector vector = { datagram.get_data(), datagram.get_size() }; - GLib.OutputVector[] vectors = { vector }; - Nice.OutputMessage message = { vectors }; - Nice.OutputMessage[] messages = { message }; - agent.send_messages_nonblocking(stream_id, component_id, messages); - } - bytes_sent += datagram.length; - } catch (GLib.Error e) { - warning("%s while send_datagram stream %u component %u", e.message, stream_id, component_id); - } - } - } - } - - public TransportParameters(Nice.Agent agent, DtlsSrtp.CredentialsCapsule? credentials, Xep.ExternalServiceDiscovery.Service? turn_service, string? turn_ip, uint8 components, Jid local_full_jid, Jid peer_full_jid, StanzaNode? node = null) { - base(components, local_full_jid, peer_full_jid, node); - this.we_want_connection = (node == null); - this.agent = agent; - - if (this.peer_fingerprint != null || !incoming) { - dtls_srtp_handler = setup_dtls(this, credentials); - own_fingerprint = dtls_srtp_handler.own_fingerprint; - if (incoming) { - own_setup = "active"; - dtls_srtp_handler.mode = DtlsSrtp.Mode.CLIENT; - dtls_srtp_handler.peer_fingerprint = peer_fingerprint; - dtls_srtp_handler.peer_fp_algo = peer_fp_algo; - } else { - own_setup = "actpass"; - dtls_srtp_handler.mode = DtlsSrtp.Mode.SERVER; - dtls_srtp_handler.setup_dtls_connection.begin((_, res) => { - var content_encryption = dtls_srtp_handler.setup_dtls_connection.end(res); - if (content_encryption != null) { - this.content.encryptions[content_encryption.encryption_ns] = content_encryption; - } - }); - } - } - - agent.candidate_gathering_done.connect(on_candidate_gathering_done); - agent.initial_binding_request_received.connect(on_initial_binding_request_received); - agent.component_state_changed.connect(on_component_state_changed); - agent.new_selected_pair_full.connect(on_new_selected_pair_full); - agent.new_candidate_full.connect(on_new_candidate); - - agent.controlling_mode = !incoming; - stream_id = agent.add_stream(components); - thread_context = new MainContext(); - new Thread(@"ice-thread-$stream_id", () => { - thread_context.push_thread_default(); - thread_loop = new MainLoop(thread_context, false); - thread_loop.run(); - thread_context.pop_thread_default(); - return null; - }); - - if (turn_ip != null) { - for (uint8 component_id = 1; component_id <= components; component_id++) { - agent.set_relay_info(stream_id, component_id, turn_ip, turn_service.port, turn_service.username, turn_service.password, Nice.RelayType.UDP); - debug("TURN info (component %i) %s:%u", component_id, turn_ip, turn_service.port); - } - } - string ufrag; - string pwd; - agent.get_local_credentials(stream_id, out ufrag, out pwd); - init(ufrag, pwd); - - for (uint8 component_id = 1; component_id <= components; component_id++) { - // We don't properly get local candidates before this call - agent.attach_recv(stream_id, component_id, thread_context, on_recv); - } - - agent.gather_candidates(stream_id); - } - - private static DtlsSrtp.Handler setup_dtls(TransportParameters tp, DtlsSrtp.CredentialsCapsule credentials) { - var weak_self = WeakRef(tp); - DtlsSrtp.Handler dtls_srtp = new DtlsSrtp.Handler.with_cert(credentials); - 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); - - for (uint8 i = 1; i <= components; i++) { - foreach (unowned Nice.Candidate nc in agent.get_local_candidates(stream_id, i)) { - if (nc.transport == Nice.CandidateTransport.UDP) { - JingleIceUdp.Candidate? candidate = candidate_to_jingle(nc); - if (candidate == null) continue; - debug("Local candidate summary: %s", agent.generate_local_candidate_sdp(nc)); - } - } - } - } - - private void on_new_candidate(Nice.Candidate nc) { - if (nc.stream_id != stream_id) return; - JingleIceUdp.Candidate? candidate = candidate_to_jingle(nc); - if (candidate == null) return; - - if (nc.transport == Nice.CandidateTransport.UDP) { - // Execution was in the agent thread before - add_local_candidate_threadsafe(candidate); - } - } - - private bool bytes_equal(uint8[] a1, uint8[] a2) { - return a1.length == a2.length && Memory.cmp(a1, a2, a1.length) == 0; - } - - public override void handle_transport_accept(StanzaNode transport) throws Jingle.IqError { - debug("on_transport_accept from %s", peer_full_jid.to_string()); - base.handle_transport_accept(transport); - - if (dtls_srtp_handler != null && peer_fingerprint != null) { - if (dtls_srtp_handler.peer_fingerprint != null) { - if (!bytes_equal(dtls_srtp_handler.peer_fingerprint, peer_fingerprint)) { - warning("Tried to replace certificate fingerprint mid use. We don't allow that."); - peer_fingerprint = dtls_srtp_handler.peer_fingerprint; - peer_fp_algo = dtls_srtp_handler.peer_fp_algo; - } - } else { - dtls_srtp_handler.peer_fingerprint = peer_fingerprint; - dtls_srtp_handler.peer_fp_algo = peer_fp_algo; - } - if (peer_setup == "passive") { - dtls_srtp_handler.mode = DtlsSrtp.Mode.CLIENT; - dtls_srtp_handler.stop_dtls_connection(); - dtls_srtp_handler.setup_dtls_connection.begin((_, res) => { - var content_encryption = dtls_srtp_handler.setup_dtls_connection.end(res); - if (content_encryption != null) { - this.content.encryptions[content_encryption.encryption_ns] = content_encryption; - } - }); - } - } else { - dtls_srtp_handler = null; - } - } - - public override void handle_transport_info(StanzaNode transport) throws Jingle.IqError { - debug("on_transport_info from %s", peer_full_jid.to_string()); - base.handle_transport_info(transport); - - if (dtls_srtp_handler != null && peer_fingerprint != null) { - if (dtls_srtp_handler.peer_fingerprint != null) { - if (!bytes_equal(dtls_srtp_handler.peer_fingerprint, peer_fingerprint)) { - warning("Tried to replace certificate fingerprint mid use. We don't allow that."); - peer_fingerprint = dtls_srtp_handler.peer_fingerprint; - peer_fp_algo = dtls_srtp_handler.peer_fp_algo; - } - } else { - dtls_srtp_handler.peer_fingerprint = peer_fingerprint; - dtls_srtp_handler.peer_fp_algo = peer_fp_algo; - } - } - - if (!we_want_connection) return; - - if (remote_ufrag != null && remote_pwd != null && !remote_credentials_set) { - agent.set_remote_credentials(stream_id, remote_ufrag, remote_pwd); - remote_credentials_set = true; - } - for (uint8 i = 1; i <= components; i++) { - SList candidates = new SList(); - foreach (JingleIceUdp.Candidate candidate in remote_candidates) { - if (candidate.component == i) { - candidates.append(candidate_to_nice(candidate)); - } - } - int new_candidates = agent.set_remote_candidates(stream_id, i, candidates); - debug("Updated to %i remote candidates for candidate %u via transport info", new_candidates, i); - } - } - - public override void create_transport_connection(XmppStream stream, Jingle.Content content) { - debug("create_transport_connection: %s", content.session.sid); - debug("local_credentials: %s %s", local_ufrag, local_pwd); - debug("remote_credentials: %s %s", remote_ufrag, remote_pwd); - debug("expected incoming credentials: %s %s", local_ufrag + ":" + remote_ufrag, local_pwd); - debug("expected outgoing credentials: %s %s", remote_ufrag + ":" + local_ufrag, remote_pwd); - - we_want_connection = true; - - if (remote_ufrag != null && remote_pwd != null && !remote_credentials_set) { - agent.set_remote_credentials(stream_id, remote_ufrag, remote_pwd); - remote_credentials_set = true; - } - for (uint8 i = 1; i <= components; i++) { - SList candidates = new SList(); - foreach (JingleIceUdp.Candidate candidate in remote_candidates) { - if (candidate.ip.has_prefix("fe80::")) continue; - if (candidate.component == i) { - candidates.append(candidate_to_nice(candidate)); - debug("remote candidate: %s", agent.generate_local_candidate_sdp(candidate_to_nice(candidate))); - } - } - int new_candidates = agent.set_remote_candidates(stream_id, i, candidates); - debug("Initiated component %u with %i remote candidates", i, new_candidates); - - connections[i] = new DatagramConnection(agent, dtls_srtp_handler, stream_id, i); - content.set_transport_connection(connections[i], i); - } - - base.create_transport_connection(stream, content); - } - - private void on_component_state_changed(uint stream_id, uint component_id, uint state) { - if (stream_id != this.stream_id) return; - debug("stream %u component %u state changed to %s", stream_id, component_id, agent.get_component_state(stream_id, component_id).to_string()); - may_consider_ready(stream_id, component_id); - if (incoming && dtls_srtp_handler != null && !dtls_srtp_handler.ready && is_component_ready(agent, stream_id, component_id) && dtls_srtp_handler.mode == DtlsSrtp.Mode.CLIENT) { - dtls_srtp_handler.setup_dtls_connection.begin((_, res) => { - Jingle.ContentEncryption? encryption = dtls_srtp_handler.setup_dtls_connection.end(res); - if (encryption != null) { - this.content.encryptions[encryption.encryption_ns] = encryption; - } - }); - } - } - - private void may_consider_ready(uint stream_id, uint component_id) { - if (stream_id != this.stream_id) return; - if (connections.has_key((uint8) component_id) && !connections[(uint8)component_id].ready && is_component_ready(agent, stream_id, component_id) && (dtls_srtp_handler == null || dtls_srtp_handler.ready)) { - connections[(uint8)component_id].ready = true; - } - } - - private void on_initial_binding_request_received(uint stream_id) { - if (stream_id != this.stream_id) return; - debug("initial_binding_request_received"); - } - - private void on_new_selected_pair_full(uint stream_id, uint component_id, Nice.Candidate p1, Nice.Candidate p2) { - if (stream_id != this.stream_id) return; - debug("new_selected_pair_full %u [%s, %s]", component_id, agent.generate_local_candidate_sdp(p1), agent.generate_local_candidate_sdp(p2)); - } - - private void on_recv(Nice.Agent agent, uint stream_id, uint component_id, uint8[] data) { - if (stream_id != this.stream_id) return; - uint8[] decrypt_data = null; - if (dtls_srtp_handler != null) { - try { - decrypt_data = dtls_srtp_handler.process_incoming_data(component_id, data); - if (decrypt_data == null) return; - } catch (Crypto.Error e) { - warning("%s while on_recv stream %u component %u", e.message, stream_id, component_id); - return; - } - } - may_consider_ready(stream_id, component_id); - if (connections.has_key((uint8) component_id)) { - if (!connections[(uint8) component_id].ready) { - debug("on_recv stream %u component %u when state %s", stream_id, component_id, agent.get_component_state(stream_id, component_id).to_string()); - } - connections[(uint8) component_id].datagram_received(new Bytes(decrypt_data ?? data)); - } else { - debug("on_recv stream %u component %u length %u", stream_id, component_id, data.length); - } - } - - private static Nice.Candidate candidate_to_nice(JingleIceUdp.Candidate c) { - Nice.CandidateType type; - switch (c.type_) { - case JingleIceUdp.Candidate.Type.HOST: type = Nice.CandidateType.HOST; break; - case JingleIceUdp.Candidate.Type.PRFLX: type = Nice.CandidateType.PEER_REFLEXIVE; break; - case JingleIceUdp.Candidate.Type.RELAY: type = Nice.CandidateType.RELAYED; break; - case JingleIceUdp.Candidate.Type.SRFLX: type = Nice.CandidateType.SERVER_REFLEXIVE; break; - default: assert_not_reached(); - } - - Nice.Candidate candidate = new Nice.Candidate(type); - candidate.component_id = c.component; - char[] foundation = new char[Nice.CANDIDATE_MAX_FOUNDATION]; - Memory.copy(foundation, c.foundation.data, size_t.min(c.foundation.length, Nice.CANDIDATE_MAX_FOUNDATION - 1)); - candidate.foundation = foundation; - candidate.addr = Nice.Address(); - candidate.addr.init(); - candidate.addr.set_from_string(c.ip); - candidate.addr.set_port(c.port); - candidate.priority = c.priority; - if (c.rel_addr != null) { - candidate.base_addr = Nice.Address(); - candidate.base_addr.init(); - candidate.base_addr.set_from_string(c.rel_addr); - candidate.base_addr.set_port(c.rel_port); - } - candidate.transport = Nice.CandidateTransport.UDP; - return candidate; - } - - private static JingleIceUdp.Candidate? candidate_to_jingle(Nice.Candidate nc) { - JingleIceUdp.Candidate candidate = new JingleIceUdp.Candidate(); - switch (nc.type) { - case Nice.CandidateType.HOST: candidate.type_ = JingleIceUdp.Candidate.Type.HOST; break; - case Nice.CandidateType.PEER_REFLEXIVE: candidate.type_ = JingleIceUdp.Candidate.Type.PRFLX; break; - case Nice.CandidateType.RELAYED: candidate.type_ = JingleIceUdp.Candidate.Type.RELAY; break; - case Nice.CandidateType.SERVER_REFLEXIVE: candidate.type_ = JingleIceUdp.Candidate.Type.SRFLX; break; - default: assert_not_reached(); - } - candidate.component = (uint8) nc.component_id; - candidate.foundation = ((string)nc.foundation).dup(); - candidate.generation = 0; - candidate.id = Random.next_int().to_string("%08x"); // TODO - - char[] res = new char[NICE_ADDRESS_STRING_LEN]; - nc.addr.to_string(res); - candidate.ip = (string) res; - candidate.network = 0; // TODO - candidate.port = (uint16) nc.addr.get_port(); - candidate.priority = nc.priority; - candidate.protocol = "udp"; - if (nc.base_addr.is_valid() && !nc.base_addr.equal(nc.addr)) { - res = new char[NICE_ADDRESS_STRING_LEN]; - nc.base_addr.to_string(res); - candidate.rel_addr = (string) res; - candidate.rel_port = (uint16) nc.base_addr.get_port(); - } - if (candidate.ip.has_prefix("fe80::")) return null; - - return candidate; - } - - public override void dispose() { - base.dispose(); - agent = null; - dtls_srtp_handler = null; - connections.clear(); - if (thread_loop != null) { - thread_loop.quit(); - } - } -} diff --git a/plugins/ice/src/util.vala b/plugins/ice/src/util.vala deleted file mode 100644 index dd89d2f4..00000000 --- a/plugins/ice/src/util.vala +++ /dev/null @@ -1,18 +0,0 @@ -using Gee; - -namespace Dino.Plugins.Ice { - -internal static bool is_component_ready(Nice.Agent agent, uint stream_id, uint component_id) { - var state = agent.get_component_state(stream_id, component_id); - return state == Nice.ComponentState.CONNECTED || state == Nice.ComponentState.READY; -} - -internal Gee.List get_local_ip_addresses() { - Gee.List result = new ArrayList(); - foreach (string ip_address in Nice.interfaces_get_local_ips(false)) { - result.add(ip_address); - } - return result; -} - -} \ No newline at end of file diff --git a/plugins/ice/vapi/metadata/Nice-0.1.metadata b/plugins/ice/vapi/metadata/Nice-0.1.metadata deleted file mode 100644 index 7fcf046a..00000000 --- a/plugins/ice/vapi/metadata/Nice-0.1.metadata +++ /dev/null @@ -1,11 +0,0 @@ -Nice cheader_filename="nice.h" -Address.to_string.dst type="char[]" -Agent.new_reliable#constructor name="create_reliable" -Agent.attach_recv skip=false -Agent.send.buf type="uint8[]" array_length_idx=2 -AgentRecvFunc.buf type="uint8[]" array_length_idx=3 -PseudoTcpCallbacks#record skip -PseudoTcpSocket#class skip - -# Not yet supported by vapigen -# Candidate copy_function="nice_candidate_copy" free_function="nice_candidate_free" type_id="" diff --git a/plugins/ice/vapi/nice.vapi b/plugins/ice/vapi/nice.vapi deleted file mode 100644 index 540e2b4e..00000000 --- a/plugins/ice/vapi/nice.vapi +++ /dev/null @@ -1,386 +0,0 @@ -/* nice.vapi generated by vapigen, do not modify. */ - -[CCode (cprefix = "Nice", gir_namespace = "Nice", gir_version = "0.1", lower_case_cprefix = "nice_")] -namespace Nice { - [CCode (cheader_filename = "nice.h", type_id = "nice_agent_get_type ()")] - public class Agent : GLib.Object { - [CCode (has_construct_function = false)] - public Agent (GLib.MainContext ctx, Nice.Compatibility compat); - public bool add_local_address (Nice.Address addr); - public uint add_stream (uint n_components); - public bool attach_recv (uint stream_id, uint component_id, GLib.MainContext ctx, Nice.AgentRecvFunc func); - [Version (since = "0.1.16")] - public async void close_async (); - [CCode (cname = "nice_agent_new_reliable", has_construct_function = false)] - [Version (since = "0.0.11")] - public Agent.create_reliable (GLib.MainContext ctx, Nice.Compatibility compat); - [Version (since = "0.1.6")] - public bool forget_relays (uint stream_id, uint component_id); - [CCode (has_construct_function = false)] - [Version (since = "0.1.15")] - public Agent.full (GLib.MainContext ctx, Nice.Compatibility compat, Nice.AgentOption flags); - public bool gather_candidates (uint stream_id); - [Version (since = "0.1.4")] - public string generate_local_candidate_sdp (Nice.Candidate candidate); - [Version (since = "0.1.4")] - public string generate_local_sdp (); - [Version (since = "0.1.4")] - public string generate_local_stream_sdp (uint stream_id, bool include_non_ice); - [Version (since = "0.1.8")] - public Nice.ComponentState get_component_state (uint stream_id, uint component_id); - public Nice.Candidate get_default_local_candidate (uint stream_id, uint component_id); - [Version (since = "0.1.5")] - public GLib.IOStream get_io_stream (uint stream_id, uint component_id); - public GLib.SList get_local_candidates (uint stream_id, uint component_id); - public bool get_local_credentials (uint stream_id, out string ufrag, out string pwd); - public GLib.SList get_remote_candidates (uint stream_id, uint component_id); - public bool get_selected_pair (uint stream_id, uint component_id, Nice.Candidate local, Nice.Candidate remote); - [Version (since = "0.1.5")] - public GLib.Socket? get_selected_socket (uint stream_id, uint component_id); - [Version (since = "0.1.4")] - public unowned string get_stream_name (uint stream_id); - [Version (since = "0.1.4")] - public Nice.Candidate parse_remote_candidate_sdp (uint stream_id, string sdp); - [Version (since = "0.1.4")] - public int parse_remote_sdp (string sdp); - [Version (since = "0.1.4")] - public GLib.SList parse_remote_stream_sdp (uint stream_id, string sdp, string ufrag, string pwd); - [Version (since = "0.1.16")] - public bool peer_candidate_gathering_done (uint stream_id); - [Version (since = "0.1.5")] - public ssize_t recv (uint stream_id, uint component_id, [CCode (array_length_cname = "buf_len", array_length_pos = 3.5, array_length_type = "gsize")] out unowned uint8[] buf, GLib.Cancellable? cancellable = null) throws GLib.Error; - [Version (since = "0.1.5")] - public int recv_messages (uint stream_id, uint component_id, [CCode (array_length_cname = "n_messages", array_length_pos = 3.5, array_length_type = "guint")] out unowned Nice.InputMessage[] messages, GLib.Cancellable? cancellable = null) throws GLib.Error; - [Version (since = "0.1.5")] - public int recv_messages_nonblocking (uint stream_id, uint component_id, [CCode (array_length_cname = "n_messages", array_length_pos = 3.5, array_length_type = "guint")] out unowned Nice.InputMessage[] messages, GLib.Cancellable? cancellable = null) throws GLib.Error; - [Version (since = "0.1.5")] - public ssize_t recv_nonblocking (uint stream_id, uint component_id, [CCode (array_length_cname = "buf_len", array_length_pos = 3.5, array_length_type = "gsize")] out unowned uint8[] buf, GLib.Cancellable? cancellable = null) throws GLib.Error; - public void remove_stream (uint stream_id); - public bool restart (); - [Version (since = "0.1.6")] - public bool restart_stream (uint stream_id); - public int send (uint stream_id, uint component_id, [CCode (array_length_cname = "len", array_length_pos = 2.5, array_length_type = "guint", type = "const gchar*")] uint8[] buf); - [Version (since = "0.1.5")] - public int send_messages_nonblocking (uint stream_id, uint component_id, [CCode (array_length_cname = "n_messages", array_length_pos = 3.5, array_length_type = "guint")] Nice.OutputMessage[] messages, GLib.Cancellable? cancellable = null) throws GLib.Error; - public bool set_local_credentials (uint stream_id, string ufrag, string pwd); - public void set_port_range (uint stream_id, uint component_id, uint min_port, uint max_port); - public bool set_relay_info (uint stream_id, uint component_id, string server_ip, uint server_port, string username, string password, Nice.RelayType type); - public int set_remote_candidates (uint stream_id, uint component_id, GLib.SList candidates); - public bool set_remote_credentials (uint stream_id, string ufrag, string pwd); - public bool set_selected_pair (uint stream_id, uint component_id, string lfoundation, string rfoundation); - public bool set_selected_remote_candidate (uint stream_id, uint component_id, Nice.Candidate candidate); - [Version (since = "0.0.10")] - public void set_software (string software); - [Version (since = "0.1.4")] - public bool set_stream_name (uint stream_id, string name); - [Version (since = "0.0.9")] - public void set_stream_tos (uint stream_id, int tos); - [NoAccessorMethod] - [Version (since = "0.1.8")] - public bool bytestream_tcp { get; } - [NoAccessorMethod] - public uint compatibility { get; construct; } - [NoAccessorMethod] - public bool controlling_mode { get; set; } - [NoAccessorMethod] - [Version (since = "0.1.14")] - public bool force_relay { get; set; } - [NoAccessorMethod] - public bool full_mode { get; construct; } - [NoAccessorMethod] - [Version (since = "0.1.8")] - public bool ice_tcp { get; set; } - [NoAccessorMethod] - [Version (since = "0.1.16")] - public bool ice_trickle { get; set; } - [NoAccessorMethod] - [Version (since = "0.1.8")] - public bool ice_udp { get; set; } - [NoAccessorMethod] - [Version (since = "0.1.8")] - public bool keepalive_conncheck { get; set; } - [NoAccessorMethod] - public void* main_context { get; construct; } - [NoAccessorMethod] - public uint max_connectivity_checks { get; set; } - [NoAccessorMethod] - [Version (since = "0.0.4")] - public string proxy_ip { owned get; set; } - [NoAccessorMethod] - [Version (since = "0.0.4")] - public string proxy_password { owned get; set; } - [NoAccessorMethod] - [Version (since = "0.0.4")] - public uint proxy_port { get; set; } - [NoAccessorMethod] - [Version (since = "0.0.4")] - public uint proxy_type { get; set; } - [NoAccessorMethod] - [Version (since = "0.0.4")] - public string proxy_username { owned get; set; } - [NoAccessorMethod] - [Version (since = "0.0.11")] - public bool reliable { get; construct; } - [NoAccessorMethod] - [Version (since = "0.1.15")] - public uint stun_initial_timeout { get; set construct; } - [NoAccessorMethod] - [Version (since = "0.1.15")] - public uint stun_max_retransmissions { get; set construct; } - [NoAccessorMethod] - public uint stun_pacing_timer { get; set construct; } - [NoAccessorMethod] - [Version (since = "0.1.15")] - public uint stun_reliable_timeout { get; set construct; } - [NoAccessorMethod] - public string stun_server { owned get; set; } - [NoAccessorMethod] - public uint stun_server_port { get; set; } - [NoAccessorMethod] - public bool support_renomination { get; set; } - [NoAccessorMethod] - [Version (since = "0.0.7")] - public bool upnp { get; set construct; } - [NoAccessorMethod] - [Version (since = "0.0.7")] - public uint upnp_timeout { get; set construct; } - public signal void candidate_gathering_done (uint stream_id); - public signal void component_state_changed (uint stream_id, uint component_id, uint state); - public signal void initial_binding_request_received (uint stream_id); - [Version (deprecated = true, deprecated_since = "0.1.8")] - public signal void new_candidate (uint stream_id, uint component_id, string foundation); - [Version (since = "0.1.8")] - public signal void new_candidate_full (Nice.Candidate candidate); - [Version (deprecated = true, deprecated_since = "0.1.8")] - public signal void new_remote_candidate (uint stream_id, uint component_id, string foundation); - [Version (since = "0.1.8")] - public signal void new_remote_candidate_full (Nice.Candidate candidate); - [Version (deprecated = true, deprecated_since = "0.1.8")] - public signal void new_selected_pair (uint stream_id, uint component_id, string lfoundation, string rfoundation); - [Version (since = "0.1.8")] - public signal void new_selected_pair_full (uint stream_id, uint component_id, Nice.Candidate lcandidate, Nice.Candidate rcandidate); - [Version (since = "0.0.11")] - public signal void reliable_transport_writable (uint stream_id, uint component_id); - [Version (since = "0.1.5")] - public signal void streams_removed ([CCode (array_length = false, array_null_terminated = true)] uint[] stream_ids); - } - [CCode (cheader_filename = "nice.h", copy_function = "nice_candidate_copy", free_function = "nice_candidate_free")] - [Compact] - public class Candidate { - public Nice.Address addr; - public Nice.Address base_addr; - public uint component_id; - [CCode (array_length = false)] - public weak char foundation[33]; - public weak string password; - public uint32 priority; - public void* sockptr; - public uint stream_id; - public Nice.CandidateTransport transport; - public Nice.TurnServer turn; - public Nice.CandidateType type; - public weak string username; - [CCode (has_construct_function = false)] - public Candidate (Nice.CandidateType type); - public Nice.Candidate copy (); - [Version (since = "0.1.15")] - public bool equal_target (Nice.Candidate candidate2); - public void free (); - } - [CCode (cheader_filename = "nice.h", has_type_id = false)] - public struct Address { - [CCode (cname = "s.addr")] - public void* s_addr; - [CCode (cname = "s.ip4")] - public void* s_ip4; - [CCode (cname = "s.ip6")] - public void* s_ip6; - public void copy_to_sockaddr (void* sin); - public bool equal (Nice.Address b); - [Version (since = "0.1.8")] - public bool equal_no_port (Nice.Address b); - public void free (); - public uint get_port (); - public void init (); - public int ip_version (); - public bool is_private (); - public bool is_valid (); - public void set_from_sockaddr (void* sin); - public bool set_from_string (string str); - public void set_ipv4 (uint32 addr_ipv4); - public void set_ipv6 (uint8 addr_ipv6); - public void set_port (uint port); - public void to_string ([CCode (array_length = false, type = "gchar*")] char[] dst); - } - [CCode (cheader_filename = "nice.h", has_type_id = false)] - [Version (since = "0.1.5")] - public struct InputMessage { - [CCode (array_length_cname = "n_buffers")] - public weak GLib.InputVector[] buffers; - public int n_buffers; - public Nice.Address from; - public size_t length; - } - [CCode (cheader_filename = "nice.h", has_type_id = false)] - [Version (since = "0.1.5")] - public struct OutputMessage { - [CCode (array_length_cname = "n_buffers")] - public weak GLib.OutputVector[] buffers; - public int n_buffers; - } - [CCode (cheader_filename = "nice.h", cname = "TurnServer", has_type_id = false)] - public struct TurnServer { - public int ref_count; - public Nice.Address server; - public weak string username; - public weak string password; - public Nice.RelayType type; - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_AGENT_OPTION_", has_type_id = false)] - [Flags] - [Version (since = "0.1.15")] - public enum AgentOption { - REGULAR_NOMINATION, - RELIABLE, - LITE_MODE, - ICE_TRICKLE, - SUPPORT_RENOMINATION - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_CANDIDATE_TRANSPORT_", has_type_id = false)] - public enum CandidateTransport { - UDP, - TCP_ACTIVE, - TCP_PASSIVE, - TCP_SO - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_CANDIDATE_TYPE_", has_type_id = false)] - public enum CandidateType { - HOST, - SERVER_REFLEXIVE, - PEER_REFLEXIVE, - RELAYED - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_COMPATIBILITY_", has_type_id = false)] - public enum Compatibility { - RFC5245, - DRAFT19, - GOOGLE, - MSN, - WLM2009, - OC2007, - OC2007R2, - LAST - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_COMPONENT_STATE_", has_type_id = false)] - public enum ComponentState { - DISCONNECTED, - GATHERING, - CONNECTING, - CONNECTED, - READY, - FAILED, - LAST; - [Version (since = "0.1.6")] - public unowned string to_string (); - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_COMPONENT_TYPE_", has_type_id = false)] - public enum ComponentType { - RTP, - RTCP - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_NOMINATION_MODE_", has_type_id = false)] - [Version (since = "0.1.15")] - public enum NominationMode { - REGULAR, - AGGRESSIVE - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_PROXY_TYPE_", has_type_id = false)] - [Version (since = "0.0.4")] - public enum ProxyType { - NONE, - SOCKS5, - HTTP, - LAST - } - [CCode (cheader_filename = "nice.h", cname = "PseudoTcpDebugLevel", cprefix = "PSEUDO_TCP_DEBUG_", has_type_id = false)] - [Version (since = "0.0.11")] - public enum PseudoTcpDebugLevel { - NONE, - NORMAL, - VERBOSE - } - [CCode (cheader_filename = "nice.h", cname = "PseudoTcpShutdown", cprefix = "PSEUDO_TCP_SHUTDOWN_", has_type_id = false)] - [Version (since = "0.1.8")] - public enum PseudoTcpShutdown { - RD, - WR, - RDWR - } - [CCode (cheader_filename = "nice.h", cname = "PseudoTcpState", cprefix = "PSEUDO_TCP_", has_type_id = false)] - [Version (since = "0.0.11")] - public enum PseudoTcpState { - LISTEN, - SYN_SENT, - SYN_RECEIVED, - ESTABLISHED, - CLOSED, - FIN_WAIT_1, - FIN_WAIT_2, - CLOSING, - TIME_WAIT, - CLOSE_WAIT, - LAST_ACK - } - [CCode (cheader_filename = "nice.h", cname = "PseudoTcpWriteResult", cprefix = "WR_", has_type_id = false)] - [Version (since = "0.0.11")] - public enum PseudoTcpWriteResult { - SUCCESS, - TOO_LARGE, - FAIL - } - [CCode (cheader_filename = "nice.h", cprefix = "NICE_RELAY_TYPE_TURN_", has_type_id = false)] - public enum RelayType { - UDP, - TCP, - TLS - } - [CCode (cheader_filename = "nice.h", instance_pos = 4.9)] - public delegate void AgentRecvFunc (Nice.Agent agent, uint stream_id, uint component_id, [CCode (array_length_cname = "len", array_length_pos = 3.5, array_length_type = "guint", type = "gchar*")] uint8[] buf); - [CCode (cheader_filename = "nice.h", cname = "NICE_AGENT_MAX_REMOTE_CANDIDATES")] - public const int AGENT_MAX_REMOTE_CANDIDATES; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_DIRECTION_MS_PREF_ACTIVE")] - public const int CANDIDATE_DIRECTION_MS_PREF_ACTIVE; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_DIRECTION_MS_PREF_PASSIVE")] - public const int CANDIDATE_DIRECTION_MS_PREF_PASSIVE; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_MAX_FOUNDATION")] - public const int CANDIDATE_MAX_FOUNDATION; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_TRANSPORT_MS_PREF_TCP")] - public const int CANDIDATE_TRANSPORT_MS_PREF_TCP; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_TRANSPORT_MS_PREF_UDP")] - public const int CANDIDATE_TRANSPORT_MS_PREF_UDP; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_TYPE_PREF_HOST")] - public const int CANDIDATE_TYPE_PREF_HOST; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_TYPE_PREF_NAT_ASSISTED")] - public const int CANDIDATE_TYPE_PREF_NAT_ASSISTED; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_TYPE_PREF_PEER_REFLEXIVE")] - public const int CANDIDATE_TYPE_PREF_PEER_REFLEXIVE; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_TYPE_PREF_RELAYED")] - public const int CANDIDATE_TYPE_PREF_RELAYED; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_TYPE_PREF_RELAYED_UDP")] - public const int CANDIDATE_TYPE_PREF_RELAYED_UDP; - [CCode (cheader_filename = "nice.h", cname = "NICE_CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE")] - public const int CANDIDATE_TYPE_PREF_SERVER_REFLEXIVE; - [CCode (cheader_filename = "nice.h")] - public static void debug_disable (bool with_stun); - [CCode (cheader_filename = "nice.h")] - public static void debug_enable (bool with_stun); - [CCode (cheader_filename = "nice.h")] - public static string? interfaces_get_ip_for_interface (string interface_name); - [CCode (cheader_filename = "nice.h")] - public static GLib.List interfaces_get_local_interfaces (); - [CCode (cheader_filename = "nice.h")] - public static GLib.List interfaces_get_local_ips (bool include_loopback); - [CCode (cheader_filename = "nice.h", cname = "pseudo_tcp_set_debug_level")] - [Version (since = "0.0.11")] - public static void pseudo_tcp_set_debug_level (Nice.PseudoTcpDebugLevel level); -} -- cgit v1.3