From 59bb9e0c9b66afb0feab57673a732689003c86a5 Mon Sep 17 00:00:00 2001 From: gh0st <1264131+gh0st42@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:57:06 +0100 Subject: [PATCH] feat(dtnrecv): dtnrecv now supports dynamically (un)registering of local endpoints --- core/dtn7/src/bin/dtnrecv.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/core/dtn7/src/bin/dtnrecv.rs b/core/dtn7/src/bin/dtnrecv.rs index d50a3114..dcf37d52 100644 --- a/core/dtn7/src/bin/dtnrecv.rs +++ b/core/dtn7/src/bin/dtnrecv.rs @@ -22,15 +22,23 @@ struct Args { verbose: bool, /// Specify local endpoint, e.g. 'incoming', or a group endpoint 'dtn://helpers/~incoming' - #[clap(short, long, required_unless_present_any = ["bid", "delete"], conflicts_with_all = ["bid", "delete"])] + #[clap(short, long, required_unless_present_any = ["bid", "delete", "register", "unregister"], conflicts_with_all = ["bid", "delete", "register", "unregister"])] endpoint: Option, + /// Register a local endpoint, e.g. 'incoming', or a group endpoint 'dtn://helpers/~incoming' + #[clap(short, long, required_unless_present_any = ["bid", "delete", "endpoint", "unregister"], conflicts_with_all = ["bid", "delete", "endpoint", "unregister"], value_name = "ENDPOINT")] + register: Option, + + /// Unregister a local endpoint, e.g. 'incoming', or a group endpoint 'dtn://helpers/~incoming' + #[clap(short, long, required_unless_present_any = ["bid", "delete", "endpoint", "register"], conflicts_with_all = ["bid", "delete", "endpoint", "unregister"], value_name = "ENDPOINT")] + unregister: Option, + /// Download any bundle by its ID - #[clap(short, long, required_unless_present_any = ["endpoint", "delete"])] + #[clap(short, long, required_unless_present_any = ["endpoint", "delete", "register", "unregister"], conflicts_with_all = ["endpoint", "delete", "register", "unregister"])] bid: Option, /// Delete any bundle by its ID - #[clap(short, long, required_unless_present_any = ["endpoint", "bid"], value_name = "BID")] + #[clap(short, long, required_unless_present_any = ["endpoint", "bid", "register", "unregister"], conflicts_with_all = ["endpoint", "bid", "register", "unregister"], value_name = "BID")] delete: Option, /// Write bundle payload to file instead of stdout @@ -79,6 +87,20 @@ fn main() { port, args.delete.clone().unwrap() ) + } else if args.register.is_some() { + format!( + "http://{}:{}/register?{}", + localhost, + port, + args.register.clone().unwrap() + ) + } else if args.unregister.is_some() { + format!( + "http://{}:{}/unregister?{}", + localhost, + port, + args.unregister.clone().unwrap() + ) } else { format!( "http://{}:{}/download?{}", @@ -101,6 +123,12 @@ fn main() { if args.delete.is_some() { println!("Deleted bundle {}", args.delete.unwrap()); process::exit(0); + } else if args.register.is_some() { + println!("Registered endpoint {}", args.register.unwrap()); + process::exit(0); + } else if args.unregister.is_some() { + println!("Unregistered endpoint {}", args.unregister.unwrap()); + process::exit(0); } else if buf.len() > 50 { // TODO: very arbitrary number, should check return code if args.hex {