use std::io;
use futures::Future;
use tokio_core::reactor::Handle;
use config::Config;
pub mod tcprelay;
pub mod udprelay;
pub mod local;
pub mod server;
mod loadbalancing;
mod dns_resolver;
pub mod socks5;
mod utils;
pub type BoxIoFuture<T> = Box<Future<Item = T, Error = io::Error>>;
fn boxed_future<T, E, F>(f: F) -> Box<Future<Item = T, Error = E>>
where F: Future<Item = T, Error = E> + 'static
{
Box::new(f)
}
scoped_thread_local!(static CONTEXT: Context);
pub struct Context {
handle: Handle,
config: Config,
}
impl Context {
#[doc(hidden)]
pub fn new(handle: Handle, config: Config) -> Context {
Context {
handle: handle,
config: config,
}
}
pub fn with<F, R>(f: F) -> R
where F: FnOnce(&Context) -> R
{
CONTEXT.with(f)
}
#[doc(hidden)]
pub fn set<F, R>(ctx: &Context, f: F) -> R
where F: FnOnce() -> R
{
CONTEXT.set(ctx, f)
}
pub fn handle(&self) -> &Handle {
&self.handle
}
pub fn config(&self) -> &Config {
&self.config
}
}