61 releases

new 0.6.4 Aug 2, 2020
0.6.3 Jul 18, 2020
0.6.2 May 4, 2020
0.6.1 Mar 21, 2020
0.3.7 Jul 29, 2019

#62 in Encoding

Download history 263/week @ 2020-04-14 25/week @ 2020-04-21 13/week @ 2020-04-28 10/week @ 2020-05-05 9/week @ 2020-05-12 5/week @ 2020-05-19 120/week @ 2020-05-26 131/week @ 2020-06-02 4/week @ 2020-06-09 60/week @ 2020-06-16 3/week @ 2020-06-23 60/week @ 2020-06-30 59/week @ 2020-07-07 136/week @ 2020-07-14 35/week @ 2020-07-21 27/week @ 2020-07-28

216 downloads per month
Used in 2 crates

MIT/Apache

105KB
2K SLoC

bp7-rs

Crates.io Docs.rs Build status License: MIT License: Apache 2.0

Rust implementation of dtn bundle protocol 7 draft https://tools.ietf.org/html/draft-ietf-dtn-bpbis-20

This library only handles encoding and decoding of bundles, not transmission or other processing of the data. A full daemon using this library can be found here: https://github.com/dtn7/dtn7-rs

This code is (probably) not production ready!

Benchmarking

A simple benchmark is shipped with the library. It (de)serializes Bundles with a primary block, bundle age block and a payload block with the contents (b"ABC"). This benchmark can be used to compare the rust implementation to the golang, python or java implementations.

cargo run --release --example benchmark
    Finished release [optimized] target(s) in 0.29s
     Running `target/release/examples/benchmark`
Creating 100000 bundles with CRC_NO: 	510059 bundles/second
Creating 100000 bundles with CRC_16: 	293399 bundles/second
Creating 100000 bundles with CRC_32: 	291399 bundles/second
Encoding 100000 bundles with CRC_NO: 	1090996 bundles/second
Encoding 100000 bundles with CRC_16: 	436836 bundles/second
Encoding 100000 bundles with CRC_32: 	432774 bundles/second
Loading 100000 bundles with CRC_NO: 	564817 bundles/second
Loading 100000 bundles with CRC_16: 	473768 bundles/second
Loading 100000 bundles with CRC_32: 	462013 bundles/second

These numbers were generated on a MBP 13" 2018 with i5 CPU and 16GB of ram.

bp7 helper tool

For debugging a small helper tool is shipped:

$ cargo install bp7
[...]
$ usage "bp7" <cmd> [args]
	 decode <hexstring>
	 dtntime [dtntimestamp] - prints current time as dtntimestamp or prints dtntime human readable
	 d2u [dtntimestamp] - converts dtntime to unixstimestamp
	 rnd - return a hexencoded random bundle
$ bp7 rnd
9f8907000182016b6e6f6465332f696e626f7882016b6e6f6465332f696e626f7882016b6e6f6465332f696e626f78821a247966ba001ad693a4004225b686010000014341424342237186080100010042dbccff

$ bp7 decode 9f8907000182016b6e6f6465332f696e626f7882016b6e6f6465332f696e626f7882016b6e6f6465332f696e626f78821a247966ba001ad693a4004225b686010000014341424342237186080100010042dbccff

[src/main.rs:17] &bndl = Bundle {
    primary: PrimaryBlock {
        version: 7,
        bundle_control_flags: 0,
        crc_type: 1,
        destination: Dtn(
            1,
            "node3/inbox"
        ),
        source: Dtn(
            1,
            "node3/inbox"
        ),
        report_to: Dtn(
            1,
            "node3/inbox"
        ),
        creation_timestamp: CreationTimestamp(
            611935930,
            0
        ),
        lifetime: 3600000000,
        fragmentation_offset: 0,
        total_data_length: 0,
        crc: [
            37,
            182
        ]
    },
    canonicals: [
        CanonicalBlock {
            block_type: 1,
            block_number: 0,
            block_control_flags: 0,
            crc_type: 1,
            data: Data(
                [
                    65,
                    66,
                    67
                ]
            ),
            crc: [
                35,
                113
            ]
        },
        CanonicalBlock {
            block_type: 8,
            block_number: 1,
            block_control_flags: 0,
            crc_type: 1,
            data: BundleAge(
                0
            ),
            crc: [
                219,
                204
            ]
        }
    ]
}

The generated hex string can also be directly discplayed as raw cbor on the awesome cbor.me website, e.g. http://cbor.me/?bytes=9f8907000182016b6e6f6465332f696e626f7882016b6e6f6465332f696e626f7882016b6e6f6465332f696e626f78821a247966ba001ad693a4004225b686010000014341424342237186080100010042dbccff

wasm support

The library should build for wasm even though only very few functions get exported. The example benchmark can also be used in the browser through the cargo-web crate:

cargo web start --target wasm32-unknown-unknown --example benchmark --release

Results should be shown in the javascript console on http://127.0.0.1:8000.

The performance is quite similar to the native performance:

Creating 100000 bundles with CRC_NO: 	441696 bundles/second
Creating 100000 bundles with CRC_16: 	416484 bundles/second
Creating 100000 bundles with CRC_32: 	405022 bundles/second
Encoding 100000 bundles with CRC_NO: 	1647039 bundles/second
Encoding 100000 bundles with CRC_16: 	908059 bundles/second
Encoding 100000 bundles with CRC_32: 	867603 bundles/second
Loading 100000 bundles with CRC_NO: 	401727 bundles/second
Loading 100000 bundles with CRC_16: 	388394 bundles/second
Loading 100000 bundles with CRC_32: 	384186 bundles/second

Some functions can easily be used from javascript (cargo web deploy --release):

Rust.bp7.then(function(bp7) {
  var b = bp7.rnd_bundle_now(); 
  var enc = bp7.encode_to_cbor(b); 
  var payload = bp7.payload_from_bundle(b)
  console.log(payload); 
  console.log(String.fromCharCode.apply(null, payload));
  console.log(bp7.cbor_is_administrative_record(enc)); 
  console.log(bp7.sender_from_cbor(enc)); 
  console.log(bp7.recipient_from_bundle(b)); 
  console.log(bp7.valid_bundle(b)); 
});

Note that at the moment all functions have a variant working on the binary bundle and one working on the decoded bundle struct.

Acknowledging this work

If you use this software in a scientific publication, please cite the following paper:

@INPROCEEDINGS{baumgaertner2019bdtn7,
  author={L. {Baumgärtner} and J. {Höchst} and T. {Meuser}},
  booktitle={2019 International Conference on Information and Communication Technologies for Disaster Management (ICT-DM)},
  title={B-DTN7: Browser-based Disruption-tolerant Networking via Bundle Protocol 7},
  year={2019},
  volume={},
  number={},
  pages={1-8},
  keywords={Protocols;Browsers;Software;Convergence;Servers;Synchronization;Wireless fidelity},
  doi={10.1109/ICT-DM47966.2019.9032944},
  ISSN={2469-8822},
  month={Dec},
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in bp7-rs by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.6–2.6MB
~56K SLoC