pub fn create_transport_type(config: &GlobalConfig) -> TransportType {
    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(convert_socks_authentication).unwrap_or_default(),
                proxy_bypass_addresses: vec![],
            }),
        },
        CommsTransport::TorHiddenService {
            control_server_address,
            socks_address_override,
            forward_address,
            auth,
            onion_port,
            tor_proxy_bypass_addresses,
        } => {
            let identity = Some(&config.base_node_tor_identity_file)
                .filter(|p| p.exists())
                .and_then(|p| {
                    // If this fails, we can just use another address
                    load_from_json::<_, TorIdentity>(p).ok()
                });
            info!(
                target: LOG_TARGET,
                "Tor identity at path '{}' {:?}",
                config.base_node_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(),
                socks_address_override,
                socks_auth: socks::Authentication::None,
                tor_proxy_bypass_addresses,
            })
        },
        CommsTransport::Socks5 {
            proxy_address,
            listener_address,
            auth,
        } => TransportType::Socks {
            socks_config: SocksConfig {
                proxy_address,
                authentication: convert_socks_authentication(auth),
                proxy_bypass_addresses: vec![],
            },
            listener_address,
        },
    }
}
/// 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
pub fn create_transport_type(config: &GlobalConfig) -> TransportType {
    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(convert_socks_authentication).unwrap_or_default(),
                proxy_bypass_addresses: vec![],
            }),
        },
        CommsTransport::TorHiddenService {
            control_server_address,
            socks_address_override,
            forward_address,
            auth,
            onion_port,
            tor_proxy_bypass_addresses,
        } => {
            let identity = Some(&config.base_node_tor_identity_file)
                .filter(|p| p.exists())
                .and_then(|p| {
                    // If this fails, we can just use another address
                    load_from_json::<_, TorIdentity>(p).ok()
                });
            info!(
                target: LOG_TARGET,
                "Tor identity at path '{}' {:?}",
                config.base_node_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(),
                socks_address_override,
                socks_auth: socks::Authentication::None,
                tor_proxy_bypass_addresses,
            })
        },
        CommsTransport::Socks5 {
            proxy_address,
            listener_address,
            auth,
        } => TransportType::Socks {
            socks_config: SocksConfig {
                proxy_address,
                authentication: convert_socks_authentication(auth),
                proxy_bypass_addresses: vec![],
            },
            listener_address,
        },
    }
}
pub fn create_transport_type ( config : & GlobalConfig ) -> TransportType { 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 ( convert_socks_authentication ) . unwrap_or_default ( ) , proxy_bypass_addresses : vec ! [ ] , } ) , } , CommsTransport :: TorHiddenService { control_server_address , socks_address_override , forward_address , auth , onion_port , tor_proxy_bypass_addresses , } => { let identity = Some ( & config . base_node_tor_identity_file ) . filter ( | p | p . exists ( ) ) . and_then ( | p | { // If this fails, we can just use another address load_from_json :: < _ , TorIdentity > ( p ) . ok ( ) } ) ; info ! ( target LOG_TARGET " " config base_node_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 ( ) , socks_address_override , socks_auth : socks :: Authentication :: None , tor_proxy_bypass_addresses , } ) } , CommsTransport :: Socks5 { proxy_address , listener_address , auth , } => TransportType :: Socks { socks_config : SocksConfig { proxy_address , authentication : convert_socks_authentication ( auth ) , proxy_bypass_addresses : vec ! [ ] , } , listener_address , } , } }
Creates a transport type from the given configuration
Creates a transport type from the given configuration
config
&GlobalConfig
TransportType based on the configuration
TransportType based on the configuration
config
&GlobalConfig
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 ]