Skip to content

Commit 69124f3

Browse files
maxholmanclaude
andcommitted
refactor: rename directive_{sink,source} to command_{sink,source}
Aligns channel names with the NodeCommand type they carry. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent cc26fa6 commit 69124f3

4 files changed

Lines changed: 30 additions & 30 deletions

File tree

crates/core/src/control/handler.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ pub struct Handler {
159159
config: HandlerConfig,
160160
/// Command channel to the mode task. Carries role changes, connect,
161161
/// listen, and disconnect commands.
162-
directive_source: mpsc::Sender<NodeCommand>,
162+
command_source: mpsc::Sender<NodeCommand>,
163163
/// Receiver side of the command channel. Extracted once by the daemon
164164
/// before wrapping Handler in `Arc<dyn NodeApi>`.
165-
directive_sink: std::sync::Mutex<Option<mpsc::Receiver<NodeCommand>>>,
165+
command_sink: std::sync::Mutex<Option<mpsc::Receiver<NodeCommand>>>,
166166
log_buffer: LogBuffer,
167167
metrics: SharedMetrics,
168168
peers: SharedRegistry,
@@ -188,11 +188,11 @@ impl Handler {
188188
log_buffer: Option<LogBuffer>,
189189
) -> Self {
190190
let state = SharedNodeState::new(config.node_role);
191-
let (directive_source, directive_sink) = mpsc::channel(8);
191+
let (command_source, command_sink) = mpsc::channel(8);
192192
Self {
193193
config,
194-
directive_source,
195-
directive_sink: std::sync::Mutex::new(Some(directive_sink)),
194+
command_source,
195+
command_sink: std::sync::Mutex::new(Some(command_sink)),
196196
log_buffer: log_buffer.unwrap_or_default(),
197197
metrics,
198198
peers,
@@ -220,12 +220,12 @@ impl Handler {
220220
///
221221
/// Panics if the mutex is poisoned or if called more than once.
222222
#[must_use]
223-
pub fn directive_sink(&self) -> mpsc::Receiver<NodeCommand> {
224-
self.directive_sink
223+
pub fn command_sink(&self) -> mpsc::Receiver<NodeCommand> {
224+
self.command_sink
225225
.lock()
226-
.expect("directive_sink mutex poisoned")
226+
.expect("command_sink mutex poisoned")
227227
.take()
228-
.expect("directive_sink already taken")
228+
.expect("command_sink already taken")
229229
}
230230

231231
/// Handles a control request and returns a response.
@@ -479,7 +479,7 @@ impl crate::node_api::NodeApi for Handler {
479479

480480
fn connect(&self, addr: &str) -> crate::node_api::Result<crate::node_api::ConnectInfo> {
481481
let (reply_sender, reply_receiver) = reply_channel();
482-
self.directive_source
482+
self.command_source
483483
.try_send(NodeCommand::Connect {
484484
addr: addr.to_string(),
485485
reply: reply_sender,
@@ -499,7 +499,7 @@ impl crate::node_api::NodeApi for Handler {
499499
addr: std::net::SocketAddr,
500500
) -> crate::node_api::Result<crate::node_api::ListenInfo> {
501501
let (reply_sender, reply_receiver) = reply_channel();
502-
self.directive_source
502+
self.command_source
503503
.try_send(NodeCommand::Listen {
504504
addr,
505505
reply: reply_sender,
@@ -516,7 +516,7 @@ impl crate::node_api::NodeApi for Handler {
516516

517517
fn disconnect(&self) -> crate::node_api::Result<()> {
518518
let (reply_sender, reply_receiver) = reply_channel();
519-
self.directive_source
519+
self.command_source
520520
.try_send(NodeCommand::Disconnect {
521521
reply: reply_sender,
522522
})
@@ -600,14 +600,14 @@ impl crate::node_api::NodeApi for Handler {
600600

601601
fn hint_set(&self, hint: RoleHint) -> crate::node_api::Result<()> {
602602
let _ = self
603-
.directive_source
603+
.command_source
604604
.try_send(NodeCommand::Role { hint: Some(hint) });
605605
Ok(())
606606
}
607607

608608
fn hint_set_auto(&self) -> crate::node_api::Result<()> {
609609
let _ = self
610-
.directive_source
610+
.command_source
611611
.try_send(NodeCommand::Role { hint: None });
612612
Ok(())
613613
}

crates/daemon/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub fn start_node(
164164
log_buffer,
165165
);
166166
let node_state = handler.node_state();
167-
let directive_sink = handler.directive_sink();
167+
let command_sink = handler.command_sink();
168168
let node_api: Arc<dyn NodeApi> = Arc::new(handler);
169169

170170
let (shutdown_tx, _shutdown_rx) = watch::channel(());
@@ -178,7 +178,7 @@ pub fn start_node(
178178
route_updates: route_update_rx,
179179
route_updates_tx: route_update_tx,
180180
node_state,
181-
directive_sink,
181+
command_sink,
182182
};
183183
let task = tokio::spawn(async move { mode::run(&config, resources).await.map_err(Into::into) });
184184

crates/daemon/src/mode/auto.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl AutoContext {
7373
/// # Errors
7474
///
7575
/// Returns error if the connection setup fails non-retryably.
76-
// REASON: threading metrics, peers, routes, route_updates_tx, directive_sink, node_state through mode dispatch
76+
// REASON: threading metrics, peers, routes, route_updates_tx, command_sink, node_state through mode dispatch
7777
#[allow(clippy::too_many_arguments)]
7878
pub(crate) async fn run(
7979
global: &GlobalConfig,
@@ -82,7 +82,7 @@ pub(crate) async fn run(
8282
peers: Arc<Registry>,
8383
routes: SharedRouteTable,
8484
route_updates_tx: tokio::sync::broadcast::Sender<RouteUpdate>,
85-
directive_sink: tokio::sync::mpsc::Receiver<wallhack_core::control::handler::NodeCommand>,
85+
command_sink: tokio::sync::mpsc::Receiver<wallhack_core::control::handler::NodeCommand>,
8686
node_state: SharedNodeState,
8787
) -> Result<(), NodeError> {
8888
let tun_capable = detect_tun_capable();
@@ -144,13 +144,13 @@ pub(crate) async fn run(
144144
}
145145
(Some(connect), None) => {
146146
// Connector-only path: run the connector as a task and poll
147-
// directive_sink for dynamic listen/disconnect commands.
148-
run_auto_connector_with_commands(Arc::clone(&ctx), connect, directive_sink).await
147+
// command_sink for dynamic listen/disconnect commands.
148+
run_auto_connector_with_commands(Arc::clone(&ctx), connect, command_sink).await
149149
}
150150
(None, Some(listen)) => {
151151
// Listener-only path: run the listener as a task and poll
152-
// directive_sink for dynamic connect/disconnect commands.
153-
run_auto_listener_with_commands(Arc::clone(&ctx), listen, directive_sink).await
152+
// command_sink for dynamic connect/disconnect commands.
153+
run_auto_listener_with_commands(Arc::clone(&ctx), listen, command_sink).await
154154
}
155155
(None, None) => Err(NodeError::Config(
156156
"auto mode requires a connect or listen address".into(),
@@ -160,15 +160,15 @@ pub(crate) async fn run(
160160

161161
/// Connector-only path with command integration.
162162
///
163-
/// Spawns the connector as a task, then polls `directive_sink` for dynamic
163+
/// Spawns the connector as a task, then polls `command_sink` for dynamic
164164
/// commands. `Listen` commands start a listener task alongside the
165165
/// connector. `Disconnect` commands abort the active connector.
166166
// REASON: too_many_lines: symmetric listen/connect/disconnect command arms with distinct spawn logic
167167
#[allow(clippy::too_many_lines)]
168168
async fn run_auto_connector_with_commands(
169169
ctx: Arc<AutoContext>,
170170
connect: &AddressSpec,
171-
mut directive_sink: tokio::sync::mpsc::Receiver<wallhack_core::control::handler::NodeCommand>,
171+
mut command_sink: tokio::sync::mpsc::Receiver<wallhack_core::control::handler::NodeCommand>,
172172
) -> Result<(), NodeError> {
173173
use wallhack_core::{control::handler::NodeCommand, node_api::NodeApiError};
174174

@@ -203,7 +203,7 @@ async fn run_auto_connector_with_commands(
203203
}
204204
return result?;
205205
}
206-
Some(cmd) = directive_sink.recv() => {
206+
Some(cmd) = command_sink.recv() => {
207207
match cmd {
208208
NodeCommand::Role { .. } => {
209209
// Role changes not yet handled in connector path.
@@ -248,15 +248,15 @@ async fn run_auto_connector_with_commands(
248248

249249
/// Listener-only path with command integration.
250250
///
251-
/// Spawns the listener as a task, then polls `directive_sink` for dynamic
251+
/// Spawns the listener as a task, then polls `command_sink` for dynamic
252252
/// commands. `Connect` commands spawn a connector task alongside the
253253
/// listener. `Disconnect` commands abort the active connector.
254254
// REASON: too_many_lines: symmetric connect/listen/disconnect command arms with distinct spawn logic
255255
#[allow(clippy::too_many_lines)]
256256
async fn run_auto_listener_with_commands(
257257
ctx: Arc<AutoContext>,
258258
listen: &AddressSpec,
259-
mut directive_sink: tokio::sync::mpsc::Receiver<wallhack_core::control::handler::NodeCommand>,
259+
mut command_sink: tokio::sync::mpsc::Receiver<wallhack_core::control::handler::NodeCommand>,
260260
) -> Result<(), NodeError> {
261261
use wallhack_core::{control::handler::NodeCommand, node_api::NodeApiError};
262262

@@ -291,7 +291,7 @@ async fn run_auto_listener_with_commands(
291291
}
292292
return result?;
293293
}
294-
Some(cmd) = directive_sink.recv() => {
294+
Some(cmd) = command_sink.recv() => {
295295
match cmd {
296296
NodeCommand::Role { .. } => {
297297
// Role changes not yet handled in listener path.

crates/daemon/src/mode/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) struct NodeResources {
3232
pub node_state: SharedNodeState,
3333
/// Receiver for commands (role, connect, listen, disconnect) from the
3434
/// control API. Only auto mode consumes this.
35-
pub directive_sink: tokio::sync::mpsc::Receiver<wallhack_core::control::handler::NodeCommand>,
35+
pub command_sink: tokio::sync::mpsc::Receiver<wallhack_core::control::handler::NodeCommand>,
3636
}
3737

3838
/// Derive a peer's role from its advertised capabilities.
@@ -163,7 +163,7 @@ pub(crate) async fn run(config: &DaemonConfig, resources: NodeResources) -> Resu
163163
resources.peers,
164164
resources.routes,
165165
resources.route_updates_tx,
166-
resources.directive_sink,
166+
resources.command_sink,
167167
resources.node_state,
168168
)
169169
.await

0 commit comments

Comments
 (0)