Skip to content

feat(turn): add TCP TURN client example and expose server/local addr#83

Open
nightness wants to merge 3 commits into
webrtc-rs:masterfrom
Brainwires:feat/tcp-turn-example
Open

feat(turn): add TCP TURN client example and expose server/local addr#83
nightness wants to merge 3 commits into
webrtc-rs:masterfrom
Brainwires:feat/tcp-turn-example

Conversation

@nightness
Copy link
Copy Markdown

@nightness nightness commented Apr 1, 2026

Summary

  • Add examples/turn_client_tcp.rs demonstrating TURN relay over TCP
  • Expose turn_server_addr() and local_addr() accessors on the TURN client
  • Enables TCP fallback when UDP TURN is blocked (common in corporate firewalls)

Review feedback addressed

  • Replace unwrap() on --log-level parse with friendly error
  • Use split_once('=') for --user to avoid panic on malformed input
  • Simplify ctrlc handler: unbounded channel, no thread wrapper
  • Extract turn_server_addr_or_err() helper to deduplicate repeated pattern
  • cargo fmt / cargo clippy pass clean
  • Fix invalid email TLD in clap author metadata
  • Fix non-blocking write_all() WouldBlock risk: use blocking writes with timeout
  • Fix EOF handling: read_tcp_input() now returns Err on EOF to break main loop
  • Add unit tests for turn_server_addr(), turn_server_addr_or_err(), local_addr()

Test plan

  • cargo build --example turn_client_tcp -p rtc-turn
  • cargo test -p rtc-turn (39 tests pass, including 5 new accessor tests)
  • Run against a TURN server with TCP support

Generated with Claude Code

@rainliu rainliu requested a review from Copilot April 4, 2026 14:08
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a TCP-based TURN client example and exposes client address accessors to support TURN-over-TCP fallback scenarios (e.g., UDP blocked by corporate firewalls).

Changes:

  • Added turn_client_tcp example demonstrating TURN relay over TCP with RFC4571 framing.
  • Exposed Client::turn_server_addr() and Client::local_addr() accessors.
  • Updated internal call sites to handle turn_server_addr() now returning Option<SocketAddr>.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
rtc-turn/src/client/relay.rs Updates TURN server address retrieval to handle Option and map to ErrNilTurnSocket.
rtc-turn/src/client/mod.rs Exposes turn_server_addr() / local_addr() publicly and adjusts transactions to use the new return type.
rtc-turn/examples/turn_client_tcp.rs New example implementing TURN client over TCP (RFC6062) with RFC4571 framing.
rtc-turn/Cargo.toml Registers the new turn_client_tcp example target.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rtc-turn/examples/turn_client_tcp.rs Outdated
Comment thread rtc-turn/examples/turn_client_tcp.rs Outdated
Comment thread rtc-turn/examples/turn_client_tcp.rs Outdated
Comment thread rtc-turn/src/client/relay.rs Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 4, 2026

Codecov Report

❌ Patch coverage is 0% with 143 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.07%. Comparing base (9feb4a3) to head (0303927).

Files with missing lines Patch % Lines
rtc-turn/examples/turn_client_tcp.rs 0.00% 138 Missing ⚠️
rtc-turn/src/client/relay.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
- Coverage   71.17%   71.07%   -0.10%     
==========================================
  Files         442      443       +1     
  Lines       67330    67468     +138     
==========================================
+ Hits        47922    47953      +31     
- Misses      19408    19515     +107     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

nightness added a commit to Brainwires/webrtc-rs-rtc that referenced this pull request Apr 8, 2026
- Replace unwrap() on log level parse with proper error message
- Use split_once('=') for --user flag to avoid panic on malformed input
- Simplify ctrlc handler: use unbounded channel, no thread wrapper needed
- Extract turn_server_addr_or_err() helper to deduplicate repeated pattern

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nightness nightness requested a review from Copilot April 8, 2026 08:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rtc-turn/examples/turn_client_tcp.rs Outdated
Comment thread rtc-turn/examples/turn_client_tcp.rs Outdated
Comment thread rtc-turn/examples/turn_client_tcp.rs Outdated
nightness and others added 3 commits April 10, 2026 00:17
…ocal_addr

- Add rtc-turn/examples/turn_client_tcp.rs: demonstrates TURN over TCP using
  RFC 4571 framing (TcpFrameDecoder + frame_packet from rtc-shared)
- Make Client::turn_server_addr() and Client::local_addr() public so callers
  (e.g. the ICE gatherer in the async layer) can identify TURN server addresses
- Fix relay.rs and mod.rs call sites from the return-type change
  (Result → Option for turn_server_addr)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Replace unwrap() on log level parse with proper error message
- Use split_once('=') for --user flag to avoid panic on malformed input
- Simplify ctrlc handler: use unbounded channel, no thread wrapper needed
- Extract turn_server_addr_or_err() helper to deduplicate repeated pattern

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix invalid email TLD in clap author metadata (brainwires@github -> .com)
- Fix non-blocking write_all by using blocking writes with timeout
- Fix EOF spin: read_tcp_input now returns Err on EOF to break main loop
- Add 5 unit tests for turn_server_addr(), turn_server_addr_or_err(), local_addr()

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nightness nightness force-pushed the feat/tcp-turn-example branch from 76ad3f5 to dc27c09 Compare April 10, 2026 05:17
@nightness
Copy link
Copy Markdown
Author

Rebased onto upstream/master so this PR contains only its own changes. Previous branch structure caused merge conflicts when PRs were merged in sequence. Each PR is now independently mergeable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants