Skip to content
Merged
Show file tree
Hide file tree
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
69 changes: 69 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/dtn7/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ dtn7-codegen = { path = "../codegen", version = "0.1.2" }
sha1 = "0.10.5"
glob-match = "0.2.1"
tower-http = { version = "0.3.4", features = ["cors"] }
mdns-sd = "0.11"

[lib]
name = "dtn7"
Expand Down
15 changes: 14 additions & 1 deletion core/dtn7/src/bin/dtnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ async fn main() -> Result<(), std::io::Error> {
.help("Sets listening port for IPND node discovery (default = 3003)")
.value_parser(value_parser!(u16))
.action(ArgAction::Set),
).arg(
)
.arg(
Arg::new("discoverytransport")
.long("discovery-transport")
.value_name("TRANSPORT")
.help("Sets discovery transport: udp-multicast (default), mdns, or both")
.value_parser(value_parser!(String))
.action(ArgAction::Set),
)
.arg(
Arg::new("webport")
.short('w')
.long("web-port")
Expand Down Expand Up @@ -354,6 +363,10 @@ Tag 255 takes 5 arguments and is interpreted as address. Usage: -S 255:'Samplest
if let Some(i) = matches.get_one::<u16>("discoveryport") {
cfg.discovery_listen_port = *i;
}
if let Some(transport) = matches.get_one::<String>("discoverytransport") {
cfg.discovery_transport = transport.parse()
.expect("Invalid discovery transport! Use: udp-multicast, mdns, or both");
}
Comment on lines +366 to +369
if let Some(i) = matches.get_one::<u16>("webport") {
cfg.webport = *i;
}
Expand Down
43 changes: 42 additions & 1 deletion core/dtn7/src/dtnconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,44 @@ use config::{Config, File};
use log::{debug, error};
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use serde::Serialize;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;
use std::{convert::TryInto, time::Duration};

/// Discovery transport mechanism
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum DiscoveryTransport {
/// UDP multicast (legacy IPND)
UdpMulticast,
/// mDNS/DNS-SD service discovery
Mdns,
/// Both UDP multicast and mDNS simultaneously
Both,
}

impl Default for DiscoveryTransport {
fn default() -> Self {
Self::UdpMulticast
}
}

impl FromStr for DiscoveryTransport {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"udp-multicast" | "udp" => Ok(Self::UdpMulticast),
"mdns" | "dns-sd" => Ok(Self::Mdns),
"both" => Ok(Self::Both),
_ => Err(format!("Unknown discovery transport: {}", s)),
}
}
}

#[derive(Debug, Default, Clone, Serialize)]
pub struct DtnConfig {
pub debug: bool,
Expand All @@ -26,6 +57,7 @@ pub struct DtnConfig {
pub webport: u16,
pub announcement_interval: Duration,
pub disable_neighbour_discovery: bool,
pub discovery_transport: DiscoveryTransport,
pub discovery_destinations: BTreeMap<String, u32>,
pub discovery_listen_port: u16,
pub janitor_interval: Duration,
Expand Down Expand Up @@ -156,6 +188,13 @@ impl From<PathBuf> for DtnConfig {
};
debug!("discovery-interval: {:?}", dtncfg.announcement_interval);

dtncfg.discovery_transport = if let Ok(transport) = s.get_string("discovery.transport") {
DiscoveryTransport::from_str(&transport).unwrap_or_default()
} else {
dtncfg.discovery_transport
};
debug!("discovery-transport: {:?}", dtncfg.discovery_transport);
Comment on lines +191 to +196

dtncfg.peer_timeout = if let Ok(interval) = s.get_string("discovery.peer-timeout") {
humantime::parse_duration(&interval).unwrap_or_else(|_| Duration::new(0, 0))
} else {
Expand Down Expand Up @@ -277,6 +316,7 @@ impl DtnConfig {
host_eid: local_node_id,
announcement_interval: "2s".parse::<humantime::Duration>().unwrap().into(),
disable_neighbour_discovery: false,
discovery_transport: DiscoveryTransport::default(),
discovery_destinations: BTreeMap::new(),
discovery_listen_port: 3003,
webport: 3000,
Expand Down Expand Up @@ -309,6 +349,7 @@ impl DtnConfig {
self.webport = cfg.webport;
self.announcement_interval = cfg.announcement_interval;
self.disable_neighbour_discovery = cfg.disable_neighbour_discovery;
self.discovery_transport = cfg.discovery_transport;
self.discovery_destinations = cfg.discovery_destinations;
self.discovery_listen_port = cfg.discovery_listen_port;
self.janitor_interval = cfg.janitor_interval;
Expand Down
Loading