1
0
mirror of https://github.com/coturn/coturn.git synced 2026-10-24 00:08:57 +03:00

51 Commits

Author SHA1 Message Date
Pavel Punsky
ac601f832d key OAuth MESSAGE-INTEGRITY with the whole mac_key (#2096)
RFC 7635 Section 6.2 keys HMAC-SHA1 MESSAGE-INTEGRITY with the token's
full 160-bit mac_key. The OAuth path went through the
long-term-credential helpers, which hash only get_hmackey_size(SHA1) =
16 bytes, so requests from RFC 7635 compliant clients failed with 401
and coturn's responses could not be verified by them. turnutils_uclient
shared the truncation, so the bundled client never noticed.

Add integrity helpers that take an explicit key length and use the whole
mac_key for OAuth sessions, both when checking requests (userdb and
check_stun_auth) and when signing responses. --oauth-legacy-mac-key on
turnserver (and on turnutils_uclient) restores the 16-byte truncation
for deployments that depend on it; the server logs a warning when it is
on. A mac_key whose last 4 bytes are zero hashes the same in both modes.

Fixes #2091 and #644

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 16:59:49 -07:00
Pavel Punsky
2ce03b8780 Add continuous latency mode to stunclient (#1937)
-c  Continuously send STUN binding requests and report round-trip latency until interrupted.

-i  Interval between continuous requests in milliseconds (Default: 1000).

-t  Response timeout in milliseconds (Default: 3000).
2026-06-09 23:21:14 -07:00
Pavel Punsky
e0c37a3aa0 Multiplexpeer (#1916)
## Summary

Adds **`--multiplex-peer`**, a non-standard relay mode that replaces the
per-allocation peer-side port bind with **one shared IPv4+IPv6 UDP
socket pair per relay thread**. Sessions are demultiplexed by exact peer
IP:port in a per-thread `mp_table`. This lifts the ~16 k allocation cap
that the default 49152-65535 relay port range imposes, and dramatically
reduces kernel-level UDP receive-buffer drops under high pps.

Design and trade-offs: [docs/multiplex-peer.md](docs/multiplex-peer.md).

## What changes

### Server (turnserver)

- **`--multiplex-peer`** (cross-platform) — enable the shared per-thread
relay sockets. Replaces the per-session port bind. Implies sendmmsg
batching on Linux and default-enables `--udp-recvmmsg` (override with
`--udp-recvmmsg=0`). Incompatible with EVEN-PORT — those Allocates are
rejected with 400.
- **`--multiplex-peer-port <port>`** (cross-platform, default 3480) —
base port; thread `i` binds `<base>+2i` (IPv4) and `<base>+2i+1` (IPv6).
A 4-thread server consumes 8 ports.
- **`--udp-gso`** (Linux-only CLI) — UDP-GSO (`UDP_SEGMENT` cmsg) on the
relay send path. Requires `--multiplex-peer` (which is what enables the
sendmmsg batching GSO piggybacks on); passing `--udp-gso` alone is a
silent no-op.
- **CLI surface tightened**: `--udp-recvmmsg`, `--udp-recvmmsg-log`,
`--udp-gso` and their fields are now `#if defined(__linux__)` — absent
from `--help`, rejected with `unrecognized option`, and the code paths
compile out on macOS/Windows.
- **Windows portability**: `SO_REUSEPORT` in `mp_open_socket` wrapped in
`#ifdef` (MSVC's Winsock doesn't define it; REUSEPORT was defensive
anyway because the per-thread port layout is unique by construction).
- **`--sock-buf-size` honoured at startup**: the shared multiplex-peer
relay socket now calls `set_ioa_socket_buf_size` in `mp_open_socket` so
the configured rcvbuf is in effect from the moment the socket exists,
not deferred to the first Allocate.

### turnutils_uclient (loadgen)

- **`--no-even-port`** — force `ep = -1` on Allocate. The default path
randomly attaches EVEN-PORT (with no-R bit) even under `-c`, which
`--multiplex-peer` strictly rejects with 400; this flag makes
alloc-flood runs against multiplex-peer deterministic.
- **Legacy `timer_handler` now wraps the per-tick send batch with
`uclient_send_batch_begin/_end`** — without this, runs with
`--sender-threads 0` (the default for `-m < 4`) silently fell through
every send to plain `send(2)`. strace A/B: 205 k `sendto` → 61 k
`sendmsg` (GSO) + 4 k `sendmmsg` + small `sendto` residual for control.

## Measured impact (3-droplet DigitalOcean, c-4 / 4 vCPU, 8 concurrent
UDP streams, 45 s)

| | baseline | `--udp-recvmmsg` | `--multiplex-peer` | `--multiplex-peer
--udp-gso` |
|---|---:|---:|---:|---:|
| Server NIC rx pps (UDP relay both legs) | 350 k | 334 k | 326 k | 294
k |
| Server `UdpInDatagrams` pps | 279 k | 292 k | 300 k | 294 k |
| **Server `UdpRcvbufErrors` pps** | **71 k** | 42 k | 26 k | **0.3 k
(−99.6 %)** |
| **`turnserver` process CPU** | **387 %** | 205 % | 283 % | **133 %
(−65 %)** |
| Server host idle | 22 % | 49 % | 41 % | **68 %** |

Same loadgen-side packet rate (~2 M pps reported by uclient `send_pps`
after the legacy-path batching fix). Iteration log:
[docs/PerformanceIterationLog.md](docs/PerformanceIterationLog.md).

## Test plan

- [x] `ctest --test-dir build` — 3/3 pass (test_ioaddr, test_stun_msg,
test_http_server) on macOS + Linux.
- [x] `examples/run_tests.sh` — 4 protocols + 4 threaded + load-gen
smoke on Linux; 4 protocols on macOS.
- [x] `examples/run_tests_conf.sh` — same coverage, conf-driven.
- [x] `examples/run_tests_multiplex_peer.sh` — UDP/TCP/TLS/DTLS via
`--multiplex-peer --multiplex-peer-port=35000` on macOS + Linux.
- [x] Flag matrix smoke on macOS: `--multiplex-peer`,
`--multiplex-peer-port=42000`, `--multiplex-peer --udp-gso` (no-op),
`uclient --no-even-port`, `uclient --listener-threads N --sender-threads
M` — all pass; `--udp-recvmmsg` / `--udp-gso` correctly rejected with
`unrecognized option`.
- [x] Flag matrix smoke on Linux (Docker): same + `--udp-recvmmsg`
accepted, `--multiplex-peer` auto-enables `--udp-recvmmsg`,
`--udp-recvmmsg=0` overrides the auto-enable.
- [x] Windows compile fix verified — `SO_REUSEPORT` no longer referenced
unconditionally.
- [x] 3-droplet perf matrix completed; per-hop UDP counters captured.

## Docs updated

- New: [docs/multiplex-peer.md](docs/multiplex-peer.md)
- [README.turnserver](README.turnserver): full entries for
`--multiplex-peer`, `--multiplex-peer-port`, `--udp-gso`; clarified
`--udp-recvmmsg` auto-enable semantics.
- [README.turnutils](README.turnutils): added `--no-even-port`, plus
previously-undocumented `--listener-threads` / `--sender-threads`
loadgen pool flags.
- [examples/etc/turnserver.conf](examples/etc/turnserver.conf):
commented `udp-recvmmsg`, `udp-recvmmsg-log`, `udp-gso`,
`multiplex-peer`, `multiplex-peer-port` keys with one-paragraph
descriptions and pointer to `docs/multiplex-peer.md`.
- Man pages regenerated via `./make-man.sh`.

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 19:16:55 -07:00
Pavel Punsky
69bc0e7351 Load generator mode in turnutils_uclient (#1894)
## Summary

Adds load-generator modes to `turnutils_uclient` for repeatable TURN
server performance testing:

- Adds `-Y packet|alloc|invalid` load modes.
- Supports packet flood, allocation flood, and invalid-packet flood
workflows.
- Adds unique local client ports for allocation flood mode.
- Removes default packet pacing in load-generator modes unless
explicitly set.
- Adds helper scripts under `examples/loadtest/`.
- Documents load-test usage in `README.turnutils`,
`man/man1/turnutils.1`, `CLAUDE.md`, and
`docs/PerformanceIterationLog.md`.

The performance log captures DigitalOcean benchmark methodology, A/B
lessons, hot-path findings, and future optimization candidates.
2026-05-03 22:03:08 -07:00
vuittont60
da6bc6b0c4 Fix typos (#1345) 2024-01-15 18:31:16 -08:00
Molly Miller
bc1678cc52 Regenerate manual pages from README files (#1117)
This PR fixes some typos and formatting, and regenerates the manual
pages from the README files. These changes were originally included in
#1105, however I've split them out into a separate PR as requested.
2022-12-06 17:04:13 -08:00
Pavel Punsky
22e51044cd Generate AUTHORS as Markdown, update references (#1102)
Refs #1049
2022-11-21 16:23:22 -08:00
Mészáros Mihály
08bb62ea88 Update README to fix #658 2020-12-08 13:40:49 +01:00
Paul Menzel
fa3f2797c2 README.*: Strip trailing spaces 2020-03-30 19:08:31 +02:00
Mészáros Mihály
d550dd200c replace email address 2018-09-27 22:09:10 +02:00
Oleg Moskalenko
a921f0ccc4 version bumped up and some spelling errors fixed 2017-12-11 23:24:54 -08:00
Mészáros Mihály
fee5442463 Update man and README according natdiscovery changes 2017-09-29 15:04:55 +02:00
Mészáros Mihály
8c38f1493b tidy 2017-09-29 14:53:41 +02:00
Mészáros Mihály
56da0bfee5 Add hairpinning natdiscovery to README and man 2017-09-29 14:53:41 +02:00
Mészáros Mihály
2848bbdda4 Add man collision 2017-09-29 14:49:00 +02:00
Oleg Moskalenko
8ca82f9055 typo fixed 2016-10-17 01:19:44 -07:00
Mészáros Mihály
82ca50ebb2 tidy and small improvments
* rename long-term-key to auth-key
 * add warning for auth key and token lifetime expiry or missmatch
 * tidy sample script
2016-09-07 15:28:27 +02:00
Mészáros Mihály
d70d0353ec tidy 2016-09-07 15:28:27 +02:00
Mészáros Mihály
14754ce43b Add turnutils_oauth to README.turnutils 2016-09-07 15:28:27 +02:00
Mészáros Mihály
87c9906d71 Added myself as Author to READMEs 2016-09-04 06:41:52 +02:00
Mészáros Mihály
7b2575fe25 add natdiscovery to make-man.sh and README.turnutils 2016-09-04 05:51:36 +02:00
Oleg Moskalenko
43b62d16f2 typos fixed 2016-08-27 16:24:08 -07:00
Oleg Moskalenko
7f0ab33928 docs changes 2015-11-29 10:16:37 -08:00
Oleg Moskalenko
e2c5911fe4 working on 4.4.5.4 2015-07-18 21:54:16 -07:00
mom040267
f85ca3cf95 minor docs fix 2015-06-15 08:39:30 +00:00
mom040267
676843bf09 retiring --sha256, etc 2015-04-11 07:53:30 +00:00
mom040267
69653ea259 native SCTP support 2015-03-15 19:48:30 +00:00
mom040267
caf63a35de sha384 added 2015-02-06 08:17:49 +00:00
mom040267
08f0488255 sha512 added 2015-02-05 07:39:07 +00:00
mom040267
d5b84163b6 working on even-port. 2015-02-01 07:26:29 +00:00
mom040267
237b3baaa7 short-term credentials removed in the TURN server 2015-01-11 06:28:58 +00:00
mom040267
83a5182941 working on https server 2015-01-01 03:22:26 +00:00
mom040267
dafedda0b9 tunable TURNDBDIR 2014-11-23 21:24:04 +00:00
mom040267
01e2364a7d docs updated 2014-11-21 08:14:45 +00:00
mom040267
68f28329fc working on sqlite 2014-11-20 04:13:49 +00:00
mom040267
221f014a6c working on sqlite install 2014-11-20 02:56:53 +00:00
mom040267
924fa29c5e make SQLite optional 2014-11-19 18:41:24 +00:00
mom040267
ef149fb30d default turndb changed to ~/turndb 2014-11-17 01:33:31 +00:00
mom040267
dcc132223b /var/db changed to /var 2014-11-16 19:05:12 +00:00
mom040267
b9ef9f4c61 working on sqlite support 2014-11-16 07:52:46 +00:00
mom040267
9ee8788e16 docs updated 2014-11-09 09:25:25 +00:00
mom040267
76b5527c33 uclent help fixed. 2014-09-27 05:55:51 +00:00
mom040267
064aca0fa7 oauth 2014-09-26 00:31:20 +00:00
mom040267
a3871c9435 author added 2014-09-23 00:39:19 +00:00
mom040267
218fe7f81d man page fixes 2014-07-23 04:32:08 +00:00
mom040267
f7f1784fc1 working on dual allocation 2014-07-16 07:04:11 +00:00
mom040267
552aca7082 working on MongoDB. 2014-07-12 01:00:36 +00:00
mom040267
7e7ee8b868 docs cleaning 2014-05-30 06:37:08 +00:00
mom040267
16f2f22dd3 working on bandwidth 2014-05-30 06:32:03 +00:00
mom040267
03ea4937ac more fixes for 123 issue 2014-04-24 06:02:45 +00:00