Annotate

plugins/mod_turn_external.lua @ 11685:247561bf6fca

net.server_epoll: Log failures to set socket options Good to know if it fails, especially since the return value doesn't seem to be checked anywhere. Since LuaSec-wrapped sockets don't expose the setoption method, this will likely show when mod_c2s tries to enable keepalives on direct tls connections.
author Kim Alvefur <zash@zash.se>
date Wed, 14 Jul 2021 22:04:23 +0200
parent 11599:ed405b6357a8
child 12282:fe5a87b5972f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11599
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local secret = module:get_option_string("turn_external_secret");
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local host = module:get_option_string("turn_external_host", module.host);
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local user = module:get_option_string("turn_external_user");
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local port = module:get_option_number("turn_external_port", 3478);
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local ttl = module:get_option_number("turn_external_ttl", 86400);
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local services = module:get_option_set("turn_external_services", {"stun-udp"; "turn-udp"});
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 if not secret then error("mod_" .. module.name .. " requires that 'turn_external_secret' be set") end
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 module:depends "external_services";
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 for _, type in ipairs({"stun"; "turn"}) do
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 for _, transport in ipairs({"udp"; "tcp"}) do
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 if services:contains(type .. "-" .. transport) then
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 module:add_item("external_service", {
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 type = type;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 transport = transport;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 host = host;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 port = port;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 username = type == "turn" and user or nil;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 secret = type == "turn" and secret or nil;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 ttl = type == "turn" and ttl or nil;
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 })
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
ed405b6357a8 mod_turn_external: Simple module to offer TURN(+STUN) via mod_external_services
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end