Ditch ToSocksAddress for the standard From/TryFrom.

This induces an added `Send` in the Network trait and its
implementations, but provides us the ability to use standard functions
with obvious extensions. So that's nice. I've also added some additional
testing to sanity check the conversions.
This commit is contained in:
2021-07-05 20:35:56 -07:00
parent d1143a414c
commit ca2eddf515
4 changed files with 145 additions and 52 deletions

View File

@@ -1,11 +1,12 @@
use crate::messages::ServerResponseStatus;
use crate::network::address::ToSOCKSAddress;
use crate::network::address::SOCKSv5Address;
use crate::network::datagram::GenericDatagramSocket;
use crate::network::listener::GenericListener;
use crate::network::stream::GenericStream;
use async_trait::async_trait;
use std::fmt::Display;
#[async_trait]
pub trait Networklike {
/// The error type for things that fail on this network. Apologies in advance
@@ -19,7 +20,7 @@ pub trait Networklike {
/// may be exactly what you're using. However, in order to support tunnelling
/// scenarios (i.e., using another proxy, going through Tor or SSH, etc.) we
/// work generically over any stream-like object.
async fn connect<A: ToSOCKSAddress>(
async fn connect<A: Send + Into<SOCKSv5Address>>(
&mut self,
addr: A,
port: u16,
@@ -27,7 +28,7 @@ pub trait Networklike {
/// Listen for connections on the given address and port, returning a generic
/// listener socket to use in the future.
async fn listen<A: ToSOCKSAddress>(
async fn listen<A: Send + Into<SOCKSv5Address>>(
&mut self,
addr: A,
port: u16,
@@ -40,7 +41,7 @@ pub trait Networklike {
///
/// Recall when using these functions that datagram protocols allow for packet
/// loss and out-of-order delivery. So ... be warned.
async fn bind<A: ToSOCKSAddress>(
async fn bind<A: Send + Into<SOCKSv5Address>>(
&mut self,
addr: A,
port: u16,