Skip to content

Commit

Permalink
Allow configuring the timer values in the RTR targets. (#106)
Browse files Browse the repository at this point in the history
This PR adds three optional configuration values to the RTR target
configuration that allow configuring the timer values included in an RTR
exchange.
  • Loading branch information
partim authored Apr 10, 2024
1 parent a6df70e commit 01331a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions doc/manual/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ from.
listen = [ "127.0.0.1:9001" ]
unit = "source-unit-name"
The three optional configuration options ``refresh``, ``retry`` and ``expire``
allow setting the respective fields in the timer values sent to the client.
If they are missing, the default values are used.

This target also supports TLS connections, via the ``rtr-tls`` type. This target
has two additional configuration options. First, the :option:`certificate`
option, which is a string value providing a path to a file containing the
Expand Down
39 changes: 32 additions & 7 deletions src/targets/rtr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ pub struct Tcp {
#[serde(default = "Tcp::default_history_size")]
#[serde(rename = "history-size")]
history_size: usize,

/// The RTR refresh interval.
refresh: Option<u32>,

/// The RTR retry interval.
retry: Option<u32>,

/// The RTR expire interval.
expire: Option<u32>,
}

impl Tcp {
Expand All @@ -54,7 +63,8 @@ impl Tcp {
/// Runs the target.
pub async fn run(self, component: Component) -> Result<(), ExitError> {
let notify = NotifySender::new();
let target = Source::new(self.history_size);
let target = Source::new(self.history_size, self.timing());

for &addr in &self.listen {
self.spawn_listener(addr, target.clone(), notify.clone())?;
}
Expand Down Expand Up @@ -118,6 +128,19 @@ impl Tcp {
Ok(())
}

fn timing(&self) -> Timing {
let mut res = Timing::default();
if let Some(refresh) = self.refresh {
res.refresh = refresh;
}
if let Some(retry) = self.retry {
res.retry = retry;
}
if let Some(expire) = self.expire {
res.expire = expire;
}
res
}
}


Expand All @@ -142,7 +165,7 @@ impl Tls {
pub async fn run(self, component: Component) -> Result<(), ExitError> {
let acceptor = TlsAcceptor::from(Arc::new(self.create_tls_config()?));
let notify = NotifySender::new();
let target = Source::new(self.tcp.history_size);
let target = Source::new(self.tcp.history_size, self.tcp.timing());
for &addr in &self.tcp.listen {
self.spawn_listener(
addr, acceptor.clone(), target.clone(), notify.clone()
Expand Down Expand Up @@ -271,14 +294,16 @@ struct Source {

/// The maximum nummber of diffs to keep.
history_size: usize,
timing: Timing,
}

impl Source {
/// Creates a new source using the given history size.
fn new(history_size: usize) -> Self {
/// Creates a new source using the given history size and timing.
fn new(history_size: usize, timing: Timing) -> Self {
Source {
data: Default::default(),
history_size
history_size,
timing,
}
}

Expand All @@ -298,7 +323,7 @@ impl Source {
state: data.state,
current: Some(payload.set().clone()),
diffs: Vec::new(),
timing: Timing::default(),
timing: self.timing,
}
}
Some(current) => {
Expand Down Expand Up @@ -326,7 +351,7 @@ impl Source {
state,
current: Some(payload.set().clone()),
diffs,
timing: Timing::default(),
timing: self.timing,
}
}
};
Expand Down

0 comments on commit 01331a6

Please sign in to comment.