Skip to content

Commit 4b3e3b7

Browse files
committed
Receive monitor requests from any address, team messages only from interface (#20)
1 parent 6a66030 commit 4b3e3b7

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ In addition, the GameController offers an interface for monitor applications (su
6464

6565
The user must ensure that all of the aforementioned network communication channels are allowed to be used by the firewall.
6666
The GameController runs on a specific network interface, which generally specifies where packets are sent and from where they are received.
67-
The exceptions are that control messages can be configured to be sent to the limited broadcast address (`255.255.255.255`) instead of the interface's broadcast address, and that team messages are received from any address.
67+
The exceptions are that control messages can be configured to be sent to the limited broadcast address (`255.255.255.255`) instead of the interface's broadcast address, and that monitor requests are received from any address.
6868

6969
## Usage
7070

game_controller_net/src/monitor_request_receiver.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{cmp::min, net::IpAddr};
1+
use std::{
2+
cmp::min,
3+
net::{IpAddr, Ipv4Addr, Ipv6Addr},
4+
};
25

36
use anyhow::Result;
47
use bytes::Bytes;
@@ -19,7 +22,14 @@ impl MonitorRequestReceiver {
1922
/// This function creates a new receiver for monitor requests.
2023
pub async fn new(address: IpAddr, event_sender: mpsc::UnboundedSender<Event>) -> Result<Self> {
2124
Ok(Self {
22-
socket: UdpSocket::bind((address, MONITOR_REQUEST_PORT)).await?,
25+
socket: UdpSocket::bind((
26+
match address {
27+
IpAddr::V4(_) => IpAddr::V4(Ipv4Addr::UNSPECIFIED),
28+
IpAddr::V6(_) => IpAddr::V6(Ipv6Addr::UNSPECIFIED),
29+
},
30+
MONITOR_REQUEST_PORT,
31+
))
32+
.await?,
2333
event_sender,
2434
})
2535
}

game_controller_net/src/team_message_receiver.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
cmp::min,
3-
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
3+
net::{IpAddr, Ipv4Addr, SocketAddr},
44
};
55

66
use anyhow::Result;
@@ -34,14 +34,8 @@ impl TeamMessageReceiver {
3434
Ok(Self {
3535
socket: {
3636
// This might be stuff that should not be done in an async function.
37-
let socket_address: SockAddr = SocketAddr::new(
38-
match address {
39-
IpAddr::V4(_) => IpAddr::V4(Ipv4Addr::UNSPECIFIED),
40-
IpAddr::V6(_) => IpAddr::V6(Ipv6Addr::UNSPECIFIED),
41-
},
42-
TEAM_MESSAGE_PORT_BASE + (team as u16),
43-
)
44-
.into();
37+
let socket_address: SockAddr =
38+
SocketAddr::new(address, TEAM_MESSAGE_PORT_BASE + (team as u16)).into();
4539
let raw_socket =
4640
Socket::new(socket_address.domain(), Type::DGRAM, Some(Protocol::UDP))?;
4741
#[cfg(target_os = "macos")]

0 commit comments

Comments
 (0)