Skip to content

Commit 5fc184e

Browse files
committed
Broadcast speed should be set per interface
1 parent ec1b3de commit 5fc184e

4 files changed

Lines changed: 14 additions & 16 deletions

File tree

pixie-server/example.config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ hosts:
33
- network: 10.0.0.1/8
44
dhcp: !static [10.187.100.1, 10.187.200.200]
55
#dhcp: !proxy 192.168.1.100
6+
broadcast_speed: 52428800
67
hostsfile: /etc/hosts
7-
broadcast_speed: 52428800
88
http:
99
listen_on: 0.0.0.0:8080
1010
#password: secret

pixie-server/src/udp.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use anyhow::{ensure, Context, Result};
88
use futures::FutureExt;
99
use ipnet::Ipv4Net;
1010
use pixie_shared::{
11-
chunk_codec::Encoder, ChunkHash, HintPacket, RegistrationInfo, UdpRequest, ACTION_PORT,
12-
CHUNKS_PORT, HINT_PORT, UDP_BODY_LEN,
11+
chunk_codec::Encoder, ChunkHash, HintPacket, InterfaceConfig, RegistrationInfo, UdpRequest,
12+
ACTION_PORT, CHUNKS_PORT, HINT_PORT, UDP_BODY_LEN,
1313
};
1414
use std::{
1515
collections::BTreeSet,
@@ -26,7 +26,7 @@ use tokio::{
2626
async fn broadcast_chunks(
2727
state: &State,
2828
socket: &UdpSocket,
29-
ip: Ipv4Addr,
29+
iface: &InterfaceConfig,
3030
mut rx: Receiver<ChunkHash>,
3131
) -> Result<()> {
3232
let mut queue = BTreeSet::<ChunkHash>::new();
@@ -77,8 +77,7 @@ async fn broadcast_chunks(
7777
continue;
7878
};
7979

80-
let hosts_cfg = &state.config.hosts;
81-
let chunks_addr = SocketAddrV4::new(ip, CHUNKS_PORT);
80+
let chunks_addr = SocketAddrV4::new(iface.network.broadcast(), CHUNKS_PORT);
8281

8382
let mut encoder = Encoder::new(cdata);
8483
write_buf[..32].clone_from_slice(&index);
@@ -87,7 +86,7 @@ async fn broadcast_chunks(
8786

8887
let sent_len = socket.send_to(&write_buf[..32 + len], chunks_addr).await?;
8988
ensure!(sent_len == 32 + len, "Could not send packet");
90-
wait_for += 8 * (sent_len as u32) * Duration::from_secs(1) / hosts_cfg.broadcast_speed;
89+
wait_for += 8 * (sent_len as u32) * Duration::from_secs(1) / iface.broadcast_speed;
9190
}
9291
}
9392

@@ -221,7 +220,7 @@ pub async fn main(state: Arc<State>) -> Result<()> {
221220
.iter()
222221
.map(|iface| {
223222
let (tx, rx) = mpsc::channel(128);
224-
((iface.network, tx), (iface.network, rx))
223+
((iface.network, tx), (iface, rx))
225224
})
226225
.unzip();
227226

@@ -231,9 +230,9 @@ pub async fn main(state: Arc<State>) -> Result<()> {
231230

232231
let mut tasks = vec![handle_requests(&state, &socket, net_tx).boxed()];
233232

234-
for (network, rx) in net_rx {
235-
tasks.push(broadcast_chunks(&state, &socket, network.broadcast(), rx).boxed());
236-
tasks.push(broadcast_hint(&state, &socket, network.broadcast()).boxed());
233+
for (iface, rx) in net_rx {
234+
tasks.push(broadcast_chunks(&state, &socket, iface, rx).boxed());
235+
tasks.push(broadcast_hint(&state, &socket, iface.network.broadcast()).boxed());
237236
}
238237

239238
futures::future::try_join_all(tasks).await?;

pixie-shared/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct InterfaceConfig {
2525
pub network: Ipv4Net,
2626
/// DHCP server.
2727
pub dhcp: DhcpMode,
28+
/// Speed in bytes/second used to broadcast chunks.
29+
pub broadcast_speed: u32,
2830
}
2931

3032
/// Registered clients will always be assigned an IP in the form
@@ -37,8 +39,6 @@ pub struct HostsConfig {
3739
pub interfaces: Vec<InterfaceConfig>,
3840
/// Hosts file to use for DHCP hostnames.
3941
pub hostsfile: Option<PathBuf>,
40-
/// Speed in bytes/second used to broadcast chunks.
41-
pub broadcast_speed: u32,
4242
}
4343

4444
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]

test_config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ hosts:
22
interfaces:
33
- network: 10.0.0.1/16
44
dhcp: !static [10.0.100.1, 10.0.200.200]
5-
#dhcp: !proxy 192.168.1.100
5+
broadcast_speed: 52428800
66
- network: 10.10.0.1/16
77
dhcp: !static [10.10.100.1, 10.10.200.200]
8+
broadcast_speed: 52428800
89
hostsfile: /etc/hosts
9-
broadcast_speed: 52428800
1010
http:
1111
listen_on: 0.0.0.0:8080
12-
#password: secret
1312
groups:
1413
- [room0, 0]
1514
- [room10, 10]

0 commit comments

Comments
 (0)