aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorAlexandre Jousset <mid@gtmp.org>2023-11-12 13:58:01 +0100
committerfiaxh <git@lightrise.org>2024-09-22 11:39:13 +0100
commit63439cd206aaf3548228e915bd1744389cd2fc54 (patch)
tree54e8c8b5045bab2bcd353ef4eb069cd852b2bf7c /plugins
parenta7f7b1ceeb78533d1c5856ed2f2adaf0bf386340 (diff)
downloaddino-63439cd206aaf3548228e915bd1744389cd2fc54.tar.gz
dino-63439cd206aaf3548228e915bd1744389cd2fc54.zip
XEP-0215: management of the field `expires`
Add a field in `Xmpp.Xep.ExternalServiceDiscovery` to keep track of the `expires` TURN service value and use it (divided by 2) to restart periodically the external services discovery.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/ice/src/plugin.vala19
1 files changed, 17 insertions, 2 deletions
diff --git a/plugins/ice/src/plugin.vala b/plugins/ice/src/plugin.vala
index ec4fe9cb..17090d26 100644
--- a/plugins/ice/src/plugin.vala
+++ b/plugins/ice/src/plugin.vala
@@ -22,10 +22,10 @@ public class Dino.Plugins.Ice.Plugin : RootInterface, Object {
stream.get_module(JingleRawUdp.Module.IDENTITY).set_local_ip_address_handler(get_local_ip_addresses);
}
});
- app.stream_interactor.stream_negotiated.connect(on_stream_negotiated);
+ app.stream_interactor.stream_negotiated.connect(external_discovery_refresh_services);
}
- private async void on_stream_negotiated(Account account, XmppStream stream) {
+ 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<Xep.ExternalServiceDiscovery.Service> services = yield ExternalServiceDiscovery.request_services(stream);
@@ -59,6 +59,21 @@ public class Dino.Plugins.Ice.Plugin : RootInterface, Object {
ice_udp_module.stun_ip = ip.to_string();
ice_udp_module.stun_port = 7886;
}
+
+ if (ice_udp_module.turn_service != null) {
+ DateTime? expires = ice_udp_module.turn_service.expires;
+ if (expires != null) {
+ uint delay = (uint) (expires.to_unix() - new DateTime.now_utc().to_unix()) / 2;
+
+ debug("Next server external service discovery in %us (because of TURN credentials' expiring time)", delay);
+
+ Timeout.add_seconds(delay, () => {
+ if (app.stream_interactor.connection_manager.get_state(account) != ConnectionManager.ConnectionState.CONNECTED) return false;
+ on_stream_negotiated.begin(account, stream);
+ return false;
+ });
+ }
+ }
}
public void shutdown() {