Skip to content

Commit b7712da

Browse files
authored
Fix handling addresses starting from p2p (#80)
Signed-off-by: kamilsa <[email protected]>
1 parent 9aabc10 commit b7712da

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/multi/multiaddress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ namespace libp2p::multi {
175175
if (protocol == nullptr) {
176176
return {};
177177
}
178-
auto proto_str = "/"s + std::string(protocol->name);
178+
auto proto_str = "/"s + std::string(protocol->name) + "/";
179179
auto proto_positions =
180180
findSubstringOccurrences(stringified_address_, proto_str);
181181
if (proto == Protocol::Code::P2P) { // ipfs and p2p are equivalent

test/libp2p/multi/multiaddress_test.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ TEST_F(MultiaddressTest, GetProtocolsWithValues) {
251251
*/
252252
TEST_F(MultiaddressTest, DnsAndIpfs) {
253253
auto addr =
254-
"/dns4/kusama-bootnode-1.paritytech.net/tcp/30333/p2p/QmV32G18YzenpNFmhqg2n7TtdjYRK7oU6FhLbDL4oRgsbe"s;
254+
"/dns4/p2p.cc3-0.kusama.network/tcp/30100/p2p/12D3KooWDgtynm4S9M3m6ZZhXYu2RrWKdvkCSScc25xKDVSg1Sjd"s;
255255
EXPECT_OUTCOME_TRUE(address, Multiaddress::create(addr));
256256
ASSERT_EQ(address.getStringAddress(), addr);
257+
auto peer_id_opt = address.getPeerId();
258+
ASSERT_TRUE(peer_id_opt);
259+
ASSERT_EQ(peer_id_opt.value(),
260+
"12D3KooWDgtynm4S9M3m6ZZhXYu2RrWKdvkCSScc25xKDVSg1Sjd");
257261
}

0 commit comments

Comments
 (0)