@@ -19,6 +19,7 @@ use crate::{
1919 hashes:: InfoHash ,
2020 peer:: PeerId ,
2121 protocol:: stream:: PeerStream ,
22+ settings:: Settings ,
2223 torrent:: { PieceStorageStrategy , TorrentActor } ,
2324 tracker:: udp:: UdpServer ,
2425} ;
@@ -51,13 +52,8 @@ pub struct EngineActor {
5152
5253 pub ( crate ) default_piece_storage_strategy : PieceStorageStrategy ,
5354
54- /// Mailbox size for each torrent instance
55- pub ( crate ) mailbox_size : usize ,
56-
57- /// If we autostart torrents
58- pub ( crate ) autostart : Option < bool > ,
59- /// How many peers we need to have before we start downloading
60- pub ( crate ) sufficient_peers : Option < usize > ,
55+ /// Runtime behavior settings shared with torrent, peer, and tracker actors.
56+ pub ( crate ) settings : Settings ,
6157
6258 pub ( crate ) default_base_path : Option < PathBuf > ,
6359}
@@ -96,21 +92,8 @@ pub struct EngineActorArgs {
9692 /// managed by this engine.
9793 pub piece_storage_strategy : PieceStorageStrategy ,
9894
99- /// Mailbox size for each torrent instance.
100- ///
101- /// Defaults to 64 if not provided. If set to 0, the mailbox will be
102- /// unbounded.
103- pub mailbox_size : Option < usize > ,
104-
105- /// Whether to automatically start torrents when they become ready.
106- ///
107- /// If not provided, defaults to `None` (use engine-level default).
108- pub autostart : Option < bool > ,
109-
110- /// Minimum number of peers required before starting download.
111- ///
112- /// If not provided, defaults to `None` (use engine-level default).
113- pub sufficient_peers : Option < usize > ,
95+ /// Runtime behavior settings.
96+ pub settings : Settings ,
11497
11598 /// Default base path for torrent downloads.
11699 ///
@@ -144,23 +127,25 @@ impl Actor for EngineActor {
144127 udp_addr,
145128 peer_id,
146129 piece_storage_strategy,
147- mailbox_size,
148- autostart,
149- sufficient_peers,
130+ settings,
150131 default_base_path,
151132 } = args;
152133
153- let tcp_addr = tcp_addr. unwrap_or_else ( || SocketAddr :: from ( ( [ 0 , 0 , 0 , 0 ] , 0 ) ) ) ;
154- // Should this be port 6881?
155- let utp_addr = utp_addr. unwrap_or_else ( || SocketAddr :: from ( ( [ 0 , 0 , 0 , 0 ] , 0 ) ) ) ;
156- let udp_addr = udp_addr. unwrap_or_else ( || SocketAddr :: from ( ( [ 0 , 0 , 0 , 0 ] , 0 ) ) ) ;
134+ let tcp_addr = tcp_addr. unwrap_or ( settings. engine . tcp_addr ) ;
135+ let utp_addr = utp_addr. unwrap_or ( settings. engine . utp_addr ) ;
136+ let udp_addr = udp_addr. unwrap_or ( settings. engine . udp_addr ) ;
157137 let tcp_socket = TcpListener :: bind ( tcp_addr)
158138 . await
159139 . map_err ( |e| EngineError :: NetworkSetupFailed ( format ! ( "tcp bind {tcp_addr}: {e}" ) ) ) ?;
160140 let utp_socket = UtpSocketUdp :: new_udp ( utp_addr)
161141 . await
162142 . map_err ( |e| EngineError :: NetworkSetupFailed ( format ! ( "utp bind {utp_addr}: {e}" ) ) ) ?;
163- let udp_server = UdpServer :: new ( Some ( udp_addr) ) . await ;
143+ let udp_server = UdpServer :: new_with_receive_buffer_size (
144+ Some ( udp_addr) ,
145+ settings. tracker . udp_receive_buffer_size ,
146+ )
147+ . await
148+ . map_err ( |e| EngineError :: NetworkSetupFailed ( format ! ( "udp bind {udp_addr}: {e}" ) ) ) ?;
164149
165150 let peer_id = peer_id. unwrap_or_default ( ) ;
166151
@@ -172,9 +157,7 @@ impl Actor for EngineActor {
172157 peer_id,
173158 actor_ref,
174159 default_piece_storage_strategy : piece_storage_strategy,
175- mailbox_size : mailbox_size. unwrap_or ( 64 ) ,
176- autostart,
177- sufficient_peers,
160+ settings,
178161 default_base_path,
179162 } )
180163 }
0 commit comments