Skip to content

Commit 7582823

Browse files
maxholmanclaude
andcommitted
refactor: align internal Rust names with proto/CLI naming convention
NodeApi trait methods, handler structs, and REST/MCP function names now follow the same noun-verb pattern used by the management protocol and CLI/REPL (e.g. hint_set, route_del, peer_disconnect). OpenAPI operationIds updated to match (e.g. peersList, peerDisconnect, infoGet). Stale comments referencing old names cleaned up. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1e3c21b commit 7582823

8 files changed

Lines changed: 60 additions & 60 deletions

File tree

crates/api/src/handlers.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ pub struct StatsResponse {
2929
pub active_flows: u64,
3030
}
3131

32-
/// Node status response.
32+
/// Node info response.
3333
#[derive(Debug, Serialize)]
34-
pub struct StatusResponse {
34+
pub struct InfoResponse {
3535
pub name: String,
3636
pub version: String,
3737
pub role: String,
@@ -133,9 +133,9 @@ pub struct PingResponseBody {
133133
pub role: String,
134134
}
135135

136-
/// Set hint request body.
136+
/// Hint set request body.
137137
#[derive(Debug, Deserialize)]
138-
pub struct SetHintRequestBody {
138+
pub struct HintSetRequestBody {
139139
pub level: String,
140140
pub role: String,
141141
}
@@ -183,7 +183,7 @@ pub async fn events(
183183
)
184184
}
185185

186-
pub async fn info(State(state): State<ApiState>) -> Result<Json<StatusResponse>, StatusCode> {
186+
pub async fn info(State(state): State<ApiState>) -> Result<Json<InfoResponse>, StatusCode> {
187187
let resp = state
188188
.ipc
189189
.lock()
@@ -195,7 +195,7 @@ pub async fn info(State(state): State<ApiState>) -> Result<Json<StatusResponse>,
195195
match resp.response {
196196
Some(management_response::Response::Info(s)) => {
197197
let role = s.role().to_string();
198-
Ok(Json(StatusResponse {
198+
Ok(Json(InfoResponse {
199199
name: s.package_name,
200200
version: s.version,
201201
role,
@@ -280,7 +280,7 @@ pub async fn peers(State(state): State<ApiState>) -> Result<Json<PeersResponse>,
280280
}
281281
}
282282

283-
pub async fn disconnect_peer(
283+
pub async fn peer_disconnect(
284284
State(state): State<ApiState>,
285285
Path(name): Path<String>,
286286
) -> (StatusCode, Json<SuccessResponse>) {
@@ -644,7 +644,7 @@ pub async fn ping(State(state): State<ApiState>) -> Result<Json<PingResponseBody
644644
}
645645
}
646646

647-
pub async fn ping_peer(
647+
pub async fn peer_ping(
648648
State(state): State<ApiState>,
649649
Path(peer): Path<String>,
650650
) -> Result<Json<PingResponseBody>, StatusCode> {
@@ -704,9 +704,9 @@ pub async fn shutdown(State(state): State<ApiState>) -> (StatusCode, Json<Succes
704704
}
705705
}
706706

707-
pub async fn set_hint(
707+
pub async fn hint_set(
708708
State(state): State<ApiState>,
709-
Json(req): Json<SetHintRequestBody>,
709+
Json(req): Json<HintSetRequestBody>,
710710
) -> (StatusCode, Json<SuccessResponse>) {
711711
let level = match req.level.as_str() {
712712
"prefer" => HintLevel::Prefer,
@@ -787,7 +787,7 @@ pub async fn set_hint(
787787
}
788788
}
789789

790-
pub async fn clear_hints(State(state): State<ApiState>) -> (StatusCode, Json<SuccessResponse>) {
790+
pub async fn hint_set_auto(State(state): State<ApiState>) -> (StatusCode, Json<SuccessResponse>) {
791791
let resp = state
792792
.ipc
793793
.lock()

crates/api/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn router(state: State) -> Router {
6565
.route("/info", get(handlers::info))
6666
.route("/stats", get(handlers::stats))
6767
.route("/peers", get(handlers::peers))
68-
.route("/peers/{name}", delete(handlers::disconnect_peer))
68+
.route("/peers/{name}", delete(handlers::peer_disconnect))
6969
.route(
7070
"/routes",
7171
get(handlers::list_routes).post(handlers::add_route),
@@ -76,11 +76,11 @@ pub fn router(state: State) -> Router {
7676
.route("/listen", post(handlers::listen))
7777
.route("/disconnect", post(handlers::disconnect))
7878
.route("/ping", get(handlers::ping))
79-
.route("/ping/{peer}", get(handlers::ping_peer))
79+
.route("/ping/{peer}", get(handlers::peer_ping))
8080
.route("/shutdown", post(handlers::shutdown))
8181
.route(
8282
"/hints",
83-
put(handlers::set_hint).delete(handlers::clear_hints),
83+
put(handlers::hint_set).delete(handlers::hint_set_auto),
8484
)
8585
.layer(middleware::from_fn(move |req, next| {
8686
let auth = auth.clone();

crates/core/src/control/handler.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ struct NodeState {
3333
/// Shared node state handle, cloneable and cheaply updatable.
3434
///
3535
/// Consumers call [`SharedNodeState::update_role`], [`SharedNodeState::update_capabilities`],
36-
/// etc. after negotiation or listening starts so that `wallhack info` /
37-
/// `wallhack_status` reflects the real state of the daemon.
36+
/// etc. after negotiation or listening starts so that `wallhack info`
37+
/// reflects the real state of the daemon.
3838
#[derive(Clone, Debug)]
3939
pub struct SharedNodeState(Arc<ArcSwap<NodeState>>);
4040

@@ -148,7 +148,7 @@ impl Handler {
148148
/// Returns a handle to the shared node state.
149149
///
150150
/// Callers (daemon modes) use this to update role, capabilities, and
151-
/// listen/connect state after negotiation so that `status()` reports
151+
/// listen/connect state after negotiation so that `info()` reports
152152
/// accurate information.
153153
#[must_use]
154154
pub fn node_state(&self) -> SharedNodeState {
@@ -396,9 +396,9 @@ impl crate::node_api::NodeApi for Handler {
396396
self.metrics.snapshot()
397397
}
398398

399-
fn status(&self) -> crate::node_api::NodeStatus {
399+
fn info(&self) -> crate::node_api::NodeInfo {
400400
let state = self.state.load();
401-
crate::node_api::NodeStatus {
401+
crate::node_api::NodeInfo {
402402
role: state.role,
403403
peer_addr: state.peer_addr.clone(),
404404
capabilities: state.capabilities,
@@ -441,7 +441,7 @@ impl crate::node_api::NodeApi for Handler {
441441
Ok(())
442442
}
443443

444-
fn remove_route(&self, cidr: &crate::Cidr) -> crate::node_api::Result<()> {
444+
fn route_del(&self, cidr: &crate::Cidr) -> crate::node_api::Result<()> {
445445
if let Some(entry) = self.routes.remove(cidr) {
446446
let _ = self
447447
.route_updates
@@ -452,7 +452,7 @@ impl crate::node_api::NodeApi for Handler {
452452
}
453453
}
454454

455-
fn disconnect_peer(&self, peer: String) -> crate::node_api::Result<()> {
455+
fn peer_disconnect(&self, peer: String) -> crate::node_api::Result<()> {
456456
// Try name prefix first, then fall back to exact address match.
457457
// Used by REPL/CLI where prefix matching is convenient.
458458
let peer_info = self.peers.find_by_prefix(&peer).or_else(|e| {
@@ -467,7 +467,7 @@ impl crate::node_api::NodeApi for Handler {
467467
Ok(())
468468
}
469469

470-
fn disconnect_peer_by_id(&self, id: String) -> crate::node_api::Result<()> {
470+
fn peer_disconnect_by_id(&self, id: String) -> crate::node_api::Result<()> {
471471
// Exact match on registry key. Used by REST API where the id
472472
// is taken directly from the peers list.
473473
if self.peers.get(&id).is_none() {
@@ -481,12 +481,12 @@ impl crate::node_api::NodeApi for Handler {
481481
self.state.load().role
482482
}
483483

484-
fn set_hint(&self, hint: RoleHint) -> crate::node_api::Result<()> {
484+
fn hint_set(&self, hint: RoleHint) -> crate::node_api::Result<()> {
485485
self.hint_tx.send_replace(Some(hint));
486486
Ok(())
487487
}
488488

489-
fn clear_hints(&self) -> crate::node_api::Result<()> {
489+
fn hint_set_auto(&self) -> crate::node_api::Result<()> {
490490
self.hint_tx.send_replace(None);
491491
Ok(())
492492
}
@@ -738,7 +738,7 @@ mod tests {
738738
}
739739

740740
#[test]
741-
fn test_status_indeterminate_role() {
741+
fn test_info_indeterminate_role() {
742742
let metrics = Arc::new(Metrics::default());
743743
let peers = Arc::new(Registry::new());
744744
let routes = RouteTable::shared();
@@ -754,7 +754,7 @@ mod tests {
754754
tokio::sync::broadcast::channel(16).0,
755755
);
756756

757-
let status = crate::node_api::NodeApi::status(&handler);
757+
let status = crate::node_api::NodeApi::info(&handler);
758758
assert_eq!(status.role, NodeRole::Indeterminate);
759759
}
760760

@@ -795,7 +795,7 @@ mod tests {
795795
}
796796

797797
#[test]
798-
fn test_status_reflects_node_state_updates() {
798+
fn test_info_reflects_node_state_updates() {
799799
let handler = Handler::new(
800800
HandlerConfig::new(
801801
NodeRole::Indeterminate,
@@ -809,7 +809,7 @@ mod tests {
809809
);
810810

811811
// Initially indeterminate with no capabilities.
812-
let status = crate::node_api::NodeApi::status(&handler);
812+
let status = crate::node_api::NodeApi::info(&handler);
813813
assert_eq!(status.role, NodeRole::Indeterminate);
814814
assert!(!status.capabilities.tun_capable);
815815
assert!(!status.capabilities.listening);
@@ -825,15 +825,15 @@ mod tests {
825825
interactive: false,
826826
});
827827

828-
let status = crate::node_api::NodeApi::status(&handler);
828+
let status = crate::node_api::NodeApi::info(&handler);
829829
assert_eq!(status.role, NodeRole::Entry);
830830
assert!(status.capabilities.tun_capable);
831831

832832
// Simulate listen address being set.
833833
let addr: SocketAddr = "0.0.0.0:4433".parse().unwrap();
834834
state.set_listen_addr(addr);
835835

836-
let status = crate::node_api::NodeApi::status(&handler);
836+
let status = crate::node_api::NodeApi::info(&handler);
837837
assert_eq!(status.listen_addr, Some(addr));
838838
assert!(status.capabilities.listening);
839839
}

crates/core/src/ipc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn dispatch_request(request: &ManagementRequest, api: &dyn NodeApi) -> Managemen
290290
Some(management_request::Request::Ping(req)) => {
291291
if req.peer.is_empty() {
292292
// Ping the daemon itself
293-
let status = api.status();
293+
let status = api.info();
294294
management_response::Response::Ping(PingResponse {
295295
uptime_ms: status.uptime_ms,
296296
version: status.version,
@@ -309,7 +309,7 @@ fn dispatch_request(request: &ManagementRequest, api: &dyn NodeApi) -> Managemen
309309
}
310310

311311
Some(management_request::Request::Info(_)) => {
312-
let s = api.status();
312+
let s = api.info();
313313
management_response::Response::Info(InfoResponse {
314314
role: management::NodeRole::from(s.role).into(),
315315
connected: false, // deprecated — derive from peer count instead
@@ -366,7 +366,7 @@ fn dispatch_request(request: &ManagementRequest, api: &dyn NodeApi) -> Managemen
366366
},
367367

368368
Some(management_request::Request::RouteDel(req)) => match req.cidr.parse() {
369-
Ok(cidr) => match api.remove_route(&cidr) {
369+
Ok(cidr) => match api.route_del(&cidr) {
370370
Ok(()) => management_response::Response::Ok(OkResponse {}),
371371
Err(e) => error_response(&e),
372372
},
@@ -378,9 +378,9 @@ fn dispatch_request(request: &ManagementRequest, api: &dyn NodeApi) -> Managemen
378378

379379
Some(management_request::Request::PeerDisconnect(req)) => {
380380
let result = if req.exact {
381-
api.disconnect_peer_by_id(req.peer.clone())
381+
api.peer_disconnect_by_id(req.peer.clone())
382382
} else {
383-
api.disconnect_peer(req.peer.clone())
383+
api.peer_disconnect(req.peer.clone())
384384
};
385385
match result {
386386
Ok(()) => management_response::Response::Ok(OkResponse {}),
@@ -430,13 +430,13 @@ fn dispatch_request(request: &ManagementRequest, api: &dyn NodeApi) -> Managemen
430430
level: level.into(),
431431
target: target.into(),
432432
};
433-
match api.set_hint(hint) {
433+
match api.hint_set(hint) {
434434
Ok(()) => management_response::Response::Ok(OkResponse {}),
435435
Err(e) => error_response(&e),
436436
}
437437
}
438438

439-
Some(management_request::Request::HintSetAuto(_)) => match api.clear_hints() {
439+
Some(management_request::Request::HintSetAuto(_)) => match api.hint_set_auto() {
440440
Ok(()) => management_response::Response::Ok(OkResponse {}),
441441
Err(e) => error_response(&e),
442442
},

crates/core/src/node_api.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ pub struct Metrics {
8080
pub packets_dropped: u64,
8181
}
8282

83-
/// Overall node status information.
83+
/// Overall node info.
8484
#[derive(Debug, Clone)]
85-
pub struct NodeStatus {
85+
pub struct NodeInfo {
8686
/// Node's role.
8787
pub role: NodeRole,
8888
/// Peer address (if connected).
@@ -153,7 +153,7 @@ pub trait NodeApi: Send + Sync {
153153
/// Get list of directly connected peers.
154154
///
155155
/// For entry nodes: returns all connected exit/relay nodes.
156-
/// For exit nodes with relay capability: returns downstream connected nodes.
156+
/// For exit nodes with relay capability: returns accepted peer connections.
157157
/// For standard exit nodes: returns empty (no peers).
158158
fn peers(&self) -> Vec<PeerInfo>;
159159

@@ -165,8 +165,8 @@ pub trait NodeApi: Send + Sync {
165165
/// Get traffic and connection metrics.
166166
fn metrics(&self) -> Metrics;
167167

168-
/// Get overall node status.
169-
fn status(&self) -> NodeStatus;
168+
/// Get overall node info.
169+
fn info(&self) -> NodeInfo;
170170

171171
/// Connect to a peer.
172172
///
@@ -197,30 +197,30 @@ pub trait NodeApi: Send + Sync {
197197
/// Peer must be directly connected.
198198
fn add_route(&self, cidr: Cidr, peer: String) -> Result<()>;
199199

200-
/// Remove a route by CIDR.
200+
/// Delete a route by CIDR.
201201
///
202202
/// Only supported on entry nodes. Returns error for exit/relay nodes.
203-
fn remove_route(&self, cidr: &Cidr) -> Result<()>;
203+
fn route_del(&self, cidr: &Cidr) -> Result<()>;
204204

205205
/// Disconnect a specific peer by name prefix or address.
206206
///
207207
/// Supports prefix matching for REPL/CLI convenience.
208-
fn disconnect_peer(&self, peer: String) -> Result<()>;
208+
fn peer_disconnect(&self, peer: String) -> Result<()>;
209209

210210
/// Disconnect a specific peer by exact registry id.
211211
///
212212
/// Used by the REST API where the id comes directly from the peers list.
213-
fn disconnect_peer_by_id(&self, id: String) -> Result<()>;
213+
fn peer_disconnect_by_id(&self, id: String) -> Result<()>;
214214

215215
/// Get the current negotiated role.
216216
fn current_role(&self) -> NodeRole;
217217

218218
/// Apply a role hint at runtime.
219219
///
220220
/// Triggers re-negotiation if the node is in auto mode.
221-
/// `role <target>` in the REPL is shorthand for `set_hint(Fixed, target)`.
222-
fn set_hint(&self, hint: RoleHint) -> Result<()>;
221+
/// `role <target>` in the REPL is shorthand for `hint_set(Fixed, target)`.
222+
fn hint_set(&self, hint: RoleHint) -> Result<()>;
223223

224224
/// Remove all hints (both startup and runtime).
225-
fn clear_hints(&self) -> Result<()>;
225+
fn hint_set_auto(&self) -> Result<()>;
226226
}

crates/daemon/src/mode/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub(crate) fn spawn_heartbeat(
115115
peer_name: String,
116116
peers: Arc<Registry>,
117117
) -> tokio::task::JoinHandle<()> {
118-
// Register control channel so disconnect_peer can send messages to this peer.
118+
// Register control channel so peer_disconnect can send messages to this peer.
119119
peers.register_control(&peer_name, &control_tx);
120120

121121
tokio::spawn(async move {

crates/mcp/src/tools.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct AddrParams {
4242
}
4343

4444
#[derive(Debug, serde::Deserialize, schemars::JsonSchema)]
45-
pub struct SetHintParams {
45+
pub struct HintSetParams {
4646
/// Hint level: "prefer", "exclude", or "fixed"
4747
pub level: String,
4848
/// Target role: "entry", "exit", or "relay"
@@ -117,7 +117,7 @@ impl WallhackServer {
117117
.await
118118
}
119119

120-
#[tool(description = "Remove a route by CIDR")]
120+
#[tool(description = "Delete a route by CIDR")]
121121
async fn route_del(
122122
&self,
123123
Parameters(params): Parameters<RouteDelParams>,
@@ -183,7 +183,7 @@ impl WallhackServer {
183183
)]
184184
async fn hint_set(
185185
&self,
186-
Parameters(params): Parameters<SetHintParams>,
186+
Parameters(params): Parameters<HintSetParams>,
187187
) -> Result<String, rmcp::ErrorData> {
188188
let level = match params.level.as_str() {
189189
"prefer" => HintLevel::Prefer,

0 commit comments

Comments
 (0)