|
|
|
@ -1,45 +1,47 @@
|
|
|
|
|
#include <crypto/crypto_noop.hpp>
|
|
|
|
|
#include <ev/ev.h>
|
|
|
|
|
#include <iwp/iwp.hpp>
|
|
|
|
|
#include <llarp_test.hpp>
|
|
|
|
|
#include <messages/link_intro.hpp>
|
|
|
|
|
#include <messages/discard.hpp>
|
|
|
|
|
#include <utp/utp.hpp>
|
|
|
|
|
|
|
|
|
|
#include <crypto/crypto_libsodium.hpp>
|
|
|
|
|
#include <test_util.hpp>
|
|
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
|
|
struct LinkLayerTest : public ::testing::Test
|
|
|
|
|
using namespace ::llarp;
|
|
|
|
|
using namespace ::testing;
|
|
|
|
|
|
|
|
|
|
struct LinkLayerTest : public test::LlarpTest< NoOpCrypto >
|
|
|
|
|
{
|
|
|
|
|
static constexpr uint16_t AlicePort = 5000;
|
|
|
|
|
static constexpr uint16_t BobPort = 6000;
|
|
|
|
|
|
|
|
|
|
struct Context
|
|
|
|
|
{
|
|
|
|
|
Context(llarp::Crypto& c)
|
|
|
|
|
Context()
|
|
|
|
|
{
|
|
|
|
|
crypto = &c;
|
|
|
|
|
crypto->identity_keygen(signingKey);
|
|
|
|
|
crypto->encryption_keygen(encryptionKey);
|
|
|
|
|
CryptoManager::instance()->identity_keygen(signingKey);
|
|
|
|
|
CryptoManager::instance()->encryption_keygen(encryptionKey);
|
|
|
|
|
rc.pubkey = signingKey.toPublic();
|
|
|
|
|
rc.enckey = encryptionKey.toPublic();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llarp::SecretKey signingKey;
|
|
|
|
|
llarp::SecretKey encryptionKey;
|
|
|
|
|
|
|
|
|
|
llarp::RouterContact rc;
|
|
|
|
|
SecretKey signingKey;
|
|
|
|
|
SecretKey encryptionKey;
|
|
|
|
|
|
|
|
|
|
llarp::Crypto* crypto;
|
|
|
|
|
RouterContact rc;
|
|
|
|
|
|
|
|
|
|
bool gotLIM = false;
|
|
|
|
|
|
|
|
|
|
const llarp::RouterContact&
|
|
|
|
|
const RouterContact&
|
|
|
|
|
GetRC() const
|
|
|
|
|
{
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llarp::RouterID
|
|
|
|
|
RouterID
|
|
|
|
|
GetRouterID() const
|
|
|
|
|
{
|
|
|
|
|
return rc.pubkey;
|
|
|
|
@ -49,12 +51,12 @@ struct LinkLayerTest : public ::testing::Test
|
|
|
|
|
bool
|
|
|
|
|
Regen()
|
|
|
|
|
{
|
|
|
|
|
crypto->encryption_keygen(encryptionKey);
|
|
|
|
|
rc.enckey = llarp::seckey_topublic(encryptionKey);
|
|
|
|
|
return rc.Sign(crypto, signingKey);
|
|
|
|
|
CryptoManager::instance()->encryption_keygen(encryptionKey);
|
|
|
|
|
rc.enckey = seckey_topublic(encryptionKey);
|
|
|
|
|
return rc.Sign(signingKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr< llarp::ILinkLayer > link;
|
|
|
|
|
std::shared_ptr< ILinkLayer > link;
|
|
|
|
|
|
|
|
|
|
static std::string
|
|
|
|
|
localLoopBack()
|
|
|
|
@ -68,7 +70,7 @@ struct LinkLayerTest : public ::testing::Test
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Start(std::shared_ptr<llarp::Logic> logic, llarp_ev_loop_ptr loop, uint16_t port)
|
|
|
|
|
Start(std::shared_ptr< Logic > logic, llarp_ev_loop_ptr loop, uint16_t port)
|
|
|
|
|
{
|
|
|
|
|
if(!link)
|
|
|
|
|
return false;
|
|
|
|
@ -79,7 +81,7 @@ struct LinkLayerTest : public ::testing::Test
|
|
|
|
|
rc.addrs.emplace_back();
|
|
|
|
|
if(!link->GetOurAddressInfo(rc.addrs[0]))
|
|
|
|
|
return false;
|
|
|
|
|
if(!rc.Sign(crypto, signingKey))
|
|
|
|
|
if(!rc.Sign(signingKey))
|
|
|
|
|
return false;
|
|
|
|
|
return link->Start(logic);
|
|
|
|
|
}
|
|
|
|
@ -99,30 +101,28 @@ struct LinkLayerTest : public ::testing::Test
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
llarp::sodium::CryptoLibSodium crypto;
|
|
|
|
|
|
|
|
|
|
Context Alice;
|
|
|
|
|
Context Bob;
|
|
|
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
|
|
llarp_ev_loop_ptr netLoop;
|
|
|
|
|
std::shared_ptr< llarp::Logic > m_logic;
|
|
|
|
|
std::shared_ptr< Logic > m_logic;
|
|
|
|
|
|
|
|
|
|
llarp_time_t oldRCLifetime;
|
|
|
|
|
|
|
|
|
|
LinkLayerTest() : Alice(crypto), Bob(crypto), netLoop(nullptr)
|
|
|
|
|
LinkLayerTest() : netLoop(nullptr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
SetUp()
|
|
|
|
|
{
|
|
|
|
|
oldRCLifetime = llarp::RouterContact::Lifetime;
|
|
|
|
|
llarp::RouterContact::IgnoreBogons = true;
|
|
|
|
|
llarp::RouterContact::Lifetime = 500;
|
|
|
|
|
netLoop = llarp_make_ev_loop();
|
|
|
|
|
m_logic.reset(new llarp::Logic());
|
|
|
|
|
oldRCLifetime = RouterContact::Lifetime;
|
|
|
|
|
RouterContact::IgnoreBogons = true;
|
|
|
|
|
RouterContact::Lifetime = 500;
|
|
|
|
|
netLoop = llarp_make_ev_loop();
|
|
|
|
|
m_logic.reset(new Logic());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
@ -132,8 +132,8 @@ struct LinkLayerTest : public ::testing::Test
|
|
|
|
|
Bob.TearDown();
|
|
|
|
|
m_logic.reset();
|
|
|
|
|
netLoop.reset();
|
|
|
|
|
llarp::RouterContact::IgnoreBogons = false;
|
|
|
|
|
llarp::RouterContact::Lifetime = oldRCLifetime;
|
|
|
|
|
RouterContact::IgnoreBogons = false;
|
|
|
|
|
RouterContact::Lifetime = oldRCLifetime;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
@ -168,10 +168,10 @@ struct LinkLayerTest : public ::testing::Test
|
|
|
|
|
|
|
|
|
|
TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
|
{
|
|
|
|
|
Alice.link = llarp::utp::NewServer(
|
|
|
|
|
&crypto, Alice.encryptionKey,
|
|
|
|
|
[&]() -> const llarp::RouterContact& { return Alice.GetRC(); },
|
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
Alice.link = utp::NewServer(
|
|
|
|
|
Alice.encryptionKey,
|
|
|
|
|
[&]() -> const RouterContact& { return Alice.GetRC(); },
|
|
|
|
|
[&](ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
if(Alice.gotLIM)
|
|
|
|
|
{
|
|
|
|
|
Alice.Regen();
|
|
|
|
@ -179,7 +179,7 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
llarp::LinkIntroMessage msg;
|
|
|
|
|
LinkIntroMessage msg;
|
|
|
|
|
ManagedBuffer copy{buf};
|
|
|
|
|
if(!msg.BDecode(©.underlying))
|
|
|
|
|
return false;
|
|
|
|
@ -189,25 +189,25 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* s) -> bool {
|
|
|
|
|
[&](ILinkSession* s) -> bool {
|
|
|
|
|
const auto rc = s->GetRemoteRC();
|
|
|
|
|
return rc.pubkey == Bob.GetRC().pubkey;
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return crypto.sign(sig, Alice.signingKey, buf);
|
|
|
|
|
[&](RouterContact, RouterContact) -> bool { return true; },
|
|
|
|
|
[&](Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return m_crypto.sign(sig, Alice.signingKey, buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
|
|
[&](ILinkSession* session) {
|
|
|
|
|
ASSERT_FALSE(session->IsEstablished());
|
|
|
|
|
Stop();
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterID router) { ASSERT_EQ(router, Bob.GetRouterID()); });
|
|
|
|
|
[&](RouterID router) { ASSERT_EQ(router, Bob.GetRouterID()); });
|
|
|
|
|
|
|
|
|
|
auto sendDiscardMessage = [](llarp::ILinkSession* s) -> bool {
|
|
|
|
|
auto sendDiscardMessage = [](ILinkSession* s) -> bool {
|
|
|
|
|
// send discard message in reply to complete unit test
|
|
|
|
|
std::array< byte_t, 32 > tmp;
|
|
|
|
|
llarp_buffer_t otherBuf(tmp);
|
|
|
|
|
llarp::DiscardMessage discard;
|
|
|
|
|
DiscardMessage discard;
|
|
|
|
|
if(!discard.BEncode(&otherBuf))
|
|
|
|
|
return false;
|
|
|
|
|
otherBuf.sz = otherBuf.cur - otherBuf.base;
|
|
|
|
@ -215,11 +215,10 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
|
return s->SendMessageBuffer(otherBuf);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Bob.link = llarp::utp::NewServer(
|
|
|
|
|
&crypto, Bob.encryptionKey,
|
|
|
|
|
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
|
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
llarp::LinkIntroMessage msg;
|
|
|
|
|
Bob.link = utp::NewServer(
|
|
|
|
|
Bob.encryptionKey, [&]() -> const RouterContact& { return Bob.GetRC(); },
|
|
|
|
|
[&](ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
LinkIntroMessage msg;
|
|
|
|
|
ManagedBuffer copy{buf};
|
|
|
|
|
if(!msg.BDecode(©.underlying))
|
|
|
|
|
return false;
|
|
|
|
@ -228,24 +227,22 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
|
Bob.gotLIM = true;
|
|
|
|
|
return sendDiscardMessage(s);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* s) -> bool {
|
|
|
|
|
[&](ILinkSession* s) -> bool {
|
|
|
|
|
if(s->GetRemoteRC().pubkey != Alice.GetRC().pubkey)
|
|
|
|
|
return false;
|
|
|
|
|
llarp::LogInfo("bob established with alice");
|
|
|
|
|
LogInfo("bob established with alice");
|
|
|
|
|
return Bob.link->VisitSessionByPubkey(Alice.GetRC().pubkey.as_array(),
|
|
|
|
|
sendDiscardMessage);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterContact newrc, llarp::RouterContact oldrc) -> bool {
|
|
|
|
|
[&](RouterContact newrc, RouterContact oldrc) -> bool {
|
|
|
|
|
success = newrc.pubkey == oldrc.pubkey;
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return crypto.sign(sig, Bob.signingKey, buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
|
|
ASSERT_FALSE(session->IsEstablished());
|
|
|
|
|
[&](Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return m_crypto.sign(sig, Bob.signingKey, buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterID router) { ASSERT_EQ(router, Alice.GetRouterID()); });
|
|
|
|
|
[&](ILinkSession* session) { ASSERT_FALSE(session->IsEstablished()); },
|
|
|
|
|
[&](RouterID router) { ASSERT_EQ(router, Alice.GetRouterID()); });
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(Alice.Start(m_logic, netLoop, AlicePort));
|
|
|
|
|
ASSERT_TRUE(Bob.Start(m_logic, netLoop, BobPort));
|
|
|
|
@ -259,11 +256,11 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
|
|
|
|
|
|
TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
|
|
|
|
|
{
|
|
|
|
|
Alice.link = llarp::utp::NewServer(
|
|
|
|
|
&crypto, Alice.encryptionKey,
|
|
|
|
|
[&]() -> const llarp::RouterContact& { return Alice.GetRC(); },
|
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
llarp::LinkIntroMessage lim;
|
|
|
|
|
Alice.link = utp::NewServer(
|
|
|
|
|
Alice.encryptionKey,
|
|
|
|
|
[&]() -> const RouterContact& { return Alice.GetRC(); },
|
|
|
|
|
[&](ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
LinkIntroMessage lim;
|
|
|
|
|
llarp_buffer_t copy(buf.base, buf.sz);
|
|
|
|
|
if(lim.BDecode(©))
|
|
|
|
|
{
|
|
|
|
@ -276,27 +273,26 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
|
|
|
|
|
}
|
|
|
|
|
return AliceGotMessage(buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* s) -> bool {
|
|
|
|
|
[&](ILinkSession* s) -> bool {
|
|
|
|
|
if(s->GetRemoteRC().pubkey != Bob.GetRC().pubkey)
|
|
|
|
|
return false;
|
|
|
|
|
llarp::LogInfo("alice established with bob");
|
|
|
|
|
LogInfo("alice established with bob");
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return crypto.sign(sig, Alice.signingKey, buf);
|
|
|
|
|
[&](RouterContact, RouterContact) -> bool { return true; },
|
|
|
|
|
[&](Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return m_crypto.sign(sig, Alice.signingKey, buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
|
|
[&](ILinkSession* session) {
|
|
|
|
|
ASSERT_FALSE(session->IsEstablished());
|
|
|
|
|
Stop();
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterID router) { ASSERT_EQ(router, Bob.GetRouterID()); });
|
|
|
|
|
[&](RouterID router) { ASSERT_EQ(router, Bob.GetRouterID()); });
|
|
|
|
|
|
|
|
|
|
Bob.link = llarp::utp::NewServer(
|
|
|
|
|
&crypto, Bob.encryptionKey,
|
|
|
|
|
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
|
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
llarp::LinkIntroMessage lim;
|
|
|
|
|
Bob.link = utp::NewServer(
|
|
|
|
|
Bob.encryptionKey, [&]() -> const RouterContact& { return Bob.GetRC(); },
|
|
|
|
|
[&](ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
LinkIntroMessage lim;
|
|
|
|
|
llarp_buffer_t copy(buf.base, buf.sz);
|
|
|
|
|
if(lim.BDecode(©))
|
|
|
|
|
{
|
|
|
|
@ -309,16 +305,16 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* s) -> bool {
|
|
|
|
|
[&](ILinkSession* s) -> bool {
|
|
|
|
|
if(s->GetRemoteRC().pubkey != Alice.GetRC().pubkey)
|
|
|
|
|
return false;
|
|
|
|
|
llarp::LogInfo("bob established with alice");
|
|
|
|
|
LogInfo("bob established with alice");
|
|
|
|
|
m_logic->queue_job({s, [](void* u) {
|
|
|
|
|
llarp::ILinkSession* self =
|
|
|
|
|
static_cast< llarp::ILinkSession* >(u);
|
|
|
|
|
ILinkSession* self =
|
|
|
|
|
static_cast< ILinkSession* >(u);
|
|
|
|
|
std::array< byte_t, 32 > tmp;
|
|
|
|
|
llarp_buffer_t otherBuf(tmp);
|
|
|
|
|
llarp::DiscardMessage discard;
|
|
|
|
|
DiscardMessage discard;
|
|
|
|
|
if(!discard.BEncode(&otherBuf))
|
|
|
|
|
return;
|
|
|
|
|
otherBuf.sz = otherBuf.cur - otherBuf.base;
|
|
|
|
@ -327,14 +323,12 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
|
|
|
|
|
}});
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return crypto.sign(sig, Bob.signingKey, buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
|
|
ASSERT_FALSE(session->IsEstablished());
|
|
|
|
|
[&](RouterContact, RouterContact) -> bool { return true; },
|
|
|
|
|
[&](Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return m_crypto.sign(sig, Bob.signingKey, buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterID router) { ASSERT_EQ(router, Alice.GetRouterID()); });
|
|
|
|
|
[&](ILinkSession* session) { ASSERT_FALSE(session->IsEstablished()); },
|
|
|
|
|
[&](RouterID router) { ASSERT_EQ(router, Alice.GetRouterID()); });
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(Alice.Start(m_logic, netLoop, AlicePort));
|
|
|
|
|
ASSERT_TRUE(Bob.Start(m_logic, netLoop, BobPort));
|
|
|
|
@ -345,93 +339,3 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
|
|
|
|
|
ASSERT_TRUE(Bob.gotLIM);
|
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
|
{
|
|
|
|
|
Alice.link = llarp::iwp::NewServer(
|
|
|
|
|
&crypto, Alice.encryptionKey,
|
|
|
|
|
[&]() -> const llarp::RouterContact& { return Alice.GetRC(); },
|
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
if(Alice.gotLIM)
|
|
|
|
|
{
|
|
|
|
|
return AliceGotMessage(buf);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
llarp::LinkIntroMessage msg;
|
|
|
|
|
ManagedBuffer copy{buf};
|
|
|
|
|
if(!msg.BDecode(©.underlying))
|
|
|
|
|
return false;
|
|
|
|
|
if(!s->GotLIM(&msg))
|
|
|
|
|
return false;
|
|
|
|
|
Alice.gotLIM = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterContact rc) {
|
|
|
|
|
ASSERT_EQ(rc, Bob.GetRC());
|
|
|
|
|
llarp::LogInfo("alice established with bob");
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return crypto.sign(sig, Alice.signingKey, buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
|
|
ASSERT_FALSE(session->IsEstablished());
|
|
|
|
|
Stop();
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterID router) { ASSERT_EQ(router, Bob.GetRouterID()); });
|
|
|
|
|
|
|
|
|
|
auto sendDiscardMessage = [](llarp::ILinkSession* s) -> bool {
|
|
|
|
|
// send discard message in reply to complete unit test
|
|
|
|
|
std::array< byte_t, 32 > tmp;
|
|
|
|
|
llarp_buffer_t otherBuf(tmp);
|
|
|
|
|
llarp::DiscardMessage discard;
|
|
|
|
|
if(!discard.BEncode(&otherBuf))
|
|
|
|
|
return false;
|
|
|
|
|
otherBuf.sz = otherBuf.cur - otherBuf.base;
|
|
|
|
|
otherBuf.cur = otherBuf.base;
|
|
|
|
|
return s->SendMessageBuffer(otherBuf);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Bob.link = llarp::iwp::NewServer(
|
|
|
|
|
&crypto, Bob.encryptionKey,
|
|
|
|
|
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
|
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
llarp::LinkIntroMessage msg;
|
|
|
|
|
ManagedBuffer copy{buf};
|
|
|
|
|
if(!msg.BDecode(©.underlying))
|
|
|
|
|
return false;
|
|
|
|
|
if(!s->GotLIM(&msg))
|
|
|
|
|
return false;
|
|
|
|
|
Bob.gotLIM = true;
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterContact rc) {
|
|
|
|
|
ASSERT_EQ(rc, Alice.GetRC());
|
|
|
|
|
llarp::LogInfo("bob established with alice");
|
|
|
|
|
Bob.link->VisitSessionByPubkey(Alice.GetRC().pubkey.as_array(),
|
|
|
|
|
sendDiscardMessage);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
|
return crypto.sign(sig, Bob.signingKey, buf);
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
|
|
ASSERT_FALSE(session->IsEstablished());
|
|
|
|
|
},
|
|
|
|
|
[&](llarp::RouterID router) { ASSERT_EQ(router, Alice.GetRouterID()); });
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(Alice.Start(m_logic.get(), netLoop, AlicePort));
|
|
|
|
|
ASSERT_TRUE(Bob.Start(m_logic.get(), netLoop, BobPort));
|
|
|
|
|
|
|
|
|
|
ASSERT_TRUE(Alice.link->TryEstablishTo(Bob.GetRC()));
|
|
|
|
|
|
|
|
|
|
RunMainloop();
|
|
|
|
|
ASSERT_TRUE(Alice.gotLIM);
|
|
|
|
|
ASSERT_TRUE(Bob.gotLIM);
|
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
|
};
|
|
|
|
|
*/
|
|
|
|
|