diff --git a/crates/tor-chanmgr/src/lib.rs b/crates/tor-chanmgr/src/lib.rs index ec6657618..abe5ef5b5 100644 --- a/crates/tor-chanmgr/src/lib.rs +++ b/crates/tor-chanmgr/src/lib.rs @@ -214,7 +214,7 @@ impl ChanMgr { let netdir = netdir.upgrade().ok_or("netdir gone away")?; let netdir = netdir.timely_netdir(); let netdir = if let Ok(nd) = netdir { nd } else { continue }; - self_.mgr.channels.process_updated_netdir(netdir).map_err(|e| { + self_.mgr.update_netdir(netdir).map_err(|e| { error!("continually_update_channels_config: failed to process! {} {:?}", &e, &e); "error processing netdir" diff --git a/crates/tor-chanmgr/src/mgr.rs b/crates/tor-chanmgr/src/mgr.rs index 360c9ded8..35a88017e 100644 --- a/crates/tor-chanmgr/src/mgr.rs +++ b/crates/tor-chanmgr/src/mgr.rs @@ -12,6 +12,7 @@ use std::result::Result as StdResult; use std::sync::Arc; use std::time::Duration; use tor_error::internal; +use tor_netdir::NetDir; use tor_proto::channel::params::ChannelsParamsUpdates; mod map; @@ -248,6 +249,16 @@ impl AbstractChanMgr { Err(last_err.unwrap_or_else(|| Error::Internal(internal!("no error was set!?")))) } + /// Update the netdir + /// + /// TODO: Handle lack of a NetDir + pub(crate) fn update_netdir( + &self, netdir: + Arc + ) -> StdResult<(), tor_error::Bug> { + self.channels.reconfigure_general(None, None, netdir) + } + /// Expire any channels that have been unused longer than /// their maximum unused duration assigned during creation. /// diff --git a/crates/tor-chanmgr/src/mgr/map.rs b/crates/tor-chanmgr/src/mgr/map.rs index f34b13bfe..39b8191ee 100644 --- a/crates/tor-chanmgr/src/mgr/map.rs +++ b/crates/tor-chanmgr/src/mgr/map.rs @@ -269,8 +269,23 @@ impl ChannelMap { } } - /// Handle a `NetDir` update (by reparameterising channels as needed) - pub(crate) fn process_updated_netdir(&self, netdir: Arc) -> Result<()> { + /// Reconfigure all channels as necessary + /// + /// (By reparameterising channels as needed) + /// This function will handle + /// - netdir update + /// - a reconfiguration (TODO, we lack configuration right now) + /// - dormancy (TODO, this isn't plumbed through here yet) + /// + /// For `new_config` and `new_dormancy`, `None` means "no change to previous info". + /// + /// TODO: Make this function be able to cope with netdir not being unavailable. + pub(super) fn reconfigure_general( + &self, + _new_config: Option<&()>, + _new_dormancy: Option<()>, + netdir: Arc, + ) -> StdResult<(), tor_error::Bug> { use ChannelState as CS; // TODO support dormant mode @@ -296,7 +311,10 @@ impl ChannelMap { p }; - let mut inner = self.inner.lock()?; + let mut inner = self + .inner + .lock() + .map_err(|_| internal!("poisonned channel manager"))?; let update = inner .channels_params .start_update() @@ -579,7 +597,7 @@ mod test { }; eprintln!("-- process a default netdir, which should send an update --"); - map.process_updated_netdir(netdir.clone()).unwrap(); + map.reconfigure_general(None, None, netdir.clone()).unwrap(); with_ch(&|ch| { assert_eq!( format!("{:?}", ch.params_update.take().unwrap()), @@ -593,7 +611,7 @@ mod test { eprintln!(); eprintln!("-- process a default netdir again, which should *not* send an update --"); - map.process_updated_netdir(netdir).unwrap(); + map.reconfigure_general(None, None, netdir).unwrap(); with_ch(&|ch| assert_eq!(ch.params_update, None)); }