2019-03-13 20:40:11 +01:00
|
|
|
//! Actix connect - tcp connector service
|
2018-12-10 17:42:31 +01:00
|
|
|
//!
|
|
|
|
//! ## Package feature
|
|
|
|
//!
|
|
|
|
//! * `ssl` - enables ssl support via `openssl` crate
|
|
|
|
//! * `rust-tls` - enables ssl support via `rustls` crate
|
|
|
|
|
2019-03-13 20:40:11 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
|
|
|
mod connect;
|
2018-12-10 17:42:31 +01:00
|
|
|
mod connector;
|
2019-03-13 20:40:11 +01:00
|
|
|
mod error;
|
2018-12-10 17:42:31 +01:00
|
|
|
mod resolver;
|
2018-12-11 01:16:40 +01:00
|
|
|
pub mod ssl;
|
2018-12-10 17:42:31 +01:00
|
|
|
|
2019-03-13 20:40:11 +01:00
|
|
|
pub use trust_dns_resolver::error::ResolveError;
|
|
|
|
|
|
|
|
pub use self::connect::{Connect, Stream};
|
|
|
|
pub use self::connector::{Connector, ConnectorFactory};
|
|
|
|
pub use self::error::ConnectError;
|
|
|
|
pub use self::resolver::{Resolver, ResolverFactory};
|
|
|
|
|
|
|
|
use actix_service::{NewService, Service, ServiceExt};
|
|
|
|
use tokio_tcp::TcpStream;
|
|
|
|
use trust_dns_resolver::config::{ResolverConfig, ResolverOpts};
|
|
|
|
|
|
|
|
/// Create tcp connector service
|
|
|
|
pub fn new_connector(
|
|
|
|
cfg: ResolverConfig,
|
|
|
|
opts: ResolverOpts,
|
|
|
|
) -> impl Service<Request = Connect, Response = Stream<TcpStream>, Error = ConnectError> + Clone
|
|
|
|
{
|
|
|
|
Resolver::new(cfg, opts).and_then(Connector)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create tcp connector service
|
|
|
|
pub fn new_connector_factory(
|
|
|
|
cfg: ResolverConfig,
|
|
|
|
opts: ResolverOpts,
|
|
|
|
) -> impl NewService<
|
|
|
|
Request = Connect,
|
|
|
|
Response = Stream<TcpStream>,
|
|
|
|
Error = ConnectError,
|
|
|
|
InitError = (),
|
|
|
|
> + Clone {
|
|
|
|
ResolverFactory::new(cfg, opts).and_then(ConnectorFactory)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create connector service with default parameters
|
|
|
|
pub fn default_connector(
|
|
|
|
) -> impl Service<Request = Connect, Response = Stream<TcpStream>, Error = ConnectError> + Clone
|
|
|
|
{
|
|
|
|
Resolver::default().and_then(Connector)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create connector service factory with default parameters
|
|
|
|
pub fn default_connector_factory() -> impl NewService<
|
|
|
|
Request = Connect,
|
|
|
|
Response = Stream<TcpStream>,
|
|
|
|
Error = ConnectError,
|
|
|
|
InitError = (),
|
|
|
|
> + Clone {
|
|
|
|
ResolverFactory::default().and_then(ConnectorFactory)
|
|
|
|
}
|