Software /
code /
prosody
Annotate
plugins/mod_turn_external.lua @ 11694:d6be4dda1f60
net.server_epoll: Set minimum wait time to 1ms, matching epoll
A timeout value less than 0.001 gets turned into zero on the C side, so
epoll_wait() returns instantly and essentially busy-loops up to 1ms,
e.g. when a timer event ends up scheduled (0, 0.001)ms into the future.
Unsure if this has much effect in practice, but it may waste a small
amount of CPU time. How much would depend on how often this ends up
happening and how fast the CPU gets trough main loop iterations.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 15 Jul 2021 01:38:44 +0200 |
parent | 11599:ed405b6357a8 |
child | 12282:fe5a87b5972f |
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 |