/// Creates a transport type from the given configuration
///
/// ## Paramters
/// `config` - The reference to the configuration in which to set up the comms stack, see [GlobalConfig]
///
/// ##Returns
/// TransportType based on the configuration
Creates a transport type from the given configuration
Creates a transport type from the given configuration
fn create_transport_type(&self) -> TransportType {
        let config = self.config;
        debug!(target: LOG_TARGET, "Transport is set to '{:?}'", config.comms_transport);
        match config.comms_transport.clone() {
            CommsTransport::Tcp {
                listener_address,
                tor_socks_address,
                tor_socks_auth,
            } => TransportType::Tcp {
                listener_address,
                tor_socks_config: tor_socks_address.map(|proxy_address| SocksConfig {
                    proxy_address,
                    authentication: tor_socks_auth
                        .map(utilities::convert_socks_authentication)
                        .unwrap_or_default(),
                }),
            },
            CommsTransport::TorHiddenService {
                control_server_address,
                socks_address_override,
                forward_address,
                auth,
                onion_port,
            } => {
                let identity = Some(&config.tor_identity_file).filter(|p| p.exists()).and_then(|p| {
                    // If this fails, we can just use another address
                    identity_management::load_from_json::<_, TorIdentity>(p).ok()
                });
                info!(
                    target: LOG_TARGET,
                    "Tor identity at path '{}' {:?}",
                    config.tor_identity_file.to_string_lossy(),
                    identity
                        .as_ref()
                        .map(|ident| format!("loaded for address '{}.onion'", ident.service_id))
                        .or_else(|| Some("not found".to_string()))
                        .unwrap()
                );
                let forward_addr = multiaddr_to_socketaddr(&forward_address).expect("Invalid tor forward address");
                TransportType::Tor(TorConfig {
                    control_server_addr: control_server_address,
                    control_server_auth: {
                        match auth {
                            TorControlAuthentication::None => tor::Authentication::None,
                            TorControlAuthentication::Password(password) => {
                                tor::Authentication::HashedPassword(password)
                            },
                        }
                    },
                    identity: identity.map(Box::new),
                    port_mapping: (onion_port, forward_addr).into(),
                    // TODO: make configurable
                    socks_address_override,
                    socks_auth: socks::Authentication::None,
                })
            },
            CommsTransport::Socks5 {
                proxy_address,
                listener_address,
                auth,
            } => TransportType::Socks {
                socks_config: SocksConfig {
                    proxy_address,
                    authentication: utilities::convert_socks_authentication(auth),
                },
                listener_address,
            },
        }
    }
fn create_transport_type ( & self ) -> TransportType { let config = self . config ; debug ! ( target LOG_TARGET " " config comms_transport ) ; match config . comms_transport . clone ( ) { CommsTransport :: Tcp { listener_address , tor_socks_address , tor_socks_auth , } => TransportType :: Tcp { listener_address , tor_socks_config : tor_socks_address . map ( | proxy_address | SocksConfig { proxy_address , authentication : tor_socks_auth . map ( utilities :: convert_socks_authentication ) . unwrap_or_default ( ) , } ) , } , CommsTransport :: TorHiddenService { control_server_address , socks_address_override , forward_address , auth , onion_port , } => { let identity = Some ( & config . tor_identity_file ) . filter ( | p | p . exists ( ) ) . and_then ( | p | { // If this fails, we can just use another address identity_management :: load_from_json :: < _ , TorIdentity > ( p ) . ok ( ) } ) ; info ! ( target LOG_TARGET " " config tor_identity_file to_string_lossy ( ) identity as_ref ( ) map ( ident format ( " " ident service_id ) ) or_else ( Some ( " " to_string ( ) ) ) unwrap ( ) ) ; let forward_addr = multiaddr_to_socketaddr ( & forward_address ) . expect ( " " ) ; TransportType :: Tor ( TorConfig { control_server_addr : control_server_address , control_server_auth : { match auth { TorControlAuthentication :: None => tor :: Authentication :: None , TorControlAuthentication :: Password ( password ) => { tor :: Authentication :: HashedPassword ( password ) } , } } , identity : identity . map ( Box :: new ) , port_mapping : ( onion_port , forward_addr ) . into ( ) , // TODO: make configurable socks_address_override , socks_auth : socks :: Authentication :: None , } ) } , CommsTransport :: Socks5 { proxy_address , listener_address , auth , } => TransportType :: Socks { socks_config : SocksConfig { proxy_address , authentication : utilities :: convert_socks_authentication ( auth ) , } , listener_address , } , } }
Creates a transport type from the given configuration
Creates a transport type from the given configuration
TransportType based on the configuration
TransportType based on the configuration
&self
paramters
`config` - The reference to the configuration in which to set up the comms stack, see [GlobalConfig]
` config ` - The reference to the configuration in which to set up the comms stack see [ GlobalConfig ]