use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
use crate::method::hole_punch::HolePunchCoordinator;
use crate::method::relayed::RelayedDialer;
use crate::method::upnp::IgdGateway;
#[derive(Default)]
pub struct NatRuntime {
pub(crate) local_port: Option<u16>,
pub(crate) gateway_v4: Option<Ipv4Addr>,
pub(crate) client_ip: Option<IpAddr>,
pub(crate) igd: Option<Arc<dyn IgdGateway>>,
pub(crate) my_external_addr: Option<SocketAddr>,
pub(crate) hole_punch: Option<Arc<dyn HolePunchCoordinator>>,
pub(crate) relayed: Option<Arc<dyn RelayedDialer>>,
}
impl NatRuntime {
pub fn builder() -> NatRuntimeBuilder {
NatRuntimeBuilder {
rt: NatRuntime::default(),
}
}
}
#[derive(Default)]
pub struct NatRuntimeBuilder {
rt: NatRuntime,
}
impl NatRuntimeBuilder {
pub fn local_port(mut self, port: u16) -> Self {
self.rt.local_port = Some(port);
self
}
pub fn gateway_v4(mut self, gateway: Ipv4Addr) -> Self {
self.rt.gateway_v4 = Some(gateway);
self
}
pub fn client_ip(mut self, ip: IpAddr) -> Self {
self.rt.client_ip = Some(ip);
self
}
pub fn igd(mut self, igd: Arc<dyn IgdGateway>) -> Self {
self.rt.igd = Some(igd);
self
}
pub fn my_external_addr(mut self, addr: SocketAddr) -> Self {
self.rt.my_external_addr = Some(addr);
self
}
pub fn hole_punch(mut self, coordinator: Arc<dyn HolePunchCoordinator>) -> Self {
self.rt.hole_punch = Some(coordinator);
self
}
pub fn relayed(mut self, relayed: Arc<dyn RelayedDialer>) -> Self {
self.rt.relayed = Some(relayed);
self
}
pub fn build(self) -> NatRuntime {
self.rt
}
}