mirror of https://github.com/libp2p/cpp-libp2p.git
Browse Source
* Add DNS processing to multiaddr * Fix IPFS resolution in multiaddr * Fix comment about IPFS/P2P in multiaddrpull/44/head
Harrm
5 years ago
committed by
GitHub
9 changed files with 91 additions and 12 deletions
@ -0,0 +1,25 @@ |
|||
/**
|
|||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. |
|||
* SPDX-License-Identifier: Apache-2.0 |
|||
*/ |
|||
|
|||
#ifndef LIBP2P_DNS_CONVERTER_HPP |
|||
#define LIBP2P_DNS_CONVERTER_HPP |
|||
|
|||
#include <libp2p/outcome/outcome.hpp> |
|||
|
|||
namespace libp2p::multi::converters { |
|||
|
|||
/**
|
|||
* Converts a DNS part of a multiaddress (a hostname) |
|||
* to bytes representation as a hex string |
|||
*/ |
|||
class DnsConverter { |
|||
public: |
|||
static auto addressToHex(std::string_view addr) |
|||
-> outcome::result<std::string>; |
|||
}; |
|||
|
|||
} // namespace libp2p::multi::converters
|
|||
|
|||
#endif // LIBP2P_DNS_CONVERTER_HPP
|
@ -0,0 +1,20 @@ |
|||
/**
|
|||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. |
|||
* SPDX-License-Identifier: Apache-2.0 |
|||
*/ |
|||
|
|||
#include <libp2p/multi/converters/dns_converter.hpp> |
|||
|
|||
#include <libp2p/common/hexutil.hpp> |
|||
#include <libp2p/multi/uvarint.hpp> |
|||
|
|||
namespace libp2p::multi::converters { |
|||
|
|||
auto DnsConverter::addressToHex(std::string_view addr) |
|||
-> outcome::result<std::string> { |
|||
std::vector<uint8_t> bytes(addr.size()); |
|||
std::copy(addr.begin(), addr.end(), bytes.begin()); |
|||
auto hex = common::hex_lower(bytes); |
|||
return UVarint{bytes.size()}.toHex() + hex; |
|||
} |
|||
} |
Loading…
Reference in new issue