Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Alternate server tcp udp distinction #1604#1605

Open
Cybermilitia wants to merge 8 commits intocoturn:masterfrom
Cybermilitia:alternate-server-tcp-udp-distinction
Open

Alternate server tcp udp distinction #1604#1605
Cybermilitia wants to merge 8 commits intocoturn:masterfrom
Cybermilitia:alternate-server-tcp-udp-distinction

Conversation

@Cybermilitia
Copy link
Contributor

  • Added separate TCP and UDP alternate server lists to resolve port ambiguity.
  • Enabled the use of an existing TLS counter for Alternate Server round-robin selection, fixing a bug where only the generic counter was used.
  • Ensures correct redirection for clients using different protocols (TCP/UDP).
  • Improves reliability and prevents misdirected connections in multi-protocol setups.

CUMHUR KARAHAN added 6 commits November 28, 2023 14:33
Added session id parameter to use it in "A peer IP <IP> denied in the
range" logs. Besides, server ID has been made visible in this logs.
Added separate TCP and UDP alternate server lists
to resolve port ambiguity.
Enabled the use of an existing TLS counter
for Alternate Server round-robin selection
@Cybermilitia
Copy link
Contributor Author

As far as I can understand, the fails are not related to the code directly. Do you have any opinion?

@eakraly
Copy link
Collaborator

eakraly commented Feb 21, 2025

Hi @Cybermilitia ! Could you please rebase and resolve the conflicts? Thanks!

@ggarber ggarber requested a review from Copilot May 27, 2025 10:30
@ggarber ggarber self-assigned this May 27, 2025
Copy link
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

This PR separates TCP and UDP alternate server lists, adjusts the round-robin counters accordingly, and exposes the new lists in both CLI and HTTP admin interfaces to prevent protocol misdirection.

  • Introduce tcp_alternate_servers_list and udp_alternate_servers_list along with their counters in the server struct.
  • Update selection logic in ns_turn_server.c to pick protocol-specific lists and counters.
  • Add CLI commands, HTTP printouts, and initialization for the new lists in relay tools.

Reviewed Changes

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

Show a summary per file
File Description
src/server/ns_turn_server.h Declare new TCP/UDP alternate server lists and counters
src/server/ns_turn_server.c Protocol-aware selection logic uses correct list and counter
src/apps/relay/turn_admin_server.c Add CLI handlers and config printing for TCP/UDP alternate servers
src/apps/relay/netengine.c Implement add_/del_{tcp,udp}_alternate_server functions
src/apps/relay/mainrelay.h Declare new CLI option handlers for TCP/UDP alternate servers
src/apps/relay/mainrelay.c Initialize new lists and wire up long options for TCP/UDP alternate servers
Comments suppressed due to low confidence (2)

src/apps/relay/turn_admin_server.c:1103

  • [nitpick] The CLI commands atcpas and audpas are terse and may be confusing; consider using clearer names like add-tcp-alt-server and add-udp-alt-server to match long-option style.
} else if (strstr(cmd, "atcpas ") == cmd) {

src/apps/relay/netengine.c:291

  • New functions add_/del_tcp_alternate_server and add_/del_udp_alternate_server are added—consider adding unit tests to verify their behavior and ensure correct list manipulation.
void add_tcp_alternate_server(const char *saddr) {

Comment on lines +292 to +304
add_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.tcp_alternate_servers_list);
}

void del_tcp_alternate_server(const char *saddr) {
del_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.tcp_alternate_servers_list);
}

void add_udp_alternate_server(const char *saddr) {
add_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.udp_alternate_servers_list);
}

void del_udp_alternate_server(const char *saddr) {
del_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.udp_alternate_servers_list);
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

Using DEFAULT_STUN_TLS_PORT as the default port for TCP alternate servers may be incorrect; consider using a TCP-appropriate default or make the port configurable to match the protocol.

Suggested change
add_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.tcp_alternate_servers_list);
}
void del_tcp_alternate_server(const char *saddr) {
del_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.tcp_alternate_servers_list);
}
void add_udp_alternate_server(const char *saddr) {
add_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.udp_alternate_servers_list);
}
void del_udp_alternate_server(const char *saddr) {
del_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.udp_alternate_servers_list);
add_alt_server(saddr, DEFAULT_TCP_PORT, &turn_params.tcp_alternate_servers_list);
}
void del_tcp_alternate_server(const char *saddr) {
del_alt_server(saddr, DEFAULT_TCP_PORT, &turn_params.tcp_alternate_servers_list);
}
void add_udp_alternate_server(const char *saddr) {
add_alt_server(saddr, DEFAULT_UDP_PORT, &turn_params.udp_alternate_servers_list);
}
void del_udp_alternate_server(const char *saddr) {
del_alt_server(saddr, DEFAULT_UDP_PORT, &turn_params.udp_alternate_servers_list);

Copilot uses AI. Check for mistakes.
}

void add_udp_alternate_server(const char *saddr) {
add_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.udp_alternate_servers_list);
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

The UDP alternate server is initialized with DEFAULT_STUN_TLS_PORT; it should likely use DEFAULT_STUN_PORT (3478) or be configurable to avoid mis-routing.

Suggested change
add_alt_server(saddr, DEFAULT_STUN_TLS_PORT, &turn_params.udp_alternate_servers_list);
add_alt_server(saddr, DEFAULT_STUN_PORT, &turn_params.udp_alternate_servers_list);

Copilot uses AI. Check for mistakes.
@ggarber
Copy link
Contributor

ggarber commented May 27, 2025

Fixed bug with ports and also rebased and reformatted. But it is still missing updating the config file and the READMe doc.

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.

4 participants