Skip to content

Commit 65c5390

Browse files
committed
docs: improve docs and logs
1 parent 591e5aa commit 65c5390

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

iroh-relay/src/main.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::{
1111

1212
use anyhow::{bail, Context as _, Result};
1313
use clap::Parser;
14+
use http::StatusCode;
1415
use iroh_base::NodeId;
1516
use iroh_relay::{
1617
defaults::{
@@ -184,8 +185,8 @@ enum AccessConfig {
184185
Denylist(Vec<NodeId>),
185186
/// Performs a HTTP POST request to determine access for each node that connects to the relay.
186187
///
187-
/// The string value is used as the URL template, where `{node_id}` will be replaced
188-
/// with the hex-encoded node id that is connecting.
188+
/// The request will have a header `X-Iroh-Node-Id` set to the hex-encoded node id attempting
189+
/// to connect to the relay.
189190
///
190191
/// To grant access, the HTTP endpoint must return a `200` response with `true` as the response text.
191192
/// In all other cases, the node will be denied access.
@@ -243,7 +244,7 @@ async fn http_access_check(
243244
node_id: NodeId,
244245
) -> iroh_relay::server::Access {
245246
use iroh_relay::server::Access;
246-
debug!(%url, "check relay access via HTTP POST");
247+
debug!(%url, "Check relay access via HTTP POST");
247248
let res = match client
248249
.post(url)
249250
.header("X-Iroh-NodeId", node_id.to_string())
@@ -252,28 +253,28 @@ async fn http_access_check(
252253
{
253254
Ok(t) => t,
254255
Err(err) => {
255-
warn!("request failed: {err}");
256+
warn!("HTTP access check failed to retrieve response: {err}");
256257
return Access::Deny;
257258
}
258259
};
259-
if res.status().is_success() {
260+
if res.status() == StatusCode::OK {
260261
match res.text().await {
261-
Err(err) => {
262-
warn!("failed to read response: {err}");
263-
Access::Deny
264-
}
265262
Ok(text) if text == "true" => {
266-
debug!("request successfull: grant access");
263+
debug!("HTTP access check successful: grant access.");
267264
Access::Allow
268265
}
269266
Ok(_) => {
270-
warn!("request successfull but response text is not `true`: deny access");
267+
warn!("HTTP access check return invalid response text: deny access.");
268+
Access::Deny
269+
}
270+
Err(err) => {
271+
warn!("HTTP access check failed to read response: {err}");
271272
Access::Deny
272273
}
273274
}
274275
} else {
275276
debug!(
276-
"request returned non-success code {}: deny access",
277+
"HTTP access check response has status code {}: deny access",
277278
res.status()
278279
);
279280
Access::Deny

0 commit comments

Comments
 (0)