Skip to content

Commit

Permalink
chore: try bind to all interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel-G committed Jan 10, 2025
1 parent 4ac3f88 commit 8176388
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion backend/client/infrastructure/task.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module "task" {
"PUBLIC_IP" = var.instance.public_ip,
"PORT" = "3478",
"SIGNAL_SERVER" = "ws://localhost:8000/signaling",
"RUST_LOG" = "sobaka_client=info"
"RUST_LOG" = "sobaka_client=debug"
}
secrets = {
JWT = {
Expand Down
10 changes: 7 additions & 3 deletions backend/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Client {
.set_read_timeout(Some(duration))
.expect("setting socket read timeout");

if let Some(input) = read_socket_input(&self.socket, &mut self.buf) {
if let Some(input) = read_socket_input(&self.socket, &self.candidate, &mut self.buf) {
// The rtc.accepts() call is how we demultiplex the incoming packet to know which
// Rtc instance the traffic belongs to.
if let Some(client) = self.connections.iter_mut().find(|c| c.accepts(&input)) {
Expand All @@ -244,7 +244,11 @@ impl Client {
}
}

fn read_socket_input<'a>(socket: &UdpSocket, buf: &'a mut Vec<u8>) -> Option<Input<'a>> {
fn read_socket_input<'a>(
socket: &UdpSocket,
candidate: &Candidate,
buf: &'a mut Vec<u8>,
) -> Option<Input<'a>> {
buf.resize(2000, 0);

match socket.recv_from(buf) {
Expand All @@ -262,7 +266,7 @@ fn read_socket_input<'a>(socket: &UdpSocket, buf: &'a mut Vec<u8>) -> Option<Inp
Receive {
proto: Protocol::Udp,
source,
destination: socket.local_addr().unwrap(),
destination: candidate.addr(),
contents,
},
))
Expand Down
4 changes: 2 additions & 2 deletions backend/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::panic;
use signal::connection::websocket_client;
use std::net::{IpAddr, SocketAddr, UdpSocket};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use str0m::Candidate;
use systemstat::{Platform, System};
use url::Url;
Expand Down Expand Up @@ -57,7 +57,7 @@ async fn main() {
.expect("PORT must be a valid number");

let socket =
UdpSocket::bind((select_host_address(), port)).expect("binding to specified UDP port");
UdpSocket::bind((Ipv4Addr::UNSPECIFIED, port)).expect("binding to specified UDP port");

let addr = socket.local_addr().expect("a local socket address");
log::info!("Bound UDP port: {}", addr);
Expand Down
1 change: 1 addition & 0 deletions backend/infrastructure/task/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ locals {
docker run \
--name ${var.name} \
--restart always \
--network host \
--detach \
${join(" ", [for env_name, value in var.env : "-e ${env_name}=${value}"])} \
${join(" ", [for port in var.ports : "-p ${port}"])} \
Expand Down

0 comments on commit 8176388

Please sign in to comment.