tests pass
This commit is contained in:
		@@ -121,7 +121,7 @@ impl Network {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub async fn send_data(&self, node_ref: NodeRef, data: Vec<u8>) -> Result<(), String> {
 | 
			
		||||
        let dial_info = node_ref.dial_info();
 | 
			
		||||
        let dial_info = node_ref.best_dial_info();
 | 
			
		||||
        let descriptor = node_ref.last_connection();
 | 
			
		||||
 | 
			
		||||
        // First try to send data to the last socket we've seen this peer on
 | 
			
		||||
 
 | 
			
		||||
@@ -91,21 +91,29 @@ impl WebsocketProtocolHandler {
 | 
			
		||||
        network_manager: NetworkManager,
 | 
			
		||||
        dial_info: &DialInfo,
 | 
			
		||||
    ) -> Result<NetworkConnection, String> {
 | 
			
		||||
        let url = dial_info.to_url_string(None);
 | 
			
		||||
        let (tls, host, port, protocol_type) = match dial_info {
 | 
			
		||||
            DialInfo::WS(ws) => (false, ws.host.clone(), ws.port, ProtocolType::WS),
 | 
			
		||||
            DialInfo::WSS(wss) => (true, wss.host.clone(), wss.port, ProtocolType::WSS),
 | 
			
		||||
        let url = dial_info
 | 
			
		||||
            .request()
 | 
			
		||||
            .ok_or_else(|| format!("missing url in websocket dialinfo: {:?}", dial_info))?;
 | 
			
		||||
        let split_url = SplitUrl::from_str(&url)?;
 | 
			
		||||
        let tls = match dial_info {
 | 
			
		||||
            DialInfo::WS(ws) => {
 | 
			
		||||
                if split_url.scheme.to_ascii_lowercase() != "ws" {
 | 
			
		||||
                    return Err(format!("wrong scheme for WS websocket url: {}", url));
 | 
			
		||||
                }
 | 
			
		||||
                false
 | 
			
		||||
            }
 | 
			
		||||
            DialInfo::WSS(wss) => {
 | 
			
		||||
                if split_url.scheme.to_ascii_lowercase() != "wss" {
 | 
			
		||||
                    return Err(format!("wrong scheme for WSS websocket url: {}", url));
 | 
			
		||||
                }
 | 
			
		||||
                true
 | 
			
		||||
            }
 | 
			
		||||
            _ => {
 | 
			
		||||
                return Err("wrong protocol for WebsocketProtocolHandler".to_owned())
 | 
			
		||||
                    .map_err(logthru_net!(error))
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        let peer_addr = PeerAddress::new(
 | 
			
		||||
            Address::from_str(&host).map_err(logthru_net!(error))?,
 | 
			
		||||
            port,
 | 
			
		||||
            protocol_type,
 | 
			
		||||
        );
 | 
			
		||||
        let peer_addr = dial_info.to_peer_address();
 | 
			
		||||
 | 
			
		||||
        let (ws, wsio) = WsMeta::connect(url, None)
 | 
			
		||||
            .await
 | 
			
		||||
 
 | 
			
		||||
@@ -35,9 +35,9 @@ impl NodeRef {
 | 
			
		||||
        self.node_id
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn dial_info_filter(&self) -> DialInfoFilter {
 | 
			
		||||
        self.dial_info_filter.clone()
 | 
			
		||||
    }
 | 
			
		||||
    // pub fn dial_info_filter(&self) -> DialInfoFilter {
 | 
			
		||||
    //     self.dial_info_filter.clone()
 | 
			
		||||
    // }
 | 
			
		||||
 | 
			
		||||
    pub fn operate<T, F>(&self, f: F) -> T
 | 
			
		||||
    where
 | 
			
		||||
 
 | 
			
		||||
@@ -585,6 +585,14 @@ impl DialInfo {
 | 
			
		||||
            Self::WSS(di) => di.socket_address.to_socket_addr(),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    pub fn to_peer_address(&self) -> PeerAddress {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::UDP(di) => PeerAddress::new(di.socket_address, ProtocolType::UDP),
 | 
			
		||||
            Self::TCP(di) => PeerAddress::new(di.socket_address, ProtocolType::TCP),
 | 
			
		||||
            Self::WS(di) => PeerAddress::new(di.socket_address, ProtocolType::WS),
 | 
			
		||||
            Self::WSS(di) => PeerAddress::new(di.socket_address, ProtocolType::WSS),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    pub fn request(&self) -> Option<String> {
 | 
			
		||||
        match self {
 | 
			
		||||
            Self::UDP(_) => None,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user