Merge branch 'staging' of ssh://github.com/loki-project/loki-network into staging

pull/236/head
Jeff Becker 5 years ago
commit 015e68df68
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -292,12 +292,14 @@ endif(NOT WIN32)
set(LIB_UTIL_SRC
llarp/constants/defaults.cpp
llarp/constants/link_layer.cpp
llarp/constants/proto.cpp
llarp/constants/version.cpp
llarp/util/aligned.cpp
llarp/util/bencode.cpp
llarp/util/bits.cpp
llarp/util/buffer.cpp
llarp/util/codel.cpp
llarp/util/common.cpp
llarp/util/encode.cpp
llarp/util/endian.cpp
@ -489,17 +491,19 @@ set(LIB_SRC
${DNSLIB_SRC}
${EV_SRC}
${UTP_SRC}
llarp/address_info.cpp
llarp/codel.cpp
llarp/config.cpp
llarp/context.cpp
llarp/crypto.cpp
llarp/crypto_libsodium.cpp
llarp/dht.cpp
llarp/crypto/constants.cpp
llarp/crypto/crypto_libsodium.cpp
llarp/crypto/crypto.cpp
llarp/crypto/encrypted_frame.cpp
llarp/crypto/encrypted.cpp
llarp/crypto/types.cpp
llarp/dht/bucket.cpp
llarp/dht/context.cpp
llarp/dht/decode.cpp
llarp/dht/dht_immediate.cpp
llarp/dht/dht.cpp
llarp/dht/find_intro.cpp
llarp/dht/find_router.cpp
llarp/dht/got_intro.cpp
@ -518,10 +522,6 @@ set(LIB_SRC
llarp/dns.cpp
llarp/dnsc.cpp
llarp/dnsd.cpp
llarp/encrypted.cpp
llarp/encrypted_ack.cpp
llarp/encrypted_frame.cpp
llarp/establish_job.cpp
llarp/exit/close_exit.cpp
llarp/exit/context.cpp
llarp/exit/endpoint.cpp
@ -532,54 +532,50 @@ set(LIB_SRC
llarp/exit/session.cpp
llarp/exit/transfer_traffic.cpp
llarp/exit/update_exit.cpp
llarp/exit_info.cpp
llarp/handlers/exit.cpp
llarp/handlers/null.cpp
llarp/handlers/tun.cpp
llarp/ip.cpp
llarp/link/curvecp.cpp
llarp/link/encoder.cpp
llarp/link/iwp.cpp
llarp/link/server.cpp
llarp/link/session.cpp
llarp/link/utp.cpp
llarp/link_intro.cpp
llarp/link_layer.cpp
llarp/link_message.cpp
llarp/messages/dht.cpp
llarp/messages/dht_immediate.cpp
llarp/messages/discard.cpp
llarp/messages/exit.cpp
llarp/messages/link_intro.cpp
llarp/messages/link_message.cpp
llarp/messages/path_confirm.cpp
llarp/messages/path_latency.cpp
llarp/messages/path_transfer.cpp
llarp/messages/relay.cpp
llarp/messages/relay_commit.cpp
llarp/messages/transfer_traffic.cpp
llarp/net/address_info.cpp
llarp/net/exit_info.cpp
llarp/net/ip.cpp
llarp/net/net_int.cpp
llarp/nodedb.cpp
llarp/path/path.cpp
llarp/path/path_types.cpp
llarp/path/pathbuilder.cpp
llarp/path/pathset.cpp
llarp/path/transit_hop.cpp
llarp/pow.cpp
llarp/profiling.cpp
llarp/proofofwork.cpp
llarp/relay_commit.cpp
llarp/relay_up_down.cpp
llarp/router.cpp
llarp/router/router.cpp
llarp/router_contact.cpp
llarp/router_id.cpp
llarp/routing/dht_message.cpp
llarp/routing/handler.cpp
llarp/routing/message.cpp
llarp/routing/message_parser.cpp
llarp/routing/message.cpp
llarp/routing/path_confirm.cpp
llarp/routing/path_latency.cpp
llarp/routing/path_transfer.cpp
llarp/routing_endpoint.cpp
llarp/rpc.cpp
llarp/rpc/rpc.cpp
llarp/service/Identity.cpp
llarp/service/Intro.cpp
llarp/service/IntroSet.cpp
@ -595,7 +591,6 @@ set(LIB_SRC
llarp/service/types.cpp
llarp/service/vanity.cpp
llarp/testnet.c
llarp/transit_hop.cpp
)
set(RC_SRC
@ -614,24 +609,28 @@ set(DNS_SRC
)
set(TEST_SRC
# helpers
test/main.cpp
test/test_util.cpp
# actual test cases
test/crypto/test_llarp_crypto_types.cpp
test/crypto/test_llarp_crypto.cpp
test/dht/test_llarp_dht_key.cpp
test/dht/test_llarp_dht.cpp
test/dns/test_llarp_dns_dns.cpp
test/exit/test_llarp_exit_context.cpp
test/link/test_llarp_link.cpp
test/main.cpp
test/net/test_llarp_net_inaddr.cpp
test/net/test_llarp_net.cpp
test/routing/llarp_routing_transfer_traffic.cpp
test/routing/test_llarp_routing_obtainexitmessage.cpp
test/service/test_llarp_service_address.cpp
test/service/test_llarp_service_identity.cpp
test/test_llarp_crypto.cpp
test/test_llarp_dns.cpp
test/test_llarp_dnsd.cpp
test/test_llarp_encrypted_frame.cpp
test/test_llarp_router.cpp
test/test_llarp_router_contact.cpp
test/test_llarp_router.cpp
test/util/test_llarp_util_aligned.cpp
test/util/test_llarp_util_bencode.cpp
test/util/test_llarp_util_encode.cpp
@ -707,7 +706,10 @@ else()
add_executable(${TEST_EXE} ${TEST_SRC} llarp/version.rc)
add_executable(${EXE} ${EXE_SRC} llarp/version.rc)
endif(NOT WIN32)
target_include_directories(${TEST_EXE} PRIVATE test)
target_include_directories(${TEST_EXE} PRIVATE ${GTEST_DIR}/include ${GTEST_DIR})
install(TARGETS ${EXE} RUNTIME DESTINATION bin)
if(WIN32)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin)

@ -1,5 +1,5 @@
#include <buffer.hpp>
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <fs.hpp>
#include <llarp.h>
#include <logger.hpp>

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 KiB

@ -0,0 +1,102 @@
digraph {
constants -> util;
crypto -> constants;
crypto -> llarp;
crypto -> util;
dht -> crypto;
dht -> messages;
dht -> llarp;
dht -> path;
dht -> routing;
dht -> service;
dht -> util;
dns -> crypto;
dns -> ev;
dns -> handlers;
dns -> llarp;
dns -> net;
dns -> service;
dns -> util;
ev -> net;
ev -> util;
exit -> crypto;
exit -> handlers;
exit -> messages;
exit -> net;
exit -> path;
exit -> routing;
exit -> util;
handlers -> dns;
handlers -> ev;
handlers -> exit;
handlers -> net;
handlers -> service;
handlers -> util;
link -> constants;
link -> crypto;
link -> ev;
link -> messages;
link -> net;
link -> util;
messages -> crypto;
messages -> dht;
messages -> exit;
messages -> link;
messages -> llarp;
messages -> path;
messages -> routing;
messages -> service;
messages -> util;
net -> crypto;
net -> util;
path -> crypto;
path -> dht;
path -> llarp;
path -> messages;
path -> routing;
path -> service;
path -> util;
routing -> llarp;
routing -> messages;
routing -> path;
routing -> util;
service -> crypto;
service -> dht;
service -> ev;
service -> exit;
service -> handlers;
service -> messages;
service -> net;
service -> path;
service -> routing;
service -> util;
util -> constants;
llarp -> constants;
llarp -> crypto;
llarp -> dht;
llarp -> dns;
llarp -> ev;
llarp -> exit;
llarp -> handlers;
llarp -> link;
llarp -> messages;
llarp -> net;
llarp -> path;
llarp -> routing;
llarp -> service;
llarp -> util;
}

@ -1,8 +1,7 @@
#ifndef LLARP_HPP
#define LLARP_HPP
#include <crypto.hpp>
#include <util/threading.hpp>
#include <util/types.hpp>
#include <iostream>
#include <memory>
@ -14,9 +13,11 @@ struct llarp_config_iterator;
struct llarp_ev_loop;
struct llarp_nodedb;
struct llarp_nodedb_iter;
struct llarp_threadpool;
namespace llarp
{
struct Crypto;
class Logic;
struct Router;
struct RouterContact;

@ -1,6 +1,6 @@
#include <abyss/client.hpp>
#include <abyss/http.hpp>
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <util/buffer.hpp>
#include <util/logger.hpp>

@ -22,7 +22,7 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "ifaddrs.h"
#include <android/ifaddrs.h>
#include <string.h>
#include <stdlib.h>

@ -1 +0,0 @@
#include <codel.hpp>

@ -0,0 +1 @@
#include <constants/link_layer.hpp>

@ -6,7 +6,7 @@
#include <dnsd.hpp>
#include <ev/ev.hpp>
#include <nodedb.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/logger.h>
#include <getopt.h>

@ -0,0 +1 @@
#include <crypto/constants.hpp>

@ -0,0 +1,25 @@
#ifndef LLARP_CRYPTO_CONSTANTS_HPP
#define LLARP_CRYPTO_CONSTANTS_HPP
#include <stdint.h>
#include <libntrup/ntru.h>
static constexpr uint32_t PUBKEYSIZE = 32;
static constexpr uint32_t SECKEYSIZE = 64;
static constexpr uint32_t NONCESIZE = 24;
static constexpr uint32_t SHAREDKEYSIZE = 32;
static constexpr uint32_t HASHSIZE = 64;
static constexpr uint32_t SHORTHASHSIZE = 32;
static constexpr uint32_t HMACSECSIZE = 32;
static constexpr uint32_t SIGSIZE = 64;
static constexpr uint32_t TUNNONCESIZE = 32;
static constexpr uint32_t HMACSIZE = 32;
static constexpr uint32_t PATHIDSIZE = 16;
static constexpr uint32_t PQ_CIPHERTEXTSIZE = crypto_kem_CIPHERTEXTBYTES;
static constexpr uint32_t PQ_PUBKEYSIZE = crypto_kem_PUBLICKEYBYTES;
static constexpr uint32_t PQ_SECRETKEYSIZE = crypto_kem_SECRETKEYBYTES;
static constexpr uint32_t PQ_KEYPAIRSIZE = (PQ_SECRETKEYSIZE + PQ_PUBKEYSIZE);
#endif

@ -0,0 +1 @@
#include <crypto/crypto.hpp>

@ -1,12 +1,10 @@
#ifndef LLARP_CRYPTO_HPP
#define LLARP_CRYPTO_HPP
#include <router_id.hpp>
#include <util/aligned.hpp>
#include <crypto/constants.hpp>
#include <crypto/types.hpp>
#include <util/buffer.h>
#include <util/common.hpp>
#include <util/mem.h>
#include <util/threadpool.h>
#include <functional>
#include <stdbool.h>
@ -19,123 +17,8 @@
* potentially allow libssl support in the future
*/
static constexpr uint32_t PUBKEYSIZE = 32;
static constexpr uint32_t SECKEYSIZE = 64;
static constexpr uint32_t NONCESIZE = 24;
static constexpr uint32_t SHAREDKEYSIZE = 32;
static constexpr uint32_t HASHSIZE = 64;
static constexpr uint32_t SHORTHASHSIZE = 32;
static constexpr uint32_t HMACSECSIZE = 32;
static constexpr uint32_t SIGSIZE = 64;
static constexpr uint32_t TUNNONCESIZE = 32;
static constexpr uint32_t HMACSIZE = 32;
static constexpr uint32_t PATHIDSIZE = 16;
#include <libntrup/ntru.h>
#define PQ_CIPHERTEXTSIZE crypto_kem_CIPHERTEXTBYTES
#define PQ_PUBKEYSIZE crypto_kem_PUBLICKEYBYTES
#define PQ_SECRETKEYSIZE crypto_kem_SECRETKEYBYTES
#define PQ_KEYPAIRSIZE (PQ_SECRETKEYSIZE + PQ_PUBKEYSIZE)
namespace llarp
{
using SharedSecret = AlignedBuffer< SHAREDKEYSIZE >;
using KeyExchangeNonce = AlignedBuffer< 32 >;
struct PubKey final : public AlignedBuffer< PUBKEYSIZE >
{
PubKey() : AlignedBuffer< SIZE >()
{
}
explicit PubKey(const byte_t *ptr) : AlignedBuffer< SIZE >(ptr)
{
}
explicit PubKey(const Data &data) : AlignedBuffer< SIZE >(data)
{
}
explicit PubKey(const AlignedBuffer< SIZE > &other)
: AlignedBuffer< SIZE >(other)
{
}
std::string
ToString() const;
bool
FromString(const std::string &str);
friend std::ostream &
operator<<(std::ostream &out, const PubKey &k)
{
return out << k.ToString();
}
operator RouterID() const
{
return RouterID(as_array());
}
PubKey &
operator=(const byte_t *ptr)
{
std::copy(ptr, ptr + SIZE, begin());
return *this;
}
};
struct SecretKey final : public AlignedBuffer< SECKEYSIZE >
{
SecretKey() : AlignedBuffer< SECKEYSIZE >(){};
explicit SecretKey(const SecretKey &k) : AlignedBuffer< SECKEYSIZE >(k)
{
}
explicit SecretKey(const byte_t *ptr) : AlignedBuffer< SECKEYSIZE >(ptr)
{
}
friend std::ostream &
operator<<(std::ostream &out, const SecretKey &)
{
// make sure we never print out secret keys
return out << "[secretkey]";
}
PubKey
toPublic() const
{
return PubKey(data() + 32);
}
bool
LoadFromFile(const char *fname);
bool
SaveToFile(const char *fname) const;
SecretKey &
operator=(const byte_t *ptr)
{
std::copy(ptr, ptr + SIZE, begin());
return *this;
}
};
using ShortHash = AlignedBuffer< SHORTHASHSIZE >;
using Signature = AlignedBuffer< SIGSIZE >;
using TunnelNonce = AlignedBuffer< TUNNONCESIZE >;
using SymmNonce = AlignedBuffer< NONCESIZE >;
using SymmKey = AlignedBuffer< 32 >;
using PQCipherBlock = AlignedBuffer< PQ_CIPHERTEXTSIZE + 1 >;
using PQPubKey = AlignedBuffer< PQ_PUBKEYSIZE >;
using PQKeyPair = AlignedBuffer< PQ_KEYPAIRSIZE >;
/// label functors
/// PKE(result, publickey, secretkey, nonce)

@ -1,4 +1,5 @@
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <sodium/crypto_generichash.h>
#include <sodium/crypto_sign.h>
#include <sodium/crypto_scalarmult.h>
@ -41,15 +42,14 @@ namespace llarp
{
llarp::SharedSecret shared;
crypto_generichash_state h;
const size_t outsz = SHAREDKEYSIZE;
if(crypto_scalarmult_curve25519(shared.data(), usSec.data(), themPub))
return false;
crypto_generichash_blake2b_init(&h, nullptr, 0U, outsz);
crypto_generichash_blake2b_init(&h, nullptr, 0U, shared.size());
crypto_generichash_blake2b_update(&h, client_pk.data(), 32);
crypto_generichash_blake2b_update(&h, server_pk.data(), 32);
crypto_generichash_blake2b_update(&h, shared.data(), 32);
crypto_generichash_blake2b_final(&h, out.data(), outsz);
crypto_generichash_blake2b_final(&h, out.data(), shared.size());
return true;
}

@ -0,0 +1 @@
#include <crypto/encrypted.hpp>

@ -1,7 +1,7 @@
#ifndef LLARP_ENCCRYPTED_HPP
#define LLARP_ENCCRYPTED_HPP
#ifndef LLARP_ENCRYPTED_HPP
#define LLARP_ENCRYPTED_HPP
#include <link_layer.hpp>
#include <constants/link_layer.hpp>
#include <util/aligned.hpp>
#include <util/bencode.h>
#include <util/buffer.h>

@ -1,6 +1,6 @@
#include <encrypted_frame.hpp>
#include <crypto/encrypted_frame.hpp>
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <util/logger.hpp>
#include <util/mem.hpp>

@ -1,14 +1,16 @@
#ifndef LLARP_ENCRYPTED_FRAME_HPP
#define LLARP_ENCRYPTED_FRAME_HPP
#include <crypto.hpp>
#include <encrypted.hpp>
#include <crypto/encrypted.hpp>
#include <crypto/types.hpp>
#include <util/buffer.hpp>
#include <util/mem.h>
#include <util/threadpool.h>
namespace llarp
{
struct Crypto;
static constexpr size_t EncryptedFrameOverheadSize =
PUBKEYSIZE + TUNNONCESIZE + SHORTHASHSIZE;
static constexpr size_t EncryptedFrameBodySize = 512;
@ -85,8 +87,7 @@ namespace llarp
otherKey = other;
if(buf.sz > EncryptedFrameBodySize)
return;
memcpy(frame.data() + PUBKEYSIZE + TUNNONCESIZE + SHORTHASHSIZE, buf.base,
buf.sz);
memcpy(frame.data() + EncryptedFrameOverheadSize, buf.base, buf.sz);
user = u;
llarp_threadpool_queue_job(worker, {this, &Encrypt});
}

@ -1,4 +1,4 @@
#include <crypto.hpp>
#include <crypto/types.hpp>
#include <util/buffer.hpp>
@ -23,30 +23,30 @@ namespace llarp
bool
SecretKey::LoadFromFile(const char* fname)
{
std::ifstream f;
f.open(fname, std::ios::binary);
std::ifstream f(fname, std::ios::in | std::ios::binary);
if(!f.is_open())
{
return false;
}
size_t sz = 0;
f.seekg(0, std::ios::end);
sz = f.tellg();
const size_t sz = f.tellg();
f.seekg(0, std::ios::beg);
if(sz == size())
{
// is raw buffer
std::copy(std::istream_iterator< byte_t >(f),
std::istream_iterator< byte_t >(), begin());
std::copy_n(std::istreambuf_iterator< char >(f), sz, begin());
return true;
}
byte_t tmp[128];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
std::array< byte_t, 128 > tmp;
llarp_buffer_t buf = llarp::Buffer(tmp);
if(sz > sizeof(tmp))
{
return false;
}
f.read((char*)tmp, sz);
f.read(reinterpret_cast< char* >(tmp.data()), sz);
return BDecode(&buf);
}

@ -0,0 +1,111 @@
#ifndef LLARP_CRYPTO_TYPES_HPP
#define LLARP_CRYPTO_TYPES_HPP
#include <crypto/constants.hpp>
#include <router_id.hpp>
#include <util/aligned.hpp>
#include <util/types.hpp>
#include <algorithm>
#include <iostream>
namespace llarp
{
using SharedSecret = AlignedBuffer< SHAREDKEYSIZE >;
using KeyExchangeNonce = AlignedBuffer< 32 >;
struct PubKey final : public AlignedBuffer< PUBKEYSIZE >
{
PubKey() : AlignedBuffer< SIZE >()
{
}
explicit PubKey(const byte_t *ptr) : AlignedBuffer< SIZE >(ptr)
{
}
explicit PubKey(const Data &data) : AlignedBuffer< SIZE >(data)
{
}
explicit PubKey(const AlignedBuffer< SIZE > &other)
: AlignedBuffer< SIZE >(other)
{
}
std::string
ToString() const;
bool
FromString(const std::string &str);
friend std::ostream &
operator<<(std::ostream &out, const PubKey &k)
{
return out << k.ToString();
}
operator RouterID() const
{
return RouterID(as_array());
}
PubKey &
operator=(const byte_t *ptr)
{
std::copy(ptr, ptr + SIZE, begin());
return *this;
}
};
struct SecretKey final : public AlignedBuffer< SECKEYSIZE >
{
SecretKey() : AlignedBuffer< SECKEYSIZE >(){};
explicit SecretKey(const SecretKey &k) : AlignedBuffer< SECKEYSIZE >(k)
{
}
explicit SecretKey(const byte_t *ptr) : AlignedBuffer< SECKEYSIZE >(ptr)
{
}
friend std::ostream &
operator<<(std::ostream &out, const SecretKey &)
{
// make sure we never print out secret keys
return out << "[secretkey]";
}
PubKey
toPublic() const
{
return PubKey(data() + 32);
}
bool
LoadFromFile(const char *fname);
bool
SaveToFile(const char *fname) const;
SecretKey &
operator=(const byte_t *ptr)
{
std::copy(ptr, ptr + SIZE, begin());
return *this;
}
};
using ShortHash = AlignedBuffer< SHORTHASHSIZE >;
using Signature = AlignedBuffer< SIGSIZE >;
using TunnelNonce = AlignedBuffer< TUNNONCESIZE >;
using SymmNonce = AlignedBuffer< NONCESIZE >;
using SymmKey = AlignedBuffer< 32 >;
using PQCipherBlock = AlignedBuffer< PQ_CIPHERTEXTSIZE + 1 >;
using PQPubKey = AlignedBuffer< PQ_PUBKEYSIZE >;
using PQKeyPair = AlignedBuffer< PQ_KEYPAIRSIZE >;
} // namespace llarp
#endif

@ -1,9 +1,10 @@
#ifndef LLARP_DHT_BUCKET_HPP
#define LLARP_DHT_BUCKET_HPP
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <dht/kademlia.hpp>
#include <dht/key.hpp>
#include <map>
#include <set>
#include <vector>

@ -1,8 +1,9 @@
#include <dht/context.hpp>
#include <dht/messages/gotrouter.hpp>
#include <messages/dht.hpp>
#include <messages/dht_immediate.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <vector>
@ -731,7 +732,8 @@ namespace llarp
void
Start(const TXOwner &peer) override
{
parent->DHTSendTo(peer.node.as_array(), new FindRouterMessage(peer.txid, target));
parent->DHTSendTo(peer.node.as_array(),
new FindRouterMessage(peer.txid, target));
}
virtual void

@ -1,8 +1,8 @@
#ifndef LLARP_DHT_CONTEXT_HPP
#define LLARP_DHT_CONTEXT_HPP
#include <dht.h>
#include <dht/bucket.hpp>
#include <dht/dht.h>
#include <dht/key.hpp>
#include <dht/message.hpp>
#include <dht/messages/findintro.hpp>

@ -1,6 +1,6 @@
#include <dht.h>
#include <dht/context.hpp>
#include "router_contact.hpp"
#include <dht/dht.h>
#include <router_contact.hpp>
llarp_dht_context::llarp_dht_context(llarp::Router *router)
{

@ -1,7 +1,7 @@
#ifndef LLARP_DHT_H_
#define LLARP_DHT_H_
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <router_contact.hpp>
#include <util/buffer.h>

@ -1,6 +1,6 @@
#include <messages/dht_immediate.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,8 +1,9 @@
#include <dht/context.hpp>
#include <dht/messages/findrouter.hpp>
#include <dht/context.hpp>
#include <dht/messages/gotrouter.hpp>
#include <messages/dht.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,7 +1,7 @@
#include <dht/context.hpp>
#include <dht/messages/gotintro.hpp>
#include <messages/dht.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,7 +1,7 @@
#include <dht/context.hpp>
#include <dht/messages/gotrouter.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,7 +1,7 @@
#ifndef LLARP_DHT_MESSAGE_HPP
#define LLARP_DHT_MESSAGE_HPP
#include <dht.h>
#include <dht/dht.h>
#include <dht/key.hpp>
#include <path/path_types.hpp>
#include <util/bencode.hpp>

@ -2,7 +2,7 @@
#include <dht/messages/pubintro.hpp>
#include <messages/dht.hpp>
#include <messages/dht_immediate.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,5 +1,7 @@
#include <dns/server.hpp>
#include <crypto/crypto.hpp>
namespace llarp
{
namespace dns

@ -1 +0,0 @@
#include <encrypted.hpp>

@ -1 +0,0 @@
#include <encrypted_ack.hpp>

@ -1,12 +0,0 @@
#ifndef LLARP_ENCRYPTED_ACK_HPP
#define LLARP_ENCRYPTED_ACK_HPP
#include <encrypted.hpp>
namespace llarp
{
struct Crypto;
} // namespace llarp
#endif

@ -1 +0,0 @@
#include <establish_job.hpp>

@ -1,35 +0,0 @@
#ifndef LLARP_ESTABLISH_JOB_HPP
#define LLARP_ESTABLISH_JOB_HPP
#include <router_contact.hpp>
namespace llarp
{
struct OutboundLinkEstablishJob
{
RouterContact rc;
OutboundLinkEstablishJob(const RouterContact& remote) : rc(remote)
{
}
virtual ~OutboundLinkEstablishJob(){};
virtual void
Success() = 0;
virtual void
Failed() = 0;
virtual void
AttemptTimedout() = 0;
virtual void
Attempt() = 0;
virtual bool
ShouldRetry() const = 0;
};
} // namespace llarp
#endif

@ -2,8 +2,8 @@
#define LLARP_EV_HPP
#include <ev/ev.h>
#include <codel.hpp>
#include <util/buffer.h>
#include <util/codel.hpp>
#include <util/threading.hpp>
// writev

@ -1,11 +1,13 @@
#ifndef EV_WIN32_HPP
#define EV_WIN32_HPP
#include <buffer.h>
#include <ev/ev.hpp>
#include <util/logger.hpp>
#include <net/net.h>
#include <net/net.hpp>
#include <util/buffer.h>
#include <util/logger.hpp>
#include <windows.h>
#include <process.h>

@ -1,6 +1,6 @@
#include <exit/endpoint.hpp>
#include <handlers/exit.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,8 +1,8 @@
#ifndef LLARP_EXIT_ENDPOINT_HPP
#define LLARP_EXIT_ENDPOINT_HPP
#include <crypto.hpp>
#include <ip.hpp>
#include <crypto/types.hpp>
#include <net/ip.hpp>
#include <path/path.hpp>
#include <util/time.hpp>

@ -1,5 +1,5 @@
#include <link_layer.hpp>
#include <messages/exit.hpp>
#include <routing/handler.hpp>
namespace llarp

@ -1,6 +1,6 @@
#include <exit/session.hpp>
#include <path/path.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,9 +1,9 @@
#ifndef LLARP_EXIT_SESSION_HPP
#define LLARP_EXIT_SESSION_HPP
#include <ip.hpp>
#include <messages/exit.hpp>
#include <messages/transfer_traffic.hpp>
#include <net/ip.hpp>
#include <path/pathbuilder.hpp>
#include <deque>

@ -2,7 +2,7 @@
#include <dns/dns.hpp>
#include <net/net.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/str.hpp>
#include <cassert>

@ -10,7 +10,7 @@
#include <dns/dns.hpp>
#include <ev/ev.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,12 +1,12 @@
#ifndef LLARP_HANDLERS_TUN_HPP
#define LLARP_HANDLERS_TUN_HPP
#include <codel.hpp>
#include <dns/server.hpp>
#include <ev/ev.h>
#include <ip.hpp>
#include <net/ip.hpp>
#include <net/net.hpp>
#include <service/endpoint.hpp>
#include <util/codel.hpp>
#include <util/threading.hpp>
namespace llarp

@ -1,13 +1,13 @@
#ifndef LLARP_LINK_ENCODER_HPP
#define LLARP_LINK_ENCODER_HPP
#include <router_contact.hpp>
#include <util/bencode.h>
#include <util/buffer.h>
struct llarp_buffer_t;
namespace llarp
{
struct KeyExchangeNonce;
class RouterContact;
/// encode Link Introduce Message onto a buffer
/// if router is nullptr then the LIM's r member is omitted.
bool

@ -1,5 +1,5 @@
#include <link/iwp_internal.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

@ -1,14 +1,18 @@
#ifndef LLARP_LINK_IWP_INTERNAL_HPP
#define LLARP_LINK_IWP_INTERNAL_HPP
#include <constants/link_layer.hpp>
#include <crypto/crypto.hpp>
#include <crypto/types.hpp>
#include <link/server.hpp>
#include <link/session.hpp>
#include <link_layer.hpp>
#include <bitset>
#include <deque>
namespace llarp
{
struct Crypto;
namespace iwp
{
struct LinkLayer;

@ -1,5 +1,6 @@
#include <link/server.hpp>
#include <crypto/crypto.hpp>
#include <util/fs.hpp>
namespace llarp
@ -131,7 +132,7 @@ namespace llarp
Lock l_authed(m_AuthedLinksMutex);
Lock l_pending(m_PendingMutex);
llarp::Addr addr = s->GetRemoteEndpoint();
auto itr = m_Pending.find(addr);
auto itr = m_Pending.find(addr);
if(itr != m_Pending.end())
{
if(m_AuthedLinks.count(pk) > MaxSessionsPerKey)
@ -163,7 +164,7 @@ namespace llarp
}
void
ILinkLayer::RemovePending(ILinkSession * s)
ILinkLayer::RemovePending(ILinkSession* s)
{
llarp::Addr remote = s->GetRemoteEndpoint();
m_Pending.erase(remote);
@ -330,10 +331,10 @@ namespace llarp
{
Lock lock(m_PendingMutex);
llarp::Addr addr = s->GetRemoteEndpoint();
auto itr = m_Pending.find(addr);
auto itr = m_Pending.find(addr);
if(itr != m_Pending.end())
return false;
m_Pending.insert(std::make_pair(addr, std::unique_ptr<ILinkSession>(s)));
m_Pending.insert(std::make_pair(addr, std::unique_ptr< ILinkSession >(s)));
return true;
}

@ -1,7 +1,7 @@
#ifndef LLARP_LINK_SERVER_HPP
#define LLARP_LINK_SERVER_HPP
#include <crypto.hpp>
#include <crypto/types.hpp>
#include <ev/ev.h>
#include <link/session.hpp>
#include <net/net.hpp>

@ -1,7 +1,7 @@
#ifndef LLARP_LINK_SESSION_HPP
#define LLARP_LINK_SESSION_HPP
#include <crypto.hpp>
#include <crypto/types.hpp>
#include <net/net.hpp>
#include <router_contact.hpp>
#include <util/types.hpp>

@ -3,7 +3,7 @@
#include <link/server.hpp>
#include <messages/discard.hpp>
#include <messages/link_intro.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/buffer.hpp>
#include <util/endian.hpp>

@ -1,15 +1,18 @@
#ifndef LLARP_LINK_UTP_INTERNAL_HPP
#define LLARP_LINK_UTP_INTERNAL_HPP
#include <constants/link_layer.hpp>
#include <crypto/types.hpp>
#include <link/utp.hpp>
#include <utp.h>
#include <link_layer.hpp>
#include <util/aligned.hpp>
#include <utp.h>
#include <tuple>
#include <deque>
namespace llarp
{
struct Crypto;
namespace utp
{
/// size of keyed hash

@ -1,175 +0,0 @@
#include <messages/link_intro.hpp>
#include <router_contact.hpp>
#include <router.hpp>
#include <util/bencode.h>
#include <util/logger.hpp>
namespace llarp
{
LinkIntroMessage::~LinkIntroMessage()
{
}
bool
LinkIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "a"))
{
llarp_buffer_t strbuf;
if(!bencode_read_string(buf, &strbuf))
return false;
if(strbuf.sz != 1)
return false;
return *strbuf.cur == 'i';
}
if(llarp_buffer_eq(key, "n"))
{
if(N.BDecode(buf))
return true;
llarp::LogWarn("failed to decode nonce in LIM");
return false;
}
if(llarp_buffer_eq(key, "p"))
{
return bencode_read_integer(buf, &P);
}
if(llarp_buffer_eq(key, "r"))
{
if(rc.BDecode(buf))
return true;
llarp::LogWarn("failed to decode RC in LIM");
llarp::DumpBuffer(*buf);
return false;
}
else if(llarp_buffer_eq(key, "v"))
{
if(!bencode_read_integer(buf, &version))
return false;
if(version != LLARP_PROTO_VERSION)
{
llarp::LogWarn("llarp protocol version missmatch ", version,
" != ", LLARP_PROTO_VERSION);
return false;
}
llarp::LogDebug("LIM version ", version);
return true;
}
else if(llarp_buffer_eq(key, "z"))
{
return Z.BDecode(buf);
}
else
{
llarp::LogWarn("invalid LIM key: ", *key.cur);
return false;
}
}
bool
LinkIntroMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!bencode_write_bytestring(buf, "a", 1))
return false;
if(!bencode_write_bytestring(buf, "i", 1))
return false;
if(!bencode_write_bytestring(buf, "n", 1))
return false;
if(!N.BEncode(buf))
return false;
if(!bencode_write_bytestring(buf, "p", 1))
return false;
if(!bencode_write_uint64(buf, P))
return false;
if(!bencode_write_bytestring(buf, "r", 1))
return false;
if(!rc.BEncode(buf))
return false;
if(!bencode_write_version_entry(buf))
return false;
if(!bencode_write_bytestring(buf, "z", 1))
return false;
if(!Z.BEncode(buf))
return false;
return bencode_end(buf);
}
LinkIntroMessage&
LinkIntroMessage::operator=(const LinkIntroMessage& msg)
{
version = msg.version;
Z = msg.Z;
rc = msg.rc;
N = msg.N;
P = msg.P;
return *this;
}
bool
LinkIntroMessage::HandleMessage(llarp::Router* router) const
{
if(!Verify(&router->crypto))
return false;
return session->GotLIM(this);
}
void
LinkIntroMessage::Clear()
{
P = 0;
N.Zero();
rc.Clear();
Z.Zero();
}
bool
LinkIntroMessage::Sign(
std::function< bool(Signature&, llarp_buffer_t) > signer)
{
Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
return signer(Z, buf);
}
bool
LinkIntroMessage::Verify(llarp::Crypto* c) const
{
LinkIntroMessage copy;
copy = *this;
copy.Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!copy.BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// outer signature
if(!c->verify(rc.pubkey, buf, Z))
{
llarp::LogError("outer signature failure");
return false;
}
// verify RC
if(!rc.Verify(c, llarp::time_now_ms()))
{
llarp::LogError("invalid RC in link intro");
return false;
}
return true;
}
} // namespace llarp

@ -1 +0,0 @@
#include <link_layer.hpp>

@ -15,11 +15,11 @@
#include <cstring>
#include <fstream>
#include <linux/netns.hpp>
#include <logger.hpp>
#include <util/logger.hpp>
#ifndef MS_REC
#define MS_REC (16384)
#endif
#include "fs.hpp"
#include <util/fs.hpp>
namespace llarp
{

@ -2,7 +2,7 @@
#define LLARP_MESSAGES_DHT_IMMEDIATE_HPP
#include <dht/message.hpp>
#include <link_message.hpp>
#include <messages/link_message.hpp>
#include <vector>

@ -1,7 +1,7 @@
#ifndef LLARP_MESSAGES_DISCARD_HPP
#define LLARP_MESSAGES_DISCARD_HPP
#include <link_message.hpp>
#include <messages/link_message.hpp>
#include <routing/handler.hpp>
#include <routing/message.hpp>
#include <util/bencode.hpp>
@ -61,7 +61,10 @@ namespace llarp
version = LLARP_PROTO_VERSION;
}
void Clear() override {}
void
Clear() override
{
}
bool
HandleMessage(IMessageHandler* h, llarp::Router* r) const override

@ -1,6 +1,7 @@
#ifndef LLARP_MESSAGES_EXIT_HPP
#define LLARP_MESSAGES_EXIT_HPP
#include <crypto.hpp>
#include <crypto/types.hpp>
#include <exit/policy.hpp>
#include <routing/message.hpp>
@ -8,6 +9,7 @@
namespace llarp
{
struct Crypto;
namespace routing
{
struct ObtainExitMessage final : public IMessage

@ -1 +1,175 @@
#include <messages/link_intro.hpp>
#include <router_contact.hpp>
#include <router/router.hpp>
#include <util/bencode.h>
#include <util/logger.hpp>
namespace llarp
{
LinkIntroMessage::~LinkIntroMessage()
{
}
bool
LinkIntroMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "a"))
{
llarp_buffer_t strbuf;
if(!bencode_read_string(buf, &strbuf))
return false;
if(strbuf.sz != 1)
return false;
return *strbuf.cur == 'i';
}
if(llarp_buffer_eq(key, "n"))
{
if(N.BDecode(buf))
return true;
llarp::LogWarn("failed to decode nonce in LIM");
return false;
}
if(llarp_buffer_eq(key, "p"))
{
return bencode_read_integer(buf, &P);
}
if(llarp_buffer_eq(key, "r"))
{
if(rc.BDecode(buf))
return true;
llarp::LogWarn("failed to decode RC in LIM");
llarp::DumpBuffer(*buf);
return false;
}
else if(llarp_buffer_eq(key, "v"))
{
if(!bencode_read_integer(buf, &version))
return false;
if(version != LLARP_PROTO_VERSION)
{
llarp::LogWarn("llarp protocol version missmatch ", version,
" != ", LLARP_PROTO_VERSION);
return false;
}
llarp::LogDebug("LIM version ", version);
return true;
}
else if(llarp_buffer_eq(key, "z"))
{
return Z.BDecode(buf);
}
else
{
llarp::LogWarn("invalid LIM key: ", *key.cur);
return false;
}
}
bool
LinkIntroMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!bencode_write_bytestring(buf, "a", 1))
return false;
if(!bencode_write_bytestring(buf, "i", 1))
return false;
if(!bencode_write_bytestring(buf, "n", 1))
return false;
if(!N.BEncode(buf))
return false;
if(!bencode_write_bytestring(buf, "p", 1))
return false;
if(!bencode_write_uint64(buf, P))
return false;
if(!bencode_write_bytestring(buf, "r", 1))
return false;
if(!rc.BEncode(buf))
return false;
if(!bencode_write_version_entry(buf))
return false;
if(!bencode_write_bytestring(buf, "z", 1))
return false;
if(!Z.BEncode(buf))
return false;
return bencode_end(buf);
}
LinkIntroMessage&
LinkIntroMessage::operator=(const LinkIntroMessage& msg)
{
version = msg.version;
Z = msg.Z;
rc = msg.rc;
N = msg.N;
P = msg.P;
return *this;
}
bool
LinkIntroMessage::HandleMessage(llarp::Router* router) const
{
if(!Verify(&router->crypto))
return false;
return session->GotLIM(this);
}
void
LinkIntroMessage::Clear()
{
P = 0;
N.Zero();
rc.Clear();
Z.Zero();
}
bool
LinkIntroMessage::Sign(
std::function< bool(Signature&, llarp_buffer_t) > signer)
{
Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
return signer(Z, buf);
}
bool
LinkIntroMessage::Verify(llarp::Crypto* c) const
{
LinkIntroMessage copy;
copy = *this;
copy.Z.Zero();
byte_t tmp[MaxSize] = {0};
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
if(!copy.BEncode(&buf))
return false;
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// outer signature
if(!c->verify(rc.pubkey, buf, Z))
{
llarp::LogError("outer signature failure");
return false;
}
// verify RC
if(!rc.Verify(c, llarp::time_now_ms()))
{
llarp::LogError("invalid RC in link intro");
return false;
}
return true;
}
} // namespace llarp

@ -1,7 +1,8 @@
#ifndef LLARP_MESSAGES_LINK_INTRO_HPP
#define LLARP_MESSAGES_LINK_INTRO_HPP
#include <link_message.hpp>
#include <crypto/types.hpp>
#include <messages/link_message.hpp>
#include <router_contact.hpp>
namespace llarp

@ -1,4 +1,4 @@
#include <link_message_parser.hpp>
#include <messages/link_message_parser.hpp>
#include <router_contact.hpp>
#include <util/buffer.hpp>

@ -1,10 +1,10 @@
#ifndef LLARP_LINK_MESSAGE_PARSER_HPP
#define LLARP_LINK_MESSAGE_PARSER_HPP
#include <link_message.hpp>
#include <messages/discard.hpp>
#include <messages/dht_immediate.hpp>
#include <messages/link_intro.hpp>
#include <messages/link_message.hpp>
#include <messages/relay.hpp>
#include <messages/relay_commit.hpp>

@ -1,8 +1,8 @@
#ifndef LLARP_MESSAGES_PATH_TRANSFER_HPP
#define LLARP_MESSAGES_PATH_TRANSFER_HPP
#include <crypto.hpp>
#include <encrypted.hpp>
#include <crypto/encrypted.hpp>
#include <crypto/types.hpp>
#include <routing/message.hpp>
#include <service/protocol.hpp>

@ -1 +1,132 @@
#include <messages/relay.hpp>
#include <router/router.hpp>
#include <util/bencode.hpp>
namespace llarp
{
RelayUpstreamMessage::RelayUpstreamMessage() : ILinkMessage()
{
}
RelayUpstreamMessage::~RelayUpstreamMessage()
{
}
void
RelayUpstreamMessage::Clear()
{
pathid.Zero();
X.Clear();
Y.Zero();
}
bool
RelayUpstreamMessage::BEncode(llarp_buffer_t *buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "u"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayUpstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayUpstreamMessage::HandleMessage(llarp::Router *r) const
{
auto path = r->paths.GetByDownstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleUpstream(X.Buffer(), Y, r);
}
return false;
}
RelayDownstreamMessage::RelayDownstreamMessage() : ILinkMessage()
{
}
RelayDownstreamMessage::~RelayDownstreamMessage()
{
}
void
RelayDownstreamMessage::Clear()
{
pathid.Zero();
X.Clear();
Y.Zero();
}
bool
RelayDownstreamMessage::BEncode(llarp_buffer_t *buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "d"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayDownstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayDownstreamMessage::HandleMessage(llarp::Router *r) const
{
auto path = r->paths.GetByUpstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleDownstream(X.Buffer(), Y, r);
}
llarp::LogWarn("unhandled downstream message");
return false;
}
} // namespace llarp

@ -1,9 +1,9 @@
#ifndef LLARP_MESSAGES_RELAY_HPP
#define LLARP_MESSAGES_RELAY_HPP
#include <crypto.hpp>
#include <encrypted.hpp>
#include <link_message.hpp>
#include <crypto/encrypted.hpp>
#include <crypto/types.hpp>
#include <messages/link_message.hpp>
#include <path/path_types.hpp>
#include <vector>

@ -1 +1,345 @@
#include <messages/relay_commit.hpp>
#include <messages/path_confirm.hpp>
#include <path/path.hpp>
#include <router/router.hpp>
#include <util/bencode.hpp>
#include <util/buffer.hpp>
#include <util/logger.hpp>
namespace llarp
{
LR_CommitMessage::~LR_CommitMessage()
{
}
bool
LR_CommitMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "c"))
{
return BEncodeReadArray(frames, buf);
}
bool read = false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
return read;
}
void
LR_CommitMessage::Clear()
{
frames[0].Clear();
frames[1].Clear();
frames[2].Clear();
frames[3].Clear();
frames[4].Clear();
frames[5].Clear();
frames[6].Clear();
frames[7].Clear();
}
bool
LR_CommitMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
// msg type
if(!BEncodeWriteDictMsgType(buf, "a", "c"))
return false;
// frames
if(!BEncodeWriteDictArray("c", frames, buf))
return false;
// version
if(!bencode_write_version_entry(buf))
return false;
return bencode_end(buf);
}
bool
LR_CommitMessage::HandleMessage(llarp::Router* router) const
{
if(frames.size() != MAXHOPS)
{
llarp::LogError("LRCM invalid number of records, ", frames.size(),
"!=", MAXHOPS);
return false;
}
if(!router->paths.AllowingTransit())
{
llarp::LogError("got LRCM when not permitting transit");
return false;
}
return AsyncDecrypt(&router->paths);
}
bool
LR_CommitRecord::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictEntry("c", commkey, buf))
return false;
if(!BEncodeWriteDictEntry("i", nextHop, buf))
return false;
if(lifetime > 10 && lifetime < 600)
{
if(!BEncodeWriteDictInt("i", lifetime, buf))
return false;
}
if(!BEncodeWriteDictEntry("n", tunnelNonce, buf))
return false;
if(!BEncodeWriteDictEntry("r", rxid, buf))
return false;
if(!BEncodeWriteDictEntry("t", txid, buf))
return false;
if(!bencode_write_version_entry(buf))
return false;
if(work && !BEncodeWriteDictEntry("w", *work, buf))
return false;
return bencode_end(buf);
}
LR_CommitRecord::~LR_CommitRecord()
{
if(work)
delete work;
}
bool
LR_CommitRecord::OnKey(dict_reader* r, llarp_buffer_t* key)
{
if(!key)
return true;
LR_CommitRecord* self = static_cast< LR_CommitRecord* >(r->user);
bool read = false;
if(!BEncodeMaybeReadDictEntry("c", self->commkey, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("i", self->nextHop, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictInt("l", self->lifetime, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("n", self->tunnelNonce, read, *key,
r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("r", self->rxid, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("t", self->txid, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadVersion("v", self->version, LLARP_PROTO_VERSION, read,
*key, r->buffer))
return false;
if(llarp_buffer_eq(*key, "w"))
{
// check for duplicate
if(self->work)
{
llarp::LogWarn("duplicate POW in LRCR");
return false;
}
self->work = new PoW();
return self->work->BDecode(r->buffer);
}
return read;
}
bool
LR_CommitRecord::BDecode(llarp_buffer_t* buf)
{
dict_reader r;
r.user = this;
r.on_key = &OnKey;
return bencode_read_dict(buf, &r);
}
bool
LR_CommitRecord::operator==(const LR_CommitRecord& other) const
{
if(work && other.work)
{
if(*work != *other.work)
return false;
}
return nextHop == other.nextHop && commkey == other.commkey
&& txid == other.txid && rxid == other.rxid;
}
struct LRCMFrameDecrypt
{
typedef llarp::path::PathContext Context;
typedef llarp::path::TransitHop Hop;
typedef AsyncFrameDecrypter< LRCMFrameDecrypt > Decrypter;
Decrypter* decrypter;
std::array< EncryptedFrame, 8 > frames;
Context* context;
// decrypted record
LR_CommitRecord record;
// the actual hop
std::shared_ptr< Hop > hop;
LRCMFrameDecrypt(Context* ctx, Decrypter* dec,
const LR_CommitMessage* commit)
: decrypter(dec), frames(commit->frames), context(ctx), hop(new Hop())
{
hop->info.downstream = commit->session->GetPubKey();
}
~LRCMFrameDecrypt()
{
delete decrypter;
}
/// this is done from logic thread
static void
SendLRCM(void* user)
{
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
// persist sessions to upstream and downstream routers until the commit
// ends
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
self->context->Router()->PersistSessionUntil(self->hop->info.upstream,
self->hop->ExpireTime());
// put hop
self->context->PutTransitHop(self->hop);
// forward to next hop
self->context->ForwardLRCM(self->hop->info.upstream, self->frames);
self->hop = nullptr;
delete self;
}
// this is called from the logic thread
static void
SendPathConfirm(void* user)
{
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
// persist session to downstream until path expiration
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
// put hop
self->context->PutTransitHop(self->hop);
// send path confirmation
llarp::routing::PathConfirmMessage confirm(self->hop->lifetime);
if(!self->hop->SendRoutingMessage(&confirm, self->context->Router()))
{
llarp::LogError("failed to send path confirmation for ",
self->hop->info);
}
self->hop = nullptr;
delete self;
}
static void
HandleDecrypted(llarp_buffer_t* buf, LRCMFrameDecrypt* self)
{
auto now = self->context->Router()->Now();
auto& info = self->hop->info;
if(!buf)
{
llarp::LogError("LRCM decrypt failed from ", info.downstream);
delete self;
return;
}
buf->cur = buf->base + EncryptedFrameOverheadSize;
llarp::LogDebug("decrypted LRCM from ", info.downstream);
// successful decrypt
if(!self->record.BDecode(buf))
{
llarp::LogError("malformed frame inside LRCM from ", info.downstream);
delete self;
return;
}
info.txID = self->record.txid;
info.rxID = self->record.rxid;
info.upstream = self->record.nextHop;
if(self->context->HasTransitHop(info))
{
llarp::LogError("duplicate transit hop ", info);
delete self;
return;
}
// generate path key as we are in a worker thread
auto DH = self->context->Crypto()->dh_server;
if(!DH(self->hop->pathKey, self->record.commkey,
self->context->EncryptionSecretKey(), self->record.tunnelNonce))
{
llarp::LogError("LRCM DH Failed ", info);
delete self;
return;
}
// generate hash of hop key for nonce mutation
self->context->Crypto()->shorthash(self->hop->nonceXOR,
self->hop->pathKey.as_buffer());
if(self->record.work
&& self->record.work->IsValid(self->context->Crypto()->shorthash, now))
{
llarp::LogDebug("LRCM extended lifetime by ",
self->record.work->extendedLifetime, " seconds for ",
info);
self->hop->lifetime += 1000 * self->record.work->extendedLifetime;
}
else if(self->record.lifetime < 600 && self->record.lifetime > 10)
{
self->hop->lifetime = self->record.lifetime;
llarp::LogDebug("LRCM short lifespan set to ", self->hop->lifetime,
" seconds for ", info);
}
// TODO: check if we really want to accept it
self->hop->started = now;
size_t sz = self->frames[0].size();
// shift
std::array< EncryptedFrame, 8 > frames;
frames[0] = self->frames[1];
frames[1] = self->frames[2];
frames[2] = self->frames[3];
frames[3] = self->frames[4];
frames[4] = self->frames[5];
frames[5] = self->frames[6];
frames[6] = self->frames[7];
// put our response on the end
frames[7] = EncryptedFrame(sz - EncryptedFrameOverheadSize);
// random junk for now
frames[7].Randomize();
self->frames = std::move(frames);
if(self->context->HopIsUs(info.upstream))
{
// we are the farthest hop
llarp::LogDebug("We are the farthest hop for ", info);
// send a LRAM down the path
self->context->Logic()->queue_job({self, &SendPathConfirm});
}
else
{
// forward upstream
// we are still in the worker thread so post job to logic
self->context->Logic()->queue_job({self, &SendLRCM});
}
}
};
bool
LR_CommitMessage::AsyncDecrypt(llarp::path::PathContext* context) const
{
LRCMFrameDecrypt::Decrypter* decrypter = new LRCMFrameDecrypt::Decrypter(
context->Crypto(), context->EncryptionSecretKey(),
&LRCMFrameDecrypt::HandleDecrypted);
// copy frames so we own them
LRCMFrameDecrypt* frames = new LRCMFrameDecrypt(context, decrypter, this);
// decrypt frames async
decrypter->AsyncDecrypt(context->Worker(), frames->frames[0], frames);
return true;
}
} // namespace llarp

@ -1,10 +1,9 @@
#ifndef LLARP_RELAY_COMMIT_HPP
#define LLARP_RELAY_COMMIT_HPP
#include <crypto.hpp>
#include <encrypted_ack.hpp>
#include <encrypted_frame.hpp>
#include <link_message.hpp>
#include <crypto/encrypted_frame.hpp>
#include <crypto/types.hpp>
#include <messages/link_message.hpp>
#include <path/path_types.hpp>
#include <pow.hpp>

@ -1,8 +1,7 @@
#ifndef LLARP_MESSAGES_TRANSFER_TRAFFIC_HPP
#define LLARP_MESSAGES_TRANSFER_TRAFFIC_HPP
#include <crypto.hpp>
#include <encrypted.hpp>
#include <crypto/encrypted.hpp>
#include <routing/message.hpp>
#include <vector>
@ -19,7 +18,8 @@ namespace llarp
std::vector< llarp::Encrypted< MaxExitMTU + ExitOverhead > > X;
size_t _size = 0;
void Clear() override
void
Clear() override
{
X.clear();
_size = 0;

@ -1,4 +1,5 @@
#include <address_info.hpp>
#include <net/address_info.hpp>
#ifndef _WIN32
#include <arpa/inet.h>
#endif

@ -1,7 +1,7 @@
#ifndef LLARP_AI_HPP
#define LLARP_AI_HPP
#include <crypto.hpp>
#include <crypto/types.hpp>
#include <net/net.h>
#include <util/bencode.hpp>
#include <util/mem.h>

@ -2,7 +2,7 @@
#include <arpa/inet.h>
#endif
#include <exit_info.hpp>
#include <net/exit_info.hpp>
#include <util/bencode.h>
#include <util/mem.h>

@ -1,7 +1,7 @@
#ifndef LLARP_XI_HPP
#define LLARP_XI_HPP
#include <crypto.hpp>
#include <crypto/types.hpp>
#include <net/net.hpp>
#include <util/bencode.hpp>
#include <util/bits.hpp>

@ -1,4 +1,4 @@
#include <ip.hpp>
#include <net/ip.hpp>
#include <util/buffer.hpp>
#include <util/endian.hpp>

@ -76,6 +76,8 @@ typedef struct ip_hdr
#include <memory>
struct llarp_ev_loop;
namespace llarp
{
namespace net

@ -1,7 +1,9 @@
#include <net/net.hpp>
#ifdef ANDROID
#include "android/ifaddrs.h"
#include <android/ifaddrs.h>
#endif
#ifndef _WIN32
#include <arpa/inet.h>
#ifndef ANDROID
@ -9,6 +11,7 @@
#endif
#include <net/if.h>
#endif
#include <net/net_addr.hpp>
#include <util/logger.hpp>
#include <util/str.hpp>

@ -1,7 +1,7 @@
#ifndef LLARP_NET_HPP
#define LLARP_NET_HPP
#include <address_info.hpp>
#include <net/address_info.hpp>
#include <net/net_int.hpp>
#include <net/net.h>
#include <util/logger.hpp>

@ -1,7 +1,7 @@
#ifndef LLARP_NET_ADDR_HPP
#define LLARP_NET_ADDR_HPP
#include <address_info.hpp>
#include <net/address_info.hpp>
#include <net/net.h>
#include <net/net.hpp>
#include <util/string_view.hpp>

@ -1,6 +1,6 @@
#include <nodedb.hpp>
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <router_contact.hpp>
#include <util/buffer.hpp>
#include <util/encode.hpp>

@ -1,7 +1,6 @@
#ifndef LLARP_NODEDB_HPP
#define LLARP_NODEDB_HPP
#include <crypto.hpp>
#include <router_contact.hpp>
#include <router_id.hpp>
#include <util/common.hpp>
@ -13,10 +12,13 @@
* persistent storage API for router contacts
*/
struct llarp_threadpool;
namespace llarp
{
struct Crypto;
class Logic;
}
} // namespace llarp
struct llarp_nodedb_iter
{

@ -1,10 +1,9 @@
#include <path/path.hpp>
#include <encrypted_frame.hpp>
#include <messages/dht.hpp>
#include <messages/discard.hpp>
#include <path/pathbuilder.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/buffer.hpp>
#include <util/endian.hpp>

@ -1,8 +1,8 @@
#ifndef LLARP_PATH_HPP
#define LLARP_PATH_HPP
#include <crypto.hpp>
#include <messages/relay_commit.hpp>
#include <crypto/encrypted_frame.hpp>
#include <crypto/types.hpp>
#include <messages/relay.hpp>
#include <path/path_types.hpp>
#include <path/pathbuilder.hpp>
@ -32,6 +32,9 @@
namespace llarp
{
struct Crypto;
struct LR_CommitMessage;
struct LR_CommitRecord;
namespace path
{
struct TransitHopInfo

@ -1,7 +1,7 @@
#ifndef LLARP_PATH_TYPES_HPP
#define LLARP_PATH_TYPES_HPP
#include <crypto.hpp>
#include <crypto/constants.hpp>
#include <util/aligned.hpp>
namespace llarp

@ -2,7 +2,7 @@
#include <nodedb.hpp>
#include <path/path.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <util/buffer.hpp>
#include <functional>

@ -2,7 +2,7 @@
#include <dht/context.hpp>
#include <messages/discard.hpp>
#include <router.hpp>
#include <router/router.hpp>
#include <routing/handler.hpp>
#include <util/buffer.hpp>
#include <util/endian.hpp>

@ -1 +1,58 @@
#include <pow.hpp>
#include <util/buffer.hpp>
#include <cmath>
namespace llarp
{
PoW::~PoW()
{
}
bool
PoW::DecodeKey(__attribute__((unused)) llarp_buffer_t k,
__attribute__((unused)) llarp_buffer_t* val)
{
// TODO: implement me
return false;
}
bool
PoW::BEncode(llarp_buffer_t* buf) const
{
// TODO: implement me
if(!bencode_start_dict(buf))
return false;
return bencode_end(buf);
}
bool
PoW::IsValid(shorthash_func hashfunc, llarp_time_t now) const
{
if(now - timestamp > (uint64_t(extendedLifetime) * 1000))
return false;
ShortHash digest;
byte_t tmp[MaxSize];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
// encode
if(!BEncode(&buf))
return false;
// rewind
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// hash
if(!hashfunc(digest, buf))
return false;
// check bytes required
uint32_t required = std::floor(std::log(extendedLifetime));
for(uint32_t idx = 0; idx < required; ++idx)
{
if(digest[idx])
return false;
}
return true;
}
} // namespace llarp

@ -1,6 +1,7 @@
#ifndef LLARP_POW_HPP
#define LLARP_POW_HPP
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <router_id.hpp>
#include <util/bencode.hpp>

@ -1,58 +0,0 @@
#include <pow.hpp>
#include <util/buffer.hpp>
#include <cmath>
namespace llarp
{
PoW::~PoW()
{
}
bool
PoW::DecodeKey(__attribute__((unused)) llarp_buffer_t k,
__attribute__((unused)) llarp_buffer_t* val)
{
// TODO: implement me
return false;
}
bool
PoW::BEncode(llarp_buffer_t* buf) const
{
// TODO: implement me
if(!bencode_start_dict(buf))
return false;
return bencode_end(buf);
}
bool
PoW::IsValid(shorthash_func hashfunc, llarp_time_t now) const
{
if(now - timestamp > (uint64_t(extendedLifetime) * 1000))
return false;
ShortHash digest;
byte_t tmp[MaxSize];
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
// encode
if(!BEncode(&buf))
return false;
// rewind
buf.sz = buf.cur - buf.base;
buf.cur = buf.base;
// hash
if(!hashfunc(digest, buf))
return false;
// check bytes required
uint32_t required = std::floor(std::log(extendedLifetime));
for(uint32_t idx = 0; idx < required; ++idx)
{
if(digest[idx])
return false;
}
return true;
}
} // namespace llarp

@ -1,344 +0,0 @@
#include <messages/path_confirm.hpp>
#include <messages/relay_commit.hpp>
#include <path/path.hpp>
#include <router.hpp>
#include <util/bencode.hpp>
#include <util/buffer.hpp>
#include <util/logger.hpp>
namespace llarp
{
LR_CommitMessage::~LR_CommitMessage()
{
}
bool
LR_CommitMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf)
{
if(llarp_buffer_eq(key, "c"))
{
return BEncodeReadArray(frames, buf);
}
bool read = false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
return read;
}
void
LR_CommitMessage::Clear()
{
frames[0].Clear();
frames[1].Clear();
frames[2].Clear();
frames[3].Clear();
frames[4].Clear();
frames[5].Clear();
frames[6].Clear();
frames[7].Clear();
}
bool
LR_CommitMessage::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
// msg type
if(!BEncodeWriteDictMsgType(buf, "a", "c"))
return false;
// frames
if(!BEncodeWriteDictArray("c", frames, buf))
return false;
// version
if(!bencode_write_version_entry(buf))
return false;
return bencode_end(buf);
}
bool
LR_CommitMessage::HandleMessage(llarp::Router* router) const
{
if(frames.size() != MAXHOPS)
{
llarp::LogError("LRCM invalid number of records, ", frames.size(),
"!=", MAXHOPS);
return false;
}
if(!router->paths.AllowingTransit())
{
llarp::LogError("got LRCM when not permitting transit");
return false;
}
return AsyncDecrypt(&router->paths);
}
bool
LR_CommitRecord::BEncode(llarp_buffer_t* buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictEntry("c", commkey, buf))
return false;
if(!BEncodeWriteDictEntry("i", nextHop, buf))
return false;
if(lifetime > 10 && lifetime < 600)
{
if(!BEncodeWriteDictInt("i", lifetime, buf))
return false;
}
if(!BEncodeWriteDictEntry("n", tunnelNonce, buf))
return false;
if(!BEncodeWriteDictEntry("r", rxid, buf))
return false;
if(!BEncodeWriteDictEntry("t", txid, buf))
return false;
if(!bencode_write_version_entry(buf))
return false;
if(work && !BEncodeWriteDictEntry("w", *work, buf))
return false;
return bencode_end(buf);
}
LR_CommitRecord::~LR_CommitRecord()
{
if(work)
delete work;
}
bool
LR_CommitRecord::OnKey(dict_reader* r, llarp_buffer_t* key)
{
if(!key)
return true;
LR_CommitRecord* self = static_cast< LR_CommitRecord* >(r->user);
bool read = false;
if(!BEncodeMaybeReadDictEntry("c", self->commkey, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("i", self->nextHop, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictInt("l", self->lifetime, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("n", self->tunnelNonce, read, *key,
r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("r", self->rxid, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadDictEntry("t", self->txid, read, *key, r->buffer))
return false;
if(!BEncodeMaybeReadVersion("v", self->version, LLARP_PROTO_VERSION, read,
*key, r->buffer))
return false;
if(llarp_buffer_eq(*key, "w"))
{
// check for duplicate
if(self->work)
{
llarp::LogWarn("duplicate POW in LRCR");
return false;
}
self->work = new PoW();
return self->work->BDecode(r->buffer);
}
return read;
}
bool
LR_CommitRecord::BDecode(llarp_buffer_t* buf)
{
dict_reader r;
r.user = this;
r.on_key = &OnKey;
return bencode_read_dict(buf, &r);
}
bool
LR_CommitRecord::operator==(const LR_CommitRecord& other) const
{
if(work && other.work)
{
if(*work != *other.work)
return false;
}
return nextHop == other.nextHop && commkey == other.commkey
&& txid == other.txid && rxid == other.rxid;
}
struct LRCMFrameDecrypt
{
typedef llarp::path::PathContext Context;
typedef llarp::path::TransitHop Hop;
typedef AsyncFrameDecrypter< LRCMFrameDecrypt > Decrypter;
Decrypter* decrypter;
std::array< EncryptedFrame, 8 > frames;
Context* context;
// decrypted record
LR_CommitRecord record;
// the actual hop
std::shared_ptr< Hop > hop;
LRCMFrameDecrypt(Context* ctx, Decrypter* dec,
const LR_CommitMessage* commit)
: decrypter(dec), frames(commit->frames), context(ctx), hop(new Hop())
{
hop->info.downstream = commit->session->GetPubKey();
}
~LRCMFrameDecrypt()
{
delete decrypter;
}
/// this is done from logic thread
static void
SendLRCM(void* user)
{
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
// persist sessions to upstream and downstream routers until the commit
// ends
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
self->context->Router()->PersistSessionUntil(self->hop->info.upstream,
self->hop->ExpireTime());
// put hop
self->context->PutTransitHop(self->hop);
// forward to next hop
self->context->ForwardLRCM(self->hop->info.upstream, self->frames);
self->hop = nullptr;
delete self;
}
// this is called from the logic thread
static void
SendPathConfirm(void* user)
{
LRCMFrameDecrypt* self = static_cast< LRCMFrameDecrypt* >(user);
// persist session to downstream until path expiration
self->context->Router()->PersistSessionUntil(self->hop->info.downstream,
self->hop->ExpireTime());
// put hop
self->context->PutTransitHop(self->hop);
// send path confirmation
llarp::routing::PathConfirmMessage confirm(self->hop->lifetime);
if(!self->hop->SendRoutingMessage(&confirm, self->context->Router()))
{
llarp::LogError("failed to send path confirmation for ",
self->hop->info);
}
self->hop = nullptr;
delete self;
}
static void
HandleDecrypted(llarp_buffer_t* buf, LRCMFrameDecrypt* self)
{
auto now = self->context->Router()->Now();
auto& info = self->hop->info;
if(!buf)
{
llarp::LogError("LRCM decrypt failed from ", info.downstream);
delete self;
return;
}
buf->cur = buf->base + EncryptedFrameOverheadSize;
llarp::LogDebug("decrypted LRCM from ", info.downstream);
// successful decrypt
if(!self->record.BDecode(buf))
{
llarp::LogError("malformed frame inside LRCM from ", info.downstream);
delete self;
return;
}
info.txID = self->record.txid;
info.rxID = self->record.rxid;
info.upstream = self->record.nextHop;
if(self->context->HasTransitHop(info))
{
llarp::LogError("duplicate transit hop ", info);
delete self;
return;
}
// generate path key as we are in a worker thread
auto DH = self->context->Crypto()->dh_server;
if(!DH(self->hop->pathKey, self->record.commkey,
self->context->EncryptionSecretKey(), self->record.tunnelNonce))
{
llarp::LogError("LRCM DH Failed ", info);
delete self;
return;
}
// generate hash of hop key for nonce mutation
self->context->Crypto()->shorthash(self->hop->nonceXOR,
self->hop->pathKey.as_buffer());
if(self->record.work
&& self->record.work->IsValid(self->context->Crypto()->shorthash, now))
{
llarp::LogDebug("LRCM extended lifetime by ",
self->record.work->extendedLifetime, " seconds for ",
info);
self->hop->lifetime += 1000 * self->record.work->extendedLifetime;
}
else if(self->record.lifetime < 600 && self->record.lifetime > 10)
{
self->hop->lifetime = self->record.lifetime;
llarp::LogDebug("LRCM short lifespan set to ", self->hop->lifetime,
" seconds for ", info);
}
// TODO: check if we really want to accept it
self->hop->started = now;
size_t sz = self->frames[0].size();
// shift
std::array< EncryptedFrame, 8 > frames;
frames[0] = self->frames[1];
frames[1] = self->frames[2];
frames[2] = self->frames[3];
frames[3] = self->frames[4];
frames[4] = self->frames[5];
frames[5] = self->frames[6];
frames[6] = self->frames[7];
// put our response on the end
frames[7] = EncryptedFrame(sz - EncryptedFrameOverheadSize);
// random junk for now
frames[7].Randomize();
self->frames = std::move(frames);
if(self->context->HopIsUs(info.upstream))
{
// we are the farthest hop
llarp::LogDebug("We are the farthest hop for ", info);
// send a LRAM down the path
self->context->Logic()->queue_job({self, &SendPathConfirm});
}
else
{
// forward upstream
// we are still in the worker thread so post job to logic
self->context->Logic()->queue_job({self, &SendLRCM});
}
}
};
bool
LR_CommitMessage::AsyncDecrypt(llarp::path::PathContext* context) const
{
LRCMFrameDecrypt::Decrypter* decrypter = new LRCMFrameDecrypt::Decrypter(
context->Crypto(), context->EncryptionSecretKey(),
&LRCMFrameDecrypt::HandleDecrypted);
// copy frames so we own them
LRCMFrameDecrypt* frames = new LRCMFrameDecrypt(context, decrypter, this);
// decrypt frames async
decrypter->AsyncDecrypt(context->Worker(), frames->frames[0], frames);
return true;
}
} // namespace llarp

@ -1,131 +0,0 @@
#include <messages/relay.hpp>
#include <router.hpp>
#include <util/bencode.hpp>
namespace llarp
{
RelayUpstreamMessage::RelayUpstreamMessage() : ILinkMessage()
{
}
RelayUpstreamMessage::~RelayUpstreamMessage()
{
}
void
RelayUpstreamMessage::Clear()
{
pathid.Zero();
X.Clear();
Y.Zero();
}
bool
RelayUpstreamMessage::BEncode(llarp_buffer_t *buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "u"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayUpstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayUpstreamMessage::HandleMessage(llarp::Router *r) const
{
auto path = r->paths.GetByDownstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleUpstream(X.Buffer(), Y, r);
}
return false;
}
RelayDownstreamMessage::RelayDownstreamMessage() : ILinkMessage()
{
}
RelayDownstreamMessage::~RelayDownstreamMessage()
{
}
void
RelayDownstreamMessage::Clear()
{
pathid.Zero();
X.Clear();
Y.Zero();
}
bool
RelayDownstreamMessage::BEncode(llarp_buffer_t *buf) const
{
if(!bencode_start_dict(buf))
return false;
if(!BEncodeWriteDictMsgType(buf, "a", "d"))
return false;
if(!BEncodeWriteDictEntry("p", pathid, buf))
return false;
if(!BEncodeWriteDictInt("v", LLARP_PROTO_VERSION, buf))
return false;
if(!BEncodeWriteDictEntry("x", X, buf))
return false;
if(!BEncodeWriteDictEntry("y", Y, buf))
return false;
return bencode_end(buf);
}
bool
RelayDownstreamMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t *buf)
{
bool read = false;
if(!BEncodeMaybeReadDictEntry("p", pathid, read, key, buf))
return false;
if(!BEncodeMaybeReadVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
return false;
if(!BEncodeMaybeReadDictEntry("x", X, read, key, buf))
return false;
if(!BEncodeMaybeReadDictEntry("y", Y, read, key, buf))
return false;
return read;
}
bool
RelayDownstreamMessage::HandleMessage(llarp::Router *r) const
{
auto path = r->paths.GetByUpstream(session->GetPubKey(), pathid);
if(path)
{
return path->HandleDownstream(X.Buffer(), Y, r);
}
llarp::LogWarn("unhandled downstream message");
return false;
}
} // namespace llarp

@ -1,14 +1,14 @@
#include <router.hpp>
#include <router/router.hpp>
#include <constants/proto.hpp>
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <dht/context.hpp>
#include <link_message.hpp>
#include <link/iwp.hpp>
#include <link/server.hpp>
#include <link/utp.hpp>
#include <messages/link_message.hpp>
#include <net/net.hpp>
#include <rpc.hpp>
#include <rpc/rpc.hpp>
#include <util/buffer.hpp>
#include <util/encode.hpp>
#include <util/logger.hpp>

@ -2,21 +2,19 @@
#define LLARP_ROUTER_HPP
#include <config.h>
#include <crypto.hpp>
#include <dht.h>
#include <establish_job.hpp>
#include <constants/link_layer.hpp>
#include <crypto/types.hpp>
#include <ev/ev.h>
#include <exit/context.hpp>
#include <handlers/tun.hpp>
#include <link_layer.hpp>
#include <link_message_parser.hpp>
#include <messages/link_message_parser.hpp>
#include <nodedb.hpp>
#include <path/path.hpp>
#include <profiling.hpp>
#include <router_contact.hpp>
#include <routing/handler.hpp>
#include <routing/message_parser.hpp>
#include <rpc.hpp>
#include <rpc/rpc.hpp>
#include <service/context.hpp>
#include <util/buffer.h>
#include <util/fs.hpp>
@ -32,6 +30,11 @@
#include <unordered_map>
#include <set>
namespace llarp
{
struct Crypto;
}
bool
llarp_findOrCreateEncryption(llarp::Crypto *crypto, const fs::path &fpath,
llarp::SecretKey &encryption);

@ -1,7 +1,7 @@
#include <router_contact.hpp>
#include <constants/version.hpp>
#include <crypto.hpp>
#include <crypto/crypto.hpp>
#include <net/net.hpp>
#include <util/bencode.hpp>
#include <util/buffer.hpp>

@ -1,10 +1,11 @@
#ifndef LLARP_RC_HPP
#define LLARP_RC_HPP
#include <address_info.hpp>
#include <constants/version.hpp>
#include <crypto.hpp>
#include <exit_info.hpp>
#include <crypto/types.hpp>
#include <net/address_info.hpp>
#include <net/exit_info.hpp>
#include <util/aligned.hpp>
#include <util/bencode.hpp>
#include <vector>
@ -14,6 +15,8 @@
namespace llarp
{
struct Crypto;
/// NetID
struct NetID final : public AlignedBuffer< 8 >
{

@ -1,5 +1,6 @@
#include <messages/dht.hpp>
#include <router.hpp>
#include <router/router.hpp>
namespace llarp
{

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save