From e14a5af8dd8a2e78828836a5f713b857870545a3 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 6 Aug 2018 10:07:22 +0200 Subject: [PATCH] Update the P2P multiaddr component to 421 (#383) --- floodsub/src/lib.rs | 2 +- identify/src/peer_id_transport.rs | 2 +- libp2p/examples/kademlia.rs | 10 ++++---- multiaddr/src/protocol.rs | 26 +++------------------ multiaddr/tests/lib.rs | 38 +++++++++++++++---------------- relay/src/utility.rs | 2 +- 6 files changed, 30 insertions(+), 50 deletions(-) diff --git a/floodsub/src/lib.rs b/floodsub/src/lib.rs index ab1bde31caf..db859a9505d 100644 --- a/floodsub/src/lib.rs +++ b/floodsub/src/lib.rs @@ -592,7 +592,7 @@ fn handle_packet_received( publish.get_data().len()); continue; } - let from: Multiaddr = AddrComponent::IPFS(from).into(); + let from: Multiaddr = AddrComponent::P2P(from).into(); let topics = publish .take_topicIDs() diff --git a/identify/src/peer_id_transport.rs b/identify/src/peer_id_transport.rs index 410ad1be655..fc21f3663df 100644 --- a/identify/src/peer_id_transport.rs +++ b/identify/src/peer_id_transport.rs @@ -278,7 +278,7 @@ fn multiaddr_to_peerid(addr: Multiaddr) -> Result { } match components.last() { - Some(&AddrComponent::P2P(ref peer_id)) | Some(&AddrComponent::IPFS(ref peer_id)) => { + Some(&AddrComponent::P2P(ref peer_id)) => { // TODO: `peer_id` is sometimes in fact a CID here match PeerId::from_bytes(peer_id.clone()) { Ok(peer_id) => Ok(peer_id), diff --git a/libp2p/examples/kademlia.rs b/libp2p/examples/kademlia.rs index 072af30c338..ea11443598a 100644 --- a/libp2p/examples/kademlia.rs +++ b/libp2p/examples/kademlia.rs @@ -254,7 +254,7 @@ where P: Peerstore + Clone, { const ADDRESSES: &[&str] = &[ - "/ip4/127.0.0.1/tcp/4001/ipfs/QmQRx32wQkw3hB45j4UDw8V9Ju4mGbxMyhs2m8mpFrFkur", + "/ip4/127.0.0.1/tcp/4001/p2p/QmQRx32wQkw3hB45j4UDw8V9Ju4mGbxMyhs2m8mpFrFkur", // TODO: add some bootstrap nodes here ]; @@ -265,12 +265,12 @@ where .parse::() .expect("failed to parse hard-coded multiaddr"); - let ipfs_component = multiaddr.pop().expect("hard-coded multiaddr is empty"); - let peer = match ipfs_component { - libp2p::multiaddr::AddrComponent::IPFS(key) => { + let p2p_component = multiaddr.pop().expect("hard-coded multiaddr is empty"); + let peer = match p2p_component { + libp2p::multiaddr::AddrComponent::P2P(key) => { PeerId::from_bytes(key).expect("invalid peer id") } - _ => panic!("hard-coded multiaddr didn't end with /ipfs/"), + _ => panic!("hard-coded multiaddr didn't end with /p2p/"), }; peer_store diff --git a/multiaddr/src/protocol.rs b/multiaddr/src/protocol.rs index 2fde66608a6..32992689ef0 100644 --- a/multiaddr/src/protocol.rs +++ b/multiaddr/src/protocol.rs @@ -28,8 +28,7 @@ pub enum Protocol { UDT = 301, UTP = 302, UNIX = 400, - P2P = 420, - IPFS = 421, + P2P = 421, HTTP = 480, HTTPS = 443, ONION = 444, @@ -70,7 +69,6 @@ impl ToString for Protocol { Protocol::UTP => "utp", Protocol::UNIX => "unix", Protocol::P2P => "p2p", - Protocol::IPFS => "ipfs", Protocol::HTTP => "http", Protocol::HTTPS => "https", Protocol::ONION => "onion", @@ -103,7 +101,6 @@ impl FromStr for Protocol { "utp" => Ok(Protocol::UTP), "unix" => Ok(Protocol::UNIX), "p2p" => Ok(Protocol::P2P), - "ipfs" => Ok(Protocol::IPFS), "http" => Ok(Protocol::HTTP), "https" => Ok(Protocol::HTTPS), "onion" => Ok(Protocol::ONION), @@ -145,8 +142,7 @@ impl Protocol { 301 => Ok(Protocol::UDT), 302 => Ok(Protocol::UTP), 400 => Ok(Protocol::UNIX), - 420 => Ok(Protocol::P2P), - 421 => Ok(Protocol::IPFS), + 421 => Ok(Protocol::P2P), 480 => Ok(Protocol::HTTP), 443 => Ok(Protocol::HTTPS), 444 => Ok(Protocol::ONION), @@ -187,7 +183,6 @@ impl Protocol { Protocol::UTP => ProtocolArgSize::Fixed { bytes: 0 }, Protocol::UNIX => ProtocolArgSize::Variable, Protocol::P2P => ProtocolArgSize::Variable, - Protocol::IPFS => ProtocolArgSize::Variable, Protocol::HTTP => ProtocolArgSize::Fixed { bytes: 0 }, Protocol::HTTPS => ProtocolArgSize::Fixed { bytes: 0 }, Protocol::ONION => ProtocolArgSize::Fixed { bytes: 10 }, @@ -263,10 +258,6 @@ impl Protocol { let bytes = Cid::from(a)?.to_bytes(); Ok(AddrComponent::P2P(bytes)) } - Protocol::IPFS => { - let bytes = Cid::from(a)?.to_bytes(); - Ok(AddrComponent::IPFS(bytes)) - } Protocol::ONION => unimplemented!(), // TODO: Protocol::QUIC => Ok(AddrComponent::QUIC), Protocol::UTP => Ok(AddrComponent::UTP), @@ -301,7 +292,6 @@ pub enum AddrComponent { UTP, UNIX(String), P2P(Vec), - IPFS(Vec), HTTP, HTTPS, ONION(Vec), @@ -332,7 +322,6 @@ impl AddrComponent { AddrComponent::UTP => Protocol::UTP, AddrComponent::UNIX(_) => Protocol::UNIX, AddrComponent::P2P(_) => Protocol::P2P, - AddrComponent::IPFS(_) => Protocol::IPFS, AddrComponent::HTTP => Protocol::HTTP, AddrComponent::HTTPS => Protocol::HTTPS, AddrComponent::ONION(_) => Protocol::ONION, @@ -420,10 +409,6 @@ impl AddrComponent { let bytes = Cid::from(data)?.to_bytes(); AddrComponent::P2P(bytes) } - Protocol::IPFS => { - let bytes = Cid::from(data)?.to_bytes(); - AddrComponent::IPFS(bytes) - } Protocol::ONION => unimplemented!(), // TODO: Protocol::QUIC => AddrComponent::QUIC, Protocol::UTP => AddrComponent::UTP, @@ -464,7 +449,7 @@ impl AddrComponent { out.write_varint(bytes.len())?; out.write_all(&bytes)?; } - AddrComponent::P2P(bytes) | AddrComponent::IPFS(bytes) => { + AddrComponent::P2P(bytes) => { out.write_varint(bytes.len())?; out.write_all(&bytes)?; } @@ -508,11 +493,6 @@ impl ToString for AddrComponent { let c = Cid::from(bytes.clone()).expect("cid is known to be valid"); format!("/p2p/{}", c) }, - AddrComponent::IPFS(ref bytes) => { - // TODO: meh for cloning - let c = Cid::from(bytes.clone()).expect("cid is known to be valid"); - format!("/ipfs/{}", c) - }, AddrComponent::HTTP => format!("/http"), AddrComponent::HTTPS => format!("/https"), AddrComponent::ONION(_) => unimplemented!(),//format!("/onion"), // TODO: diff --git a/multiaddr/tests/lib.rs b/multiaddr/tests/lib.rs index 575b9d5199c..0f28bb03651 100644 --- a/multiaddr/tests/lib.rs +++ b/multiaddr/tests/lib.rs @@ -54,17 +54,17 @@ fn construct_success() { ma_valid("/sctp/1234", "840104D2", vec![SCTP]); ma_valid("/udp/65535", "11FFFF", vec![UDP]); ma_valid("/tcp/65535", "06FFFF", vec![TCP]); - ma_valid("/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", + ma_valid("/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![IPFS]); + vec![P2P]); ma_valid("/udp/1234/sctp/1234", "1104D2840104D2", vec![UDP, SCTP]); ma_valid("/udp/1234/udt", "1104D2AD02", vec![UDP, UDT]); ma_valid("/udp/1234/utp", "1104D2AE02", vec![UDP, UTP]); ma_valid("/tcp/1234/http", "0604D2E003", vec![TCP, HTTP]); ma_valid("/tcp/1234/https", "0604D2BB03", vec![TCP, HTTPS]); - ma_valid("/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", + ma_valid("/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", "A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B0604D2", - vec![IPFS, TCP]); + vec![P2P, TCP]); ma_valid("/ip4/127.0.0.1/udp/1234", "047F0000011104D2", vec![IP4, UDP]); @@ -72,36 +72,36 @@ fn construct_success() { ma_valid("/ip4/127.0.0.1/tcp/1234", "047F0000010604D2", vec![IP4, TCP]); - ma_valid("/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", + ma_valid("/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "047F000001A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![IP4, IPFS]); - ma_valid("/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", + vec![IP4, P2P]); + ma_valid("/ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234", "047F000001A503221220D52EBB89D85B02A284948203A\ 62FF28389C57C9F42BEEC4EC20DB76A68911C0B0604D2", - vec![IP4, IPFS, TCP]); + vec![IP4, P2P, TCP]); // /unix/a/b/c/d/e, // /unix/stdio, // /ip4/1.2.3.4/tcp/80/unix/a/b/c/d/e/f, - // /ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio + // /ip4/127.0.0.1/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234/unix/stdio ma_valid("/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:\ - 7095/tcp/8000/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", + 7095/tcp/8000/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "29200108A07AC542013AC986FFFE317095061F40DD03A5\ 03221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![IP6, TCP, WS, IPFS]); + vec![IP6, TCP, WS, P2P]); ma_valid("/p2p-webrtc-star/ip4/127.0.0.\ - 1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", + 1/tcp/9090/ws/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "9302047F000001062382DD03A503221220D52EBB89D85B\ 02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![Libp2pWebrtcStar, IP4, TCP, WS, IPFS]); + vec![Libp2pWebrtcStar, IP4, TCP, WS, P2P]); ma_valid("/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:\ - 7095/tcp/8000/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", + 7095/tcp/8000/wss/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "29200108A07AC542013AC986FFFE317095061F40DE03A503221220D52EBB8\ 9D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![IP6, TCP, WSS, IPFS]); - ma_valid("/ip4/127.0.0.1/tcp/9090/p2p-circuit/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", + vec![IP6, TCP, WSS, P2P]); + ma_valid("/ip4/127.0.0.1/tcp/9090/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC", "047F000001062382A202A503221220D52EBB89D85B\ 02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B", - vec![IP4, TCP, P2pCircuit, IPFS]); + vec![IP4, TCP, P2pCircuit, P2P]); } #[test] @@ -128,8 +128,8 @@ fn construct_fail() { "/ip4/127.0.0.1/udp", "/ip4/127.0.0.1/tcp/jfodsajfidosajfoidsa", "/ip4/127.0.0.1/tcp", - "/ip4/127.0.0.1/ipfs", - "/ip4/127.0.0.1/ipfs/tcp", + "/ip4/127.0.0.1/p2p", + "/ip4/127.0.0.1/p2p/tcp", "/p2p-circuit/50"]; for address in &addresses { diff --git a/relay/src/utility.rs b/relay/src/utility.rs index 0b51876260a..3908386ecf5 100644 --- a/relay/src/utility.rs +++ b/relay/src/utility.rs @@ -145,7 +145,7 @@ pub(crate) struct Peer { impl Peer { pub(crate) fn from(mut addr: Multiaddr) -> Option { match addr.pop() { - Some(AddrComponent::P2P(id)) | Some(AddrComponent::IPFS(id)) => { + Some(AddrComponent::P2P(id)) => { PeerId::from_bytes(id).ok().map(|pid| { if addr.iter().count() == 0 { Peer {