Skip to content

Commit cf48ed4

Browse files
committed
feat: send HTTP api call now also supports setting the bundle processing control flags
1 parent c6ed484 commit cf48ed4

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

core/dtn7/src/dtnd/httpd.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,21 +467,33 @@ async fn send_post(
467467
) -> Result<String, (StatusCode, &'static str)> {
468468
let mut dst: EndpointID = EndpointID::none();
469469
let mut lifetime = std::time::Duration::from_secs(60 * 60);
470+
let mut flags = BundleControlFlags::BUNDLE_MUST_NOT_FRAGMENTED;
471+
// | BundleControlFlags::BUNDLE_STATUS_REQUEST_DELIVERY;
472+
470473
for (k, v) in query_params.iter() {
471474
if k == "dst" {
472475
dst = v.as_str().try_into().unwrap();
473476
} else if k == "lifetime" {
474477
if let Ok(dur) = humantime::parse_duration(v) {
475478
lifetime = dur;
476479
}
480+
} else if k == "flags" {
481+
let param_flags: u64 = v.as_str().parse().unwrap_or(0);
482+
if let Some(bpcf) = BundleControlFlags::from_bits(param_flags) {
483+
flags = bpcf;
484+
} else {
485+
return Err((
486+
StatusCode::BAD_REQUEST,
487+
"Invalid Bundle Processing Control Flags!",
488+
));
489+
}
477490
}
478491
}
479492
if dst == EndpointID::none() {
480493
return Err((StatusCode::BAD_REQUEST, "Missing destination endpoint id!"));
481494
}
482495
let src = CONFIG.lock().host_eid.clone();
483-
let flags = BundleControlFlags::BUNDLE_MUST_NOT_FRAGMENTED
484-
| BundleControlFlags::BUNDLE_STATUS_REQUEST_DELIVERY;
496+
485497
let pblock = bp7::primary::PrimaryBlockBuilder::default()
486498
.bundle_control_flags(flags.bits())
487499
.destination(dst)
@@ -508,12 +520,12 @@ async fn send_post(
508520

509521
debug!(
510522
"Sending bundle {} to {}",
511-
bndl.id(),
523+
&bndl.id(),
512524
bndl.primary.destination
513525
);
514-
526+
let bid = bndl.id();
515527
crate::core::processing::send_bundle(bndl).await;
516-
Ok(format!("Sent payload with {} bytes", b_len))
528+
Ok(format!("Sent ADU in bundle {} with {} bytes", bid, b_len))
517529
}
518530

519531
//#[post("/push")]

core/dtn7/src/dtnd/ws.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ impl WsAASession {
363363
}
364364
}
365365
WsReceiveMode::Data(format) => {
366+
// TODO: make BPCF configurable via WsSendData
366367
let send_data = match format {
367368
DataReceiveFormat::CBOR => serde_cbor::from_slice::<WsSendData>(&bin)
368369
.map_err(|_| "error parsing cbor"),

doc/http-client-api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ This is meant to be viewed with a standard web browser such as firefox, chrome,
1616

1717
These API endpoints can only be called from localhost for security reasons.
1818

19-
### **POST** `/send?dst=<EID>&lifetime=<LIFETIME>`
19+
### **POST** `/send?dst=<EID>&lifetime=<LIFETIME>&flags=<BPCF>`
2020

2121
Construct a new bundle with the given parameters.
2222
The bundle payload is sent as the body of the *POST* request.
2323
The URL parameters `dst` and `lifetime` are used to set the corresponding bundle fields.
24+
The [Bundle Processing Control Flags](https://www.rfc-editor.org/rfc/rfc9171.html#name-bundle-processing-control-f) can be set as an unsigned integer via the `flags` parameter.
2425

2526
```
2627
$ curl -X POST -d 'hello world' "http://127.0.0.1:3000/send?dst=dtn://node3/incoming&lifetime=5m"

0 commit comments

Comments
 (0)