mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-15 12:13:24 +00:00
Buffer methods
- Fixed final bencode.h dependencies in AlignedBuffer that was pending refactor of other types - Last traces of any non-oxenc bencode are done - Next is TCP listeners!
This commit is contained in:
parent
078d0dfc23
commit
9e6a334da3
@ -2,6 +2,7 @@
|
||||
|
||||
#include <llarp/crypto/constants.hpp>
|
||||
#include <llarp/util/aligned.hpp>
|
||||
#include <llarp/util/buffer.hpp>
|
||||
#include <llarp/util/concept.hpp>
|
||||
|
||||
/** TODO:
|
||||
|
@ -122,14 +122,13 @@ namespace llarp
|
||||
std::unordered_map<NetworkAddress, auth::AuthInfo> exit_auths;
|
||||
std::unordered_map<std::string, auth::AuthInfo> ons_exit_auths;
|
||||
|
||||
// RPC and File auth values
|
||||
auth::AuthType auth_type = auth::AuthType::NONE;
|
||||
auth::AuthFileType auth_file_type = auth::AuthFileType::HASHES;
|
||||
std::optional<std::string> auth_url;
|
||||
std::optional<std::string> auth_method;
|
||||
|
||||
std::unordered_set<NetworkAddress> auth_whitelist;
|
||||
std::unordered_set<std::string> auth_static_tokens;
|
||||
|
||||
std::set<fs::path> auth_files;
|
||||
|
||||
std::vector<llarp::dns::SRVData> srv_records;
|
||||
|
@ -10,37 +10,6 @@
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
// bool PubKey::from_hex(const std::string& str)
|
||||
// {
|
||||
// if (str.size() != 2 * size())
|
||||
// return false;
|
||||
// oxenc::from_hex(str.begin(), str.end(), begin());
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// PubKey PubKey::make_from_hex(const std::string& s)
|
||||
// {
|
||||
// PubKey p;
|
||||
// oxenc::from_hex(s.begin(), s.end(), p.begin());
|
||||
// return p;
|
||||
// }
|
||||
|
||||
// std::string PubKey::to_string() const
|
||||
// {
|
||||
// return oxenc::to_hex(begin(), end());
|
||||
// }
|
||||
|
||||
// PubKey& PubKey::operator=(const uint8_t* ptr)
|
||||
// {
|
||||
// std::copy(ptr, ptr + SIZE, begin());
|
||||
// return *this;
|
||||
// }
|
||||
|
||||
// bool operator==(const PubKey& lhs, const PubKey& rhs)
|
||||
// {
|
||||
// return lhs.as_array() == rhs.as_array();
|
||||
// }
|
||||
|
||||
PubKey SecretKey::to_pubkey() const
|
||||
{
|
||||
return PubKey(data() + 32);
|
||||
@ -49,7 +18,9 @@ namespace llarp
|
||||
bool SecretKey::load_from_file(const fs::path& fname)
|
||||
{
|
||||
size_t sz;
|
||||
std::array<uint8_t, 128> tmp;
|
||||
std::string tmp;
|
||||
tmp.resize(128);
|
||||
|
||||
try
|
||||
{
|
||||
sz = util::file_to_buffer(fname, tmp.data(), tmp.size());
|
||||
@ -66,8 +37,7 @@ namespace llarp
|
||||
return true;
|
||||
}
|
||||
|
||||
llarp_buffer_t buf(tmp);
|
||||
return BDecode(&buf);
|
||||
return bt_decode(tmp);
|
||||
}
|
||||
|
||||
bool SecretKey::recalculate()
|
||||
|
@ -128,7 +128,4 @@ namespace llarp
|
||||
|
||||
/// PKE(result, publickey, secretkey, nonce)
|
||||
using path_dh_func = bool (*)(SharedSecret&, const PubKey&, const SecretKey&, const TunnelNonce&);
|
||||
|
||||
/// SH(result, body)
|
||||
using shorthash_func = bool (*)(ShortHash&, const llarp_buffer_t&);
|
||||
} // namespace llarp
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "srv_data.hpp"
|
||||
|
||||
// #include <llarp/util/bencode.h>
|
||||
#include <llarp/util/str.hpp>
|
||||
#include <llarp/util/types.hpp>
|
||||
|
||||
|
@ -47,7 +47,6 @@ namespace llarp::handlers
|
||||
|
||||
void LocalEndpoint::configure()
|
||||
{
|
||||
// auto _dns_config = _router.config()->dns;
|
||||
auto net_config = _router.config()->network;
|
||||
|
||||
if (net_config.is_reachable)
|
||||
@ -68,6 +67,9 @@ namespace llarp::handlers
|
||||
_local_introset.exit_policy = _exit_policy;
|
||||
}
|
||||
|
||||
if (not net_config.srv_records.empty())
|
||||
_local_introset.SRVs = std::move(net_config.srv_records);
|
||||
|
||||
_if_name = *net_config._if_name;
|
||||
_local_range = *net_config._local_ip_range;
|
||||
_local_addr = *net_config._local_addr;
|
||||
|
@ -34,7 +34,7 @@ namespace llarp
|
||||
struct PathHopConfig;
|
||||
|
||||
/// A path we made
|
||||
struct Path final : public std::enable_shared_from_this<Path>
|
||||
struct Path : public std::enable_shared_from_this<Path>
|
||||
{
|
||||
std::vector<PathHopConfig> hops;
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "vanity.hpp"
|
||||
|
||||
#include <llarp/address/address.hpp>
|
||||
#include <llarp/constants/proto.hpp>
|
||||
#include <llarp/crypto/types.hpp>
|
||||
|
||||
#include <oxenc/bt.h>
|
||||
|
@ -3,8 +3,8 @@
|
||||
#include <llarp/crypto/crypto.hpp>
|
||||
#include <llarp/nodedb.hpp>
|
||||
#include <llarp/path/path.hpp>
|
||||
#include <llarp/path/path_context.hpp>
|
||||
#include <llarp/router/router.hpp>
|
||||
#include <llarp/util/formattable.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
@ -87,7 +87,7 @@ namespace llarp::session
|
||||
path::PathHandler::path_build_succeeded(remote, p);
|
||||
|
||||
// TODO: add callback here
|
||||
if (p->obtain_exit(_auth->session_key(), _is_snode_service ? 1 : 0, p->TXID().bt_encode()))
|
||||
if (p->obtain_exit(_auth->session_key(), _is_snode_service ? 1 : 0, p->TXID().to_string()))
|
||||
log::info(logcat, "Asking {} for exit", _remote_router);
|
||||
else
|
||||
log::warning(logcat, "Failed to send exit request");
|
||||
@ -156,7 +156,7 @@ namespace llarp::session
|
||||
|
||||
void OutboundSession::send_path_close(std::shared_ptr<path::Path> p)
|
||||
{
|
||||
if (p->close_exit(_auth->session_key(), p->TXID().bt_encode()))
|
||||
if (p->close_exit(_auth->session_key(), p->TXID().to_string()))
|
||||
log::info(logcat, "Sent path close on path {}", p->to_string());
|
||||
else
|
||||
log::warning(logcat, "Failed to send path close on path {}", p->to_string());
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <llarp/auth/auth.hpp>
|
||||
#include <llarp/constants/path.hpp>
|
||||
#include <llarp/path/path_handler.hpp>
|
||||
#include <llarp/util/concept.hpp>
|
||||
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "bencode.h"
|
||||
#include "formattable.hpp"
|
||||
#include "logging.hpp"
|
||||
|
||||
#include <oxenc/bt.h>
|
||||
#include <oxenc/hex.h>
|
||||
|
||||
#include <algorithm>
|
||||
@ -202,18 +202,6 @@ namespace llarp
|
||||
return _data.cend();
|
||||
}
|
||||
|
||||
// TODO: move to .cpp file to add static logcat def
|
||||
bool FromBytestring(llarp_buffer_t* buf)
|
||||
{
|
||||
if (buf->sz != sz)
|
||||
{
|
||||
// log::error(logcat, "bdecode buffer size mismatch {}!={}", buf->sz, sz);
|
||||
return false;
|
||||
}
|
||||
memcpy(data(), buf->base, sz);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool from_string(std::string_view b)
|
||||
{
|
||||
if (b.size() != sz)
|
||||
@ -226,24 +214,15 @@ namespace llarp
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bt_encode(llarp_buffer_t* buf) const
|
||||
{
|
||||
return bencode_write_bytestring(buf, data(), sz);
|
||||
}
|
||||
|
||||
std::string bt_encode() const
|
||||
{
|
||||
return {reinterpret_cast<const char*>(data()), sz};
|
||||
return oxenc::bt_serialize(_data);
|
||||
}
|
||||
|
||||
bool BDecode(llarp_buffer_t* buf)
|
||||
bool bt_decode(std::string buf)
|
||||
{
|
||||
llarp_buffer_t strbuf;
|
||||
if (!bencode_read_string(buf, &strbuf))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return FromBytestring(&strbuf);
|
||||
oxenc::bt_deserialize<decltype(*this)>(buf, *this);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string_view to_view() const
|
||||
|
@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "buffer.hpp"
|
||||
#include "common.hpp"
|
||||
|
||||
#include <llarp/constants/proto.hpp>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* bencode.h
|
||||
*
|
||||
* helper functions for handling bencoding
|
||||
* https://en.wikipedia.org/wiki/Bencode for more information on the format
|
||||
* we utilize llarp_buffer which provides memory management
|
||||
*/
|
||||
|
||||
bool bencode_read_integer(llarp_buffer_t* buffer, uint64_t* result);
|
||||
|
||||
bool bencode_read_string(llarp_buffer_t* buffer, llarp_buffer_t* result);
|
||||
|
||||
bool bencode_write_bytestring(llarp_buffer_t* buff, const void* data, size_t sz);
|
||||
|
||||
bool bencode_write_uint64(llarp_buffer_t* buff, uint64_t i);
|
||||
|
||||
/// Write a dictionary entry with a uint64_t value
|
||||
bool bencode_write_uint64_entry(llarp_buffer_t* buff, const void* name, size_t sz, uint64_t i);
|
||||
|
||||
bool bencode_start_list(llarp_buffer_t* buff);
|
||||
|
||||
bool bencode_start_dict(llarp_buffer_t* buff);
|
||||
|
||||
bool bencode_end(llarp_buffer_t* buff);
|
||||
|
||||
/// read next member, discard it and advance buffer
|
||||
bool bencode_discard(llarp_buffer_t* buf);
|
@ -48,72 +48,6 @@ namespace llarp
|
||||
{
|
||||
return {reinterpret_cast<const uint8_t*>(v.data()), v.size()};
|
||||
}
|
||||
|
||||
struct llarp_buffer
|
||||
{
|
||||
private:
|
||||
std::string _buf;
|
||||
std::string_view _bview;
|
||||
size_t _size;
|
||||
|
||||
public:
|
||||
llarp_buffer() = default;
|
||||
llarp_buffer(size_t s) : _size{s}
|
||||
{
|
||||
_buf.reserve(_size);
|
||||
_bview = {_buf};
|
||||
}
|
||||
llarp_buffer(std::string& b) : _buf{std::move(b)}, _bview{_buf}, _size{_buf.size()}
|
||||
{}
|
||||
llarp_buffer(std::string_view bv) : _buf{bv}, _bview{_buf}, _size{_buf.size()}
|
||||
{}
|
||||
|
||||
template <
|
||||
typename CharT,
|
||||
std::enable_if_t<std::is_convertible_v<CharT, char> || std::is_constructible_v<std::string, CharT>, int> =
|
||||
0>
|
||||
llarp_buffer(CharT* c) : _buf{c}, _bview{_buf}, _size{_buf.size()}
|
||||
{}
|
||||
|
||||
std::string_view view() const
|
||||
{
|
||||
return _bview;
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
|
||||
bool is_empty() const
|
||||
{
|
||||
return _buf.empty();
|
||||
}
|
||||
|
||||
char* data()
|
||||
{
|
||||
return _buf.data();
|
||||
}
|
||||
char* data_at(size_t pos)
|
||||
{
|
||||
return _buf.data() + pos;
|
||||
}
|
||||
|
||||
const char* vdata()
|
||||
{
|
||||
return _bview.data();
|
||||
}
|
||||
const char* vdata_at(size_t pos)
|
||||
{
|
||||
return _bview.data() + pos;
|
||||
}
|
||||
|
||||
char operator[](size_t pos)
|
||||
{
|
||||
return *(data() + pos);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace llarp
|
||||
|
||||
struct ManagedBuffer;
|
||||
|
Loading…
Reference in New Issue
Block a user