Skip to content
This repository was archived by the owner on Dec 10, 2022. It is now read-only.

Commit 10a4ef2

Browse files
authored
Merge pull request #36 from tox-rs/bounded
Use bounded streams
2 parents a77cce2 + a0a95e2 commit 10a4ef2

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ use syslog::Facility;
4646
use cli_config::*;
4747
use motd::{Motd, Counters};
4848

49+
/// Channel size for onion messages between UDP and TCP relay.
50+
const ONION_CHANNEL_SIZE: usize = 32;
51+
/// Channel size for DHT packets.
52+
const DHT_CHANNEL_SIZE: usize = 32;
53+
4954
/// Get version in format 3AAABBBCCC, where A B and C are major, minor and patch
5055
/// versions of node. `tox-bootstrapd` uses similar scheme but with leading 1.
5156
/// Before it used format YYYYMMDDVV so the leading numeral was 2. To make a
@@ -136,23 +141,23 @@ fn run<F>(future: F, threads_config: ThreadsConfig)
136141
/// Onion sink and stream for TCP.
137142
struct TcpOnion {
138143
/// Sink for onion packets from TCP to UDP.
139-
tx: mpsc::UnboundedSender<(OnionRequest, SocketAddr)>,
144+
tx: mpsc::Sender<(OnionRequest, SocketAddr)>,
140145
/// Stream of onion packets from TCP to UDP.
141-
rx: mpsc::UnboundedReceiver<(InnerOnionResponse, SocketAddr)>,
146+
rx: mpsc::Receiver<(InnerOnionResponse, SocketAddr)>,
142147
}
143148

144149
/// Onion sink and stream for UDP.
145150
struct UdpOnion {
146151
/// Sink for onion packets from UDP to TCP.
147-
tx: mpsc::UnboundedSender<(InnerOnionResponse, SocketAddr)>,
152+
tx: mpsc::Sender<(InnerOnionResponse, SocketAddr)>,
148153
/// Stream of onion packets from TCP to UDP.
149-
rx: mpsc::UnboundedReceiver<(OnionRequest, SocketAddr)>,
154+
rx: mpsc::Receiver<(OnionRequest, SocketAddr)>,
150155
}
151156

152157
/// Create onion streams for TCP and UDP servers communication.
153158
fn create_onion_streams() -> (TcpOnion, UdpOnion) {
154-
let (udp_onion_tx, udp_onion_rx) = mpsc::unbounded();
155-
let (tcp_onion_tx, tcp_onion_rx) = mpsc::unbounded();
159+
let (udp_onion_tx, udp_onion_rx) = mpsc::channel(ONION_CHANNEL_SIZE);
160+
let (tcp_onion_tx, tcp_onion_rx) = mpsc::channel(ONION_CHANNEL_SIZE);
156161
let tcp_onion = TcpOnion {
157162
tx: tcp_onion_tx,
158163
rx: udp_onion_rx,
@@ -224,7 +229,7 @@ fn run_udp(cli_config: &CliConfig, dht_pk: PublicKey, dht_sk: &SecretKey, udp_on
224229
let (sink, stream) = UdpFramed::new(socket, codec).split();
225230

226231
// Create a channel for server to communicate with network
227-
let (tx, rx) = mpsc::unbounded();
232+
let (tx, rx) = mpsc::channel(DHT_CHANNEL_SIZE);
228233

229234
let lan_discovery_future = if cli_config.lan_discovery_enabled {
230235
Either::A(LanDiscoverySender::new(tx.clone(), dht_pk, udp_addr.is_ipv6())

0 commit comments

Comments
 (0)