Commit 6de0dae0 authored by Ivan Vilata-i-Balaguer's avatar Ivan Vilata-i-Balaguer
Browse files

Merge branch 'swarm-name-fixes'.

Among other minor fixes, this allows the client to cache the URI swarm name
prefix, avoiding extra encoding every time it is needed.
parents 1d32a9b6 3a1d55ef
......@@ -19,12 +19,17 @@ std::string compute_bridge_swarm_name(const ouinet::util::Ed25519PublicKey& pubk
, "/bridges");
}
std::string compute_uri_swarm_name(const ouinet::util::Ed25519PublicKey& pubkey, unsigned protocol_version, boost::string_view key)
std::string compute_uri_swarm_prefix(const ouinet::util::Ed25519PublicKey& pubkey, unsigned protocol_version)
{
return util::str
( "ed25519:", util::base32up_encode(pubkey.serialize())
, "/v", protocol_version
, "/uri/", key);
, "/uri/");
}
std::string compute_uri_swarm_name(boost::string_view prefix, boost::string_view uri)
{
return util::str(prefix, uri);
}
}} // namespaces
......@@ -4,10 +4,47 @@
namespace ouinet { namespace bep5 {
// https://redmine.equalit.ie/issues/14920#note-1
std::string compute_injector_swarm_name(const ouinet::util::Ed25519PublicKey&, unsigned protocol_version);
std::string compute_bridge_swarm_name(const ouinet::util::Ed25519PublicKey&, unsigned protocol_version);
std::string compute_uri_swarm_name(const ouinet::util::Ed25519PublicKey&, unsigned protocol_version, boost::string_view key);
// Ouinet swarm names are constructed following this pattern:
//
// <KEY_TYPE>:<BASE32(INJECTOR_PUBKEY)>/v<VERSION>/<WHAT>
//
// `KEY_TYPE` indicates the type of injector key following.
// Currently `ed25519` is the only supported value.
//
// `BASE32(INJECTOR_KEY)` is the unpadded, lower case result of
// encoding the injector public key using Base32.
//
// `VERSION` is the Ouinet protocol version number (decimal).
//
// `WHAT` depends on the protocol version and
// the kind of information made available via the swarm.
// Currently supported values for v4 are:
//
// - `injectors`: uTP endpoints for reaching injectors
// with the given `INJECTOR_KEY`.
//
// - `bridges`: uTP endpoints for reaching bridges to
// injectors with the given `INJECTOR_KEY`.
//
// - `uri/<URI>`: uTP endpoints for reaching clients keeping a cached copy of
// the given `URI` signed with the given `INJECTOR_KEY`.
//
// Please bear in mind that BitTorrent DHT IDs are not the swarm names themselves,
// but their respective SHA1 digests.
std::string compute_injector_swarm_name( const ouinet::util::Ed25519PublicKey&
, unsigned protocol_version);
std::string compute_bridge_swarm_name( const ouinet::util::Ed25519PublicKey&
, unsigned protocol_version);
// Reuse the resulting prefix with `compute_uri_swarm_name` below.
std::string compute_uri_swarm_prefix( const ouinet::util::Ed25519PublicKey&
, unsigned protocol_version);
// Reuse the prefix resulting from `compute_uri_swarm_prefix` above.
std::string compute_uri_swarm_name( boost::string_view prefix
, boost::string_view uri);
}} // namespaces
......@@ -36,6 +36,7 @@ struct Client::Impl {
asio::executor ex;
shared_ptr<bt::MainlineDht> dht;
string uri_swarm_prefix;
util::Ed25519PublicKey cache_pk;
fs::path cache_dir;
unique_ptr<cache::AbstractHttpStore> http_store;
......@@ -59,6 +60,8 @@ struct Client::Impl {
, log_level_t log_level)
: ex(dht_->get_executor())
, dht(move(dht_))
, uri_swarm_prefix(bep5::compute_uri_swarm_prefix
(cache_pk, http_::protocol_version_current))
, cache_pk(cache_pk)
, cache_dir(move(cache_dir))
, http_store(move(http_store))
......@@ -70,8 +73,7 @@ struct Client::Impl {
std::string compute_swarm_name(boost::string_view dht_group) const {
return bep5::compute_uri_swarm_name(
cache_pk,
http_::protocol_version_current,
uri_swarm_prefix,
dht_group);
}
......
......@@ -43,7 +43,7 @@ struct to_5_bit {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,26,27,28,29,30,31,-1,-1,-1,-1,-1, 0,-1,-1, // render '=' as 0
14, 8,26,27,28,29,30,31, 1, 6,-1,-1,-1, 0,-1,-1, // render '=' as 0
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment