2018-03-07 10:49:11 +01:00
|
|
|
// Copyright 2018 Parity Technologies (UK) Ltd.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2019-01-21 10:33:51 +00:00
|
|
|
use crate::structs_proto;
|
2022-05-05 18:28:47 +02:00
|
|
|
use asynchronous_codec::{FramedRead, FramedWrite};
|
2022-06-07 13:42:34 +02:00
|
|
|
use futures::{future::BoxFuture, prelude::*};
|
2018-11-15 17:41:11 +01:00
|
|
|
use libp2p_core::{
|
2022-12-13 20:24:31 +00:00
|
|
|
connection::ConnectionId,
|
2022-05-05 18:28:47 +02:00
|
|
|
identity, multiaddr,
|
|
|
|
upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo},
|
2018-11-15 17:41:11 +01:00
|
|
|
Multiaddr, PublicKey,
|
|
|
|
};
|
2022-12-24 14:20:55 +01:00
|
|
|
use log::{debug, trace};
|
2019-04-17 20:12:31 +02:00
|
|
|
use std::convert::TryFrom;
|
2022-12-13 20:24:31 +00:00
|
|
|
use std::{io, iter, pin::Pin};
|
2022-05-05 18:28:47 +02:00
|
|
|
use thiserror::Error;
|
2022-06-07 13:42:34 +02:00
|
|
|
use void::Void;
|
2022-05-05 18:28:47 +02:00
|
|
|
|
|
|
|
const MAX_MESSAGE_SIZE_BYTES: usize = 4096;
|
2018-03-07 10:49:11 +01:00
|
|
|
|
2022-07-15 09:16:03 +02:00
|
|
|
pub const PROTOCOL_NAME: &[u8; 14] = b"/ipfs/id/1.0.0";
|
|
|
|
|
|
|
|
pub const PUSH_PROTOCOL_NAME: &[u8; 19] = b"/ipfs/id/push/1.0.0";
|
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
/// The type of the Substream protocol.
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
pub enum Protocol {
|
|
|
|
Identify(ConnectionId),
|
|
|
|
Push,
|
|
|
|
}
|
|
|
|
|
2021-03-18 12:47:01 +01:00
|
|
|
/// Substream upgrade protocol for `/ipfs/id/1.0.0`.
|
2018-03-07 10:49:11 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2022-12-13 20:24:31 +00:00
|
|
|
pub struct Identify;
|
2018-03-07 10:49:11 +01:00
|
|
|
|
2021-03-18 12:47:01 +01:00
|
|
|
/// Substream upgrade protocol for `/ipfs/id/push/1.0.0`.
|
2018-11-15 17:41:11 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2022-12-13 20:24:31 +00:00
|
|
|
pub struct Push<T>(T);
|
2021-03-18 12:47:01 +01:00
|
|
|
pub struct InboundPush();
|
2022-10-04 01:17:31 +01:00
|
|
|
pub struct OutboundPush(Info);
|
2021-03-18 12:47:01 +01:00
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
impl Push<InboundPush> {
|
2021-03-18 12:47:01 +01:00
|
|
|
pub fn inbound() -> Self {
|
2022-12-13 20:24:31 +00:00
|
|
|
Push(InboundPush())
|
2021-03-18 12:47:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
impl Push<OutboundPush> {
|
2022-10-04 01:17:31 +01:00
|
|
|
pub fn outbound(info: Info) -> Self {
|
2022-12-13 20:24:31 +00:00
|
|
|
Push(OutboundPush(info))
|
2021-03-18 12:47:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Information of a peer sent in protocol messages.
|
|
|
|
#[derive(Debug, Clone)]
|
2022-10-04 01:17:31 +01:00
|
|
|
pub struct Info {
|
2021-03-18 12:47:01 +01:00
|
|
|
/// The public key of the local peer.
|
|
|
|
pub public_key: PublicKey,
|
|
|
|
/// Application-specific version of the protocol family used by the peer,
|
|
|
|
/// e.g. `ipfs/1.0.0` or `polkadot/1.0.0`.
|
|
|
|
pub protocol_version: String,
|
|
|
|
/// Name and version of the peer, similar to the `User-Agent` header in
|
|
|
|
/// the HTTP protocol.
|
|
|
|
pub agent_version: String,
|
|
|
|
/// The addresses that the peer is listening on.
|
|
|
|
pub listen_addrs: Vec<Multiaddr>,
|
|
|
|
/// The list of protocols supported by the peer, e.g. `/ipfs/ping/1.0.0`.
|
|
|
|
pub protocols: Vec<String>,
|
|
|
|
/// Address observed by or for the remote.
|
2018-11-15 17:41:11 +01:00
|
|
|
pub observed_addr: Multiaddr,
|
2018-03-07 10:49:11 +01:00
|
|
|
}
|
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
impl UpgradeInfo for Identify {
|
2018-12-11 15:13:10 +01:00
|
|
|
type Info = &'static [u8];
|
|
|
|
type InfoIter = iter::Once<Self::Info>;
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2018-12-11 15:13:10 +01:00
|
|
|
fn protocol_info(&self) -> Self::InfoIter {
|
2022-07-15 09:16:03 +02:00
|
|
|
iter::once(PROTOCOL_NAME)
|
2018-03-07 16:20:55 +01:00
|
|
|
}
|
2018-11-15 17:41:11 +01:00
|
|
|
}
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
impl<C> InboundUpgrade<C> for Identify {
|
|
|
|
type Output = C;
|
2022-05-05 18:28:47 +02:00
|
|
|
type Error = UpgradeError;
|
|
|
|
type Future = future::Ready<Result<Self::Output, UpgradeError>>;
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2020-01-13 14:34:43 +01:00
|
|
|
fn upgrade_inbound(self, socket: C, _: Self::Info) -> Self::Future {
|
2022-12-13 20:24:31 +00:00
|
|
|
future::ok(socket)
|
2018-11-15 17:41:11 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
impl<C> OutboundUpgrade<C> for Identify
|
2018-11-15 17:41:11 +01:00
|
|
|
where
|
2019-11-26 14:47:49 +01:00
|
|
|
C: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
2018-11-15 17:41:11 +01:00
|
|
|
{
|
2022-10-04 01:17:31 +01:00
|
|
|
type Output = Info;
|
2022-05-05 18:28:47 +02:00
|
|
|
type Error = UpgradeError;
|
2019-11-26 14:47:49 +01:00
|
|
|
type Future = Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send>>;
|
2019-09-16 11:08:44 +02:00
|
|
|
|
2021-03-18 12:47:01 +01:00
|
|
|
fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future {
|
|
|
|
recv(socket).boxed()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
impl<T> UpgradeInfo for Push<T> {
|
2021-03-18 12:47:01 +01:00
|
|
|
type Info = &'static [u8];
|
|
|
|
type InfoIter = iter::Once<Self::Info>;
|
2018-11-16 13:59:56 +01:00
|
|
|
|
2021-03-18 12:47:01 +01:00
|
|
|
fn protocol_info(&self) -> Self::InfoIter {
|
2022-07-15 09:16:03 +02:00
|
|
|
iter::once(PUSH_PROTOCOL_NAME)
|
2021-03-18 12:47:01 +01:00
|
|
|
}
|
|
|
|
}
|
2018-11-16 13:59:56 +01:00
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
impl<C> InboundUpgrade<C> for Push<InboundPush>
|
2021-03-18 12:47:01 +01:00
|
|
|
where
|
|
|
|
C: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
|
|
|
{
|
2022-10-04 01:17:31 +01:00
|
|
|
type Output = BoxFuture<'static, Result<Info, UpgradeError>>;
|
2022-06-07 13:42:34 +02:00
|
|
|
type Error = Void;
|
|
|
|
type Future = future::Ready<Result<Self::Output, Self::Error>>;
|
2021-03-18 12:47:01 +01:00
|
|
|
|
|
|
|
fn upgrade_inbound(self, socket: C, _: Self::Info) -> Self::Future {
|
2022-06-07 13:42:34 +02:00
|
|
|
// Lazily upgrade stream, thus allowing upgrade to happen within identify's handler.
|
|
|
|
future::ok(recv(socket).boxed())
|
2021-03-18 12:47:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
impl<C> OutboundUpgrade<C> for Push<OutboundPush>
|
2021-03-18 12:47:01 +01:00
|
|
|
where
|
|
|
|
C: AsyncWrite + Unpin + Send + 'static,
|
|
|
|
{
|
|
|
|
type Output = ();
|
2022-05-05 18:28:47 +02:00
|
|
|
type Error = UpgradeError;
|
2021-03-18 12:47:01 +01:00
|
|
|
type Future = Pin<Box<dyn Future<Output = Result<Self::Output, Self::Error>> + Send>>;
|
|
|
|
|
|
|
|
fn upgrade_outbound(self, socket: C, _: Self::Info) -> Self::Future {
|
|
|
|
send(socket, self.0 .0).boxed()
|
2018-03-07 16:20:55 +01:00
|
|
|
}
|
2018-03-07 10:49:11 +01:00
|
|
|
}
|
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
pub(crate) async fn send<T>(io: T, info: Info) -> Result<(), UpgradeError>
|
2021-03-18 12:47:01 +01:00
|
|
|
where
|
|
|
|
T: AsyncWrite + Unpin,
|
|
|
|
{
|
|
|
|
trace!("Sending: {:?}", info);
|
|
|
|
|
|
|
|
let listen_addrs = info
|
|
|
|
.listen_addrs
|
|
|
|
.into_iter()
|
|
|
|
.map(|addr| addr.to_vec())
|
|
|
|
.collect();
|
|
|
|
|
2021-07-22 22:34:13 +02:00
|
|
|
let pubkey_bytes = info.public_key.to_protobuf_encoding();
|
2021-03-18 12:47:01 +01:00
|
|
|
|
|
|
|
let message = structs_proto::Identify {
|
|
|
|
agent_version: Some(info.agent_version),
|
|
|
|
protocol_version: Some(info.protocol_version),
|
|
|
|
public_key: Some(pubkey_bytes),
|
|
|
|
listen_addrs,
|
|
|
|
observed_addr: Some(info.observed_addr.to_vec()),
|
|
|
|
protocols: info.protocols,
|
|
|
|
};
|
|
|
|
|
2022-05-05 18:28:47 +02:00
|
|
|
let mut framed_io = FramedWrite::new(
|
|
|
|
io,
|
|
|
|
prost_codec::Codec::<structs_proto::Identify>::new(MAX_MESSAGE_SIZE_BYTES),
|
|
|
|
);
|
2021-07-04 00:23:10 +10:00
|
|
|
|
2022-05-05 18:28:47 +02:00
|
|
|
framed_io.send(message).await?;
|
|
|
|
framed_io.close().await?;
|
2021-07-04 00:23:10 +10:00
|
|
|
|
|
|
|
Ok(())
|
2021-03-18 12:47:01 +01:00
|
|
|
}
|
|
|
|
|
2022-10-04 01:17:31 +01:00
|
|
|
async fn recv<T>(mut socket: T) -> Result<Info, UpgradeError>
|
2021-03-18 12:47:01 +01:00
|
|
|
where
|
|
|
|
T: AsyncRead + AsyncWrite + Unpin,
|
|
|
|
{
|
|
|
|
socket.close().await?;
|
|
|
|
|
2022-05-05 18:28:47 +02:00
|
|
|
let info = FramedRead::new(
|
|
|
|
socket,
|
|
|
|
prost_codec::Codec::<structs_proto::Identify>::new(MAX_MESSAGE_SIZE_BYTES),
|
|
|
|
)
|
|
|
|
.next()
|
|
|
|
.await
|
|
|
|
.ok_or(UpgradeError::StreamClosed)??
|
|
|
|
.try_into()?;
|
2021-03-18 12:47:01 +01:00
|
|
|
|
|
|
|
trace!("Received: {:?}", info);
|
|
|
|
|
|
|
|
Ok(info)
|
|
|
|
}
|
|
|
|
|
2022-10-04 01:17:31 +01:00
|
|
|
impl TryFrom<structs_proto::Identify> for Info {
|
2022-05-05 18:28:47 +02:00
|
|
|
type Error = UpgradeError;
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2022-05-05 18:28:47 +02:00
|
|
|
fn try_from(msg: structs_proto::Identify) -> Result<Self, Self::Error> {
|
|
|
|
fn parse_multiaddr(bytes: Vec<u8>) -> Result<Multiaddr, multiaddr::Error> {
|
|
|
|
Multiaddr::try_from(bytes)
|
2018-03-07 16:20:55 +01:00
|
|
|
}
|
|
|
|
|
2022-05-05 18:28:47 +02:00
|
|
|
let listen_addrs = {
|
|
|
|
let mut addrs = Vec::new();
|
|
|
|
for addr in msg.listen_addrs.into_iter() {
|
2022-12-24 14:20:55 +01:00
|
|
|
match parse_multiaddr(addr) {
|
|
|
|
Ok(a) => addrs.push(a),
|
|
|
|
Err(e) => {
|
|
|
|
debug!("Unable to parse multiaddr: {e:?}");
|
|
|
|
}
|
|
|
|
}
|
2022-05-05 18:28:47 +02:00
|
|
|
}
|
|
|
|
addrs
|
|
|
|
};
|
|
|
|
|
|
|
|
let public_key = PublicKey::from_protobuf_encoding(&msg.public_key.unwrap_or_default())?;
|
|
|
|
|
2022-12-24 14:20:55 +01:00
|
|
|
let observed_addr = match parse_multiaddr(msg.observed_addr.unwrap_or_default()) {
|
|
|
|
Ok(a) => a,
|
|
|
|
Err(e) => {
|
|
|
|
debug!("Unable to parse multiaddr: {e:?}");
|
|
|
|
Multiaddr::empty()
|
|
|
|
}
|
|
|
|
};
|
2022-10-04 01:17:31 +01:00
|
|
|
let info = Info {
|
2022-05-05 18:28:47 +02:00
|
|
|
public_key,
|
|
|
|
protocol_version: msg.protocol_version.unwrap_or_default(),
|
|
|
|
agent_version: msg.agent_version.unwrap_or_default(),
|
|
|
|
listen_addrs,
|
|
|
|
protocols: msg.protocols,
|
|
|
|
observed_addr,
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(info)
|
2018-03-07 16:20:55 +01:00
|
|
|
}
|
2018-03-07 10:49:11 +01:00
|
|
|
}
|
|
|
|
|
2022-05-05 18:28:47 +02:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum UpgradeError {
|
2022-11-02 23:02:21 +11:00
|
|
|
#[error(transparent)]
|
|
|
|
Codec(#[from] prost_codec::Error),
|
2022-05-05 18:28:47 +02:00
|
|
|
#[error("I/O interaction failed")]
|
2022-11-02 23:02:21 +11:00
|
|
|
Io(#[from] io::Error),
|
2022-05-05 18:28:47 +02:00
|
|
|
#[error("Stream closed")]
|
|
|
|
StreamClosed,
|
|
|
|
#[error("Failed decoding multiaddr")]
|
2022-11-02 23:02:21 +11:00
|
|
|
Multiaddr(#[from] multiaddr::Error),
|
2022-05-05 18:28:47 +02:00
|
|
|
#[error("Failed decoding public key")]
|
2022-11-02 23:02:21 +11:00
|
|
|
PublicKey(#[from] identity::error::DecodingError),
|
2022-05-05 18:28:47 +02:00
|
|
|
}
|
|
|
|
|
2018-03-07 10:49:11 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2019-02-11 14:58:15 +01:00
|
|
|
use super::*;
|
2021-09-08 00:36:52 +10:00
|
|
|
use futures::channel::oneshot;
|
2019-04-10 10:29:21 +02:00
|
|
|
use libp2p_core::{
|
|
|
|
identity,
|
2019-10-10 11:31:44 +02:00
|
|
|
upgrade::{self, apply_inbound, apply_outbound},
|
2019-04-10 10:29:21 +02:00
|
|
|
Transport,
|
|
|
|
};
|
2022-12-13 07:58:01 +11:00
|
|
|
use libp2p_tcp as tcp;
|
2018-03-07 16:20:55 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn correct_transfer() {
|
|
|
|
// We open a server and a client, send info from the server to the client, and check that
|
|
|
|
// they were successfully received.
|
2019-03-11 13:42:53 +01:00
|
|
|
let send_pubkey = identity::Keypair::generate_ed25519().public();
|
|
|
|
let recv_pubkey = send_pubkey.clone();
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2019-11-26 14:47:49 +01:00
|
|
|
let (tx, rx) = oneshot::channel();
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2019-11-26 14:47:49 +01:00
|
|
|
let bg_task = async_std::task::spawn(async move {
|
2022-10-24 15:41:08 +11:00
|
|
|
let mut transport = tcp::async_io::Transport::default().boxed();
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2022-07-04 04:16:57 +02:00
|
|
|
transport
|
2018-03-07 16:20:55 +01:00
|
|
|
.listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap())
|
|
|
|
.unwrap();
|
2018-11-15 17:41:11 +01:00
|
|
|
|
2022-07-04 04:16:57 +02:00
|
|
|
let addr = transport
|
2019-11-26 14:47:49 +01:00
|
|
|
.next()
|
|
|
|
.await
|
2019-04-10 10:29:21 +02:00
|
|
|
.expect("some event")
|
|
|
|
.into_new_address()
|
|
|
|
.expect("listen address");
|
2018-03-07 16:20:55 +01:00
|
|
|
tx.send(addr).unwrap();
|
|
|
|
|
2022-07-04 04:16:57 +02:00
|
|
|
let socket = transport
|
2021-03-18 12:47:01 +01:00
|
|
|
.next()
|
|
|
|
.await
|
2022-07-04 04:16:57 +02:00
|
|
|
.expect("some event")
|
|
|
|
.into_incoming()
|
2018-03-07 16:20:55 +01:00
|
|
|
.unwrap()
|
2021-03-18 12:47:01 +01:00
|
|
|
.0
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
let sender = apply_inbound(socket, Identify).await.unwrap();
|
2021-03-18 12:47:01 +01:00
|
|
|
|
2022-12-13 20:24:31 +00:00
|
|
|
send(
|
|
|
|
sender,
|
|
|
|
Info {
|
2019-11-26 14:47:49 +01:00
|
|
|
public_key: send_pubkey,
|
|
|
|
protocol_version: "proto_version".to_owned(),
|
|
|
|
agent_version: "agent_version".to_owned(),
|
|
|
|
listen_addrs: vec![
|
|
|
|
"/ip4/80.81.82.83/tcp/500".parse().unwrap(),
|
|
|
|
"/ip6/::1/udp/1000".parse().unwrap(),
|
|
|
|
],
|
|
|
|
protocols: vec!["proto1".to_string(), "proto2".to_string()],
|
2021-03-18 12:47:01 +01:00
|
|
|
observed_addr: "/ip4/100.101.102.103/tcp/5000".parse().unwrap(),
|
2022-12-13 20:24:31 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2018-03-07 16:20:55 +01:00
|
|
|
});
|
|
|
|
|
2019-11-26 14:47:49 +01:00
|
|
|
async_std::task::block_on(async move {
|
2022-10-24 15:41:08 +11:00
|
|
|
let mut transport = tcp::async_io::Transport::default();
|
2018-03-07 16:20:55 +01:00
|
|
|
|
2019-11-26 14:47:49 +01:00
|
|
|
let socket = transport.dial(rx.await.unwrap()).unwrap().await.unwrap();
|
2022-12-13 20:24:31 +00:00
|
|
|
let info = apply_outbound(socket, Identify, upgrade::Version::V1)
|
2021-03-18 12:47:01 +01:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
info.observed_addr,
|
|
|
|
"/ip4/100.101.102.103/tcp/5000".parse().unwrap()
|
|
|
|
);
|
2019-11-26 14:47:49 +01:00
|
|
|
assert_eq!(info.public_key, recv_pubkey);
|
|
|
|
assert_eq!(info.protocol_version, "proto_version");
|
|
|
|
assert_eq!(info.agent_version, "agent_version");
|
|
|
|
assert_eq!(
|
|
|
|
info.listen_addrs,
|
|
|
|
&[
|
|
|
|
"/ip4/80.81.82.83/tcp/500".parse().unwrap(),
|
|
|
|
"/ip6/::1/udp/1000".parse().unwrap()
|
2021-08-11 13:12:12 +02:00
|
|
|
]
|
2019-11-26 14:47:49 +01:00
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
info.protocols,
|
|
|
|
&["proto1".to_string(), "proto2".to_string()]
|
|
|
|
);
|
|
|
|
|
|
|
|
bg_task.await;
|
|
|
|
});
|
2018-03-07 16:20:55 +01:00
|
|
|
}
|
2022-12-24 14:20:55 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn skip_invalid_multiaddr() {
|
|
|
|
let valid_multiaddr: Multiaddr = "/ip6/2001:db8::/tcp/1234".parse().unwrap();
|
|
|
|
let valid_multiaddr_bytes = valid_multiaddr.to_vec();
|
|
|
|
|
|
|
|
let invalid_multiaddr = {
|
|
|
|
let a = vec![255; 8];
|
|
|
|
assert!(Multiaddr::try_from(a.clone()).is_err());
|
|
|
|
a
|
|
|
|
};
|
|
|
|
|
|
|
|
let payload = structs_proto::Identify {
|
|
|
|
agent_version: None,
|
|
|
|
listen_addrs: vec![valid_multiaddr_bytes, invalid_multiaddr],
|
|
|
|
observed_addr: None,
|
|
|
|
protocol_version: None,
|
|
|
|
protocols: vec![],
|
|
|
|
public_key: Some(
|
|
|
|
identity::Keypair::generate_ed25519()
|
|
|
|
.public()
|
|
|
|
.to_protobuf_encoding(),
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
|
|
|
let info = Info::try_from(payload).expect("not to fail");
|
|
|
|
|
|
|
|
assert_eq!(info.listen_addrs, vec![valid_multiaddr])
|
|
|
|
}
|
2018-03-07 10:49:11 +01:00
|
|
|
}
|