Skip to content

Commit fa4399b

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

4 files changed

Lines changed: 13 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: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ 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, ACTION_PORT, CHUNKS_PORT, HINT_PORT, UDP_BODY_LEN
1312
};
1413
use std::{
1514
collections::BTreeSet,
@@ -26,7 +25,7 @@ use tokio::{
2625
async fn broadcast_chunks(
2726
state: &State,
2827
socket: &UdpSocket,
29-
ip: Ipv4Addr,
28+
iface: &InterfaceConfig,
3029
mut rx: Receiver<ChunkHash>,
3130
) -> Result<()> {
3231
let mut queue = BTreeSet::<ChunkHash>::new();
@@ -77,8 +76,7 @@ async fn broadcast_chunks(
7776
continue;
7877
};
7978

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

8381
let mut encoder = Encoder::new(cdata);
8482
write_buf[..32].clone_from_slice(&index);
@@ -87,7 +85,7 @@ async fn broadcast_chunks(
8785

8886
let sent_len = socket.send_to(&write_buf[..32 + len], chunks_addr).await?;
8987
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;
88+
wait_for += 8 * (sent_len as u32) * Duration::from_secs(1) / iface.broadcast_speed;
9189
}
9290
}
9391

@@ -221,7 +219,7 @@ pub async fn main(state: Arc<State>) -> Result<()> {
221219
.iter()
222220
.map(|iface| {
223221
let (tx, rx) = mpsc::channel(128);
224-
((iface.network, tx), (iface.network, rx))
222+
((iface.network, tx), (iface, rx))
225223
})
226224
.unzip();
227225

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

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

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());
232+
for (iface, rx) in net_rx {
233+
tasks.push(broadcast_chunks(&state, &socket, iface, rx).boxed());
234+
tasks.push(broadcast_hint(&state, &socket, iface.network.broadcast()).boxed());
237235
}
238236

239237
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)