aboutsummaryrefslogtreecommitdiff
path: root/plugins/ice/src
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2024-09-22 11:09:25 +0100
committerfiaxh <git@lightrise.org>2024-09-22 11:39:13 +0100
commit3a4ac7c11d93553a485aa7dec9be05d71a7c9cb6 (patch)
tree6f9af16cea0f112624e2ff45e274d85f5033624a /plugins/ice/src
parent63439cd206aaf3548228e915bd1744389cd2fc54 (diff)
downloaddino-3a4ac7c11d93553a485aa7dec9be05d71a7c9cb6.tar.gz
dino-3a4ac7c11d93553a485aa7dec9be05d71a7c9cb6.zip
XEP-0215: Remove timeout from previous connection
Diffstat (limited to 'plugins/ice/src')
-rw-r--r--plugins/ice/src/plugin.vala22
1 files changed, 15 insertions, 7 deletions
diff --git a/plugins/ice/src/plugin.vala b/plugins/ice/src/plugin.vala
index 17090d26..d1655a74 100644
--- a/plugins/ice/src/plugin.vala
+++ b/plugins/ice/src/plugin.vala
@@ -6,6 +6,8 @@ using Xmpp.Xep;
private extern const size_t NICE_ADDRESS_STRING_LEN;
public class Dino.Plugins.Ice.Plugin : RootInterface, Object {
+ private HashMap<Account, uint> timeouts = new HashMap<Account, uint>(Account.hash_func, Account.equals_func);
+
public Dino.Application app;
public void registered(Dino.Application app) {
@@ -28,6 +30,7 @@ public class Dino.Plugins.Ice.Plugin : RootInterface, Object {
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);
foreach (Xep.ExternalServiceDiscovery.Service service in services) {
if (service.transport == "udp" && (service.ty == "stun" || service.ty == "turn")) {
@@ -60,18 +63,23 @@ public class Dino.Plugins.Ice.Plugin : RootInterface, Object {
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 delay = (uint) (expires.to_unix() - new DateTime.now_utc().to_unix()) / 2;
+ uint refresh_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);
+ if (refresh_delay >= 300 && refresh_delay <= (int64) uint.MAX) { // 5 min < refetch < max
+ debug("Re-fetching TURN credentials in %u sec", refresh_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;
- });
+ 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);
+ }
}
}
}