Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dtnrecv): dtnrecv now supports dynamically (un)registering of local endpoints #65

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions core/dtn7/src/bin/dtnrecv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// 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<String>,

/// 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<String>,

/// 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<String>,

/// 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<String>,

/// Write bundle payload to file instead of stdout
Expand Down Expand Up @@ -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?{}",
Expand All @@ -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 {
Expand Down
Loading