mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-03 17:45:44 +00:00
fix peer establish direct conn with subnet proxy to one of local interface (#1782)
* fix peer establish direct conn with subnet proxy to one of local interface * fix peer mgr ref loop
This commit is contained in:
@@ -12,7 +12,6 @@ use std::{
|
||||
};
|
||||
|
||||
use device::BufferDevice;
|
||||
use futures::Future;
|
||||
use reactor::Reactor;
|
||||
pub use smoltcp;
|
||||
use smoltcp::{
|
||||
@@ -24,6 +23,8 @@ pub use socket::{TcpListener, TcpStream, UdpSocket};
|
||||
pub use socket_allocator::BufferSize;
|
||||
use tokio::sync::Notify;
|
||||
|
||||
use crate::common::scoped_task::ScopedTask;
|
||||
|
||||
/// The async devices.
|
||||
pub mod channel_device;
|
||||
pub mod device;
|
||||
@@ -78,6 +79,7 @@ pub struct Net {
|
||||
ip_addr: IpCidr,
|
||||
from_port: AtomicU16,
|
||||
stopper: Arc<Notify>,
|
||||
fut: ScopedTask<io::Result<()>>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Net {
|
||||
@@ -92,15 +94,10 @@ impl std::fmt::Debug for Net {
|
||||
impl Net {
|
||||
/// Creates a new `Net` instance. It panics if the medium is not supported.
|
||||
pub fn new<D: device::AsyncDevice + 'static>(device: D, config: NetConfig) -> Net {
|
||||
let (net, fut) = Self::new2(device, config);
|
||||
tokio::spawn(fut);
|
||||
net
|
||||
Self::new2(device, config)
|
||||
}
|
||||
|
||||
fn new2<D: device::AsyncDevice + 'static>(
|
||||
device: D,
|
||||
config: NetConfig,
|
||||
) -> (Net, impl Future<Output = io::Result<()>> + Send) {
|
||||
fn new2<D: device::AsyncDevice + 'static>(device: D, config: NetConfig) -> Net {
|
||||
let mut buffer_device = BufferDevice::new(device.capabilities().clone());
|
||||
let mut iface = Interface::new(config.interface_config, &mut buffer_device, Instant::now());
|
||||
let ip_addr = config.ip_addr;
|
||||
@@ -129,15 +126,13 @@ impl Net {
|
||||
stopper.clone(),
|
||||
);
|
||||
|
||||
(
|
||||
Net {
|
||||
reactor: Arc::new(reactor),
|
||||
ip_addr: config.ip_addr,
|
||||
from_port: AtomicU16::new(10001),
|
||||
stopper,
|
||||
},
|
||||
fut,
|
||||
)
|
||||
Net {
|
||||
reactor: Arc::new(reactor),
|
||||
ip_addr: config.ip_addr,
|
||||
from_port: AtomicU16::new(10001),
|
||||
stopper,
|
||||
fut: ScopedTask::from(tokio::spawn(fut)),
|
||||
}
|
||||
}
|
||||
pub fn get_address(&self) -> IpAddr {
|
||||
self.ip_addr.address().into()
|
||||
|
||||
Reference in New Issue
Block a user