chanmgr: reconfigure_general: Rename fn and change types

This function is going to become the code for controlling channels, in
general.  (Including padding control.)  Right now it doesn't do most
of the things.

In this commit:

 * Change the prototype and the name now.
 * Pass `()` for the dormancy and config, adding TODOs.
 * Provide update_netdir method on AbstractChanMgr, and call that,
   rather than having the ChanMgr go directly into the channel.
   (That will enable us to test that `update_netdir` method
   with test cases that don't have a complete ChanMgr.)
This commit is contained in:
Ian Jackson 2022-07-26 18:07:57 +01:00
parent 6d16e3f947
commit 968e6eab34
3 changed files with 35 additions and 6 deletions

View File

@ -214,7 +214,7 @@ impl<R: Runtime> ChanMgr<R> {
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"

View File

@ -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<CF: ChannelFactory> AbstractChanMgr<CF> {
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<NetDir>
) -> 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.
///

View File

@ -269,8 +269,23 @@ impl<C: AbstractChannel> ChannelMap<C> {
}
}
/// Handle a `NetDir` update (by reparameterising channels as needed)
pub(crate) fn process_updated_netdir(&self, netdir: Arc<tor_netdir::NetDir>) -> 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<NetDir>,
) -> StdResult<(), tor_error::Bug> {
use ChannelState as CS;
// TODO support dormant mode
@ -296,7 +311,10 @@ impl<C: AbstractChannel> ChannelMap<C> {
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));
}