|
|
@ -189,9 +189,9 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::RouterContact rc) {
|
|
|
|
[&](llarp::ILinkSession * s) -> bool {
|
|
|
|
ASSERT_EQ(rc, Bob.GetRC());
|
|
|
|
const auto rc = s->GetRemoteRC();
|
|
|
|
llarp::LogInfo("alice established with bob");
|
|
|
|
return rc.pubkey == Bob.GetRC().pubkey;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
@ -228,10 +228,11 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
Bob.gotLIM = true;
|
|
|
|
Bob.gotLIM = true;
|
|
|
|
return sendDiscardMessage(s);
|
|
|
|
return sendDiscardMessage(s);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::RouterContact rc) {
|
|
|
|
[&](llarp::ILinkSession * s) -> bool {
|
|
|
|
ASSERT_EQ(rc, Alice.GetRC());
|
|
|
|
if(s->GetRemoteRC().pubkey != Alice.GetRC().pubkey)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
llarp::LogInfo("bob established with alice");
|
|
|
|
llarp::LogInfo("bob established with alice");
|
|
|
|
Bob.link->VisitSessionByPubkey(Alice.GetRC().pubkey.as_array(),
|
|
|
|
return Bob.link->VisitSessionByPubkey(Alice.GetRC().pubkey.as_array(),
|
|
|
|
sendDiscardMessage);
|
|
|
|
sendDiscardMessage);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::RouterContact newrc, llarp::RouterContact oldrc) -> bool {
|
|
|
|
[&](llarp::RouterContact newrc, llarp::RouterContact oldrc) -> bool {
|
|
|
@ -252,7 +253,6 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
|
|
|
|
ASSERT_TRUE(Alice.link->TryEstablishTo(Bob.GetRC()));
|
|
|
|
ASSERT_TRUE(Alice.link->TryEstablishTo(Bob.GetRC()));
|
|
|
|
|
|
|
|
|
|
|
|
RunMainloop();
|
|
|
|
RunMainloop();
|
|
|
|
ASSERT_TRUE(Alice.gotLIM);
|
|
|
|
|
|
|
|
ASSERT_TRUE(Bob.gotLIM);
|
|
|
|
ASSERT_TRUE(Bob.gotLIM);
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -262,26 +262,14 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
|
|
|
|
Alice.link = llarp::utp::NewServer(
|
|
|
|
Alice.link = llarp::utp::NewServer(
|
|
|
|
&crypto, Alice.encryptionKey,
|
|
|
|
&crypto, Alice.encryptionKey,
|
|
|
|
[&]() -> const llarp::RouterContact& { return Alice.GetRC(); },
|
|
|
|
[&]() -> const llarp::RouterContact& { return Alice.GetRC(); },
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
[&](llarp::ILinkSession*, const llarp_buffer_t& buf) -> bool {
|
|
|
|
if(Alice.gotLIM)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return AliceGotMessage(buf);
|
|
|
|
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) {
|
|
|
|
[&](llarp::ILinkSession * s) -> bool {
|
|
|
|
ASSERT_EQ(rc, Bob.GetRC());
|
|
|
|
if(s->GetRemoteRC().pubkey != Bob.GetRC().pubkey)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
llarp::LogInfo("alice established with bob");
|
|
|
|
llarp::LogInfo("alice established with bob");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
@ -293,37 +281,29 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::RouterID router) { ASSERT_EQ(router, Bob.GetRouterID()); });
|
|
|
|
[&](llarp::RouterID router) { ASSERT_EQ(router, Bob.GetRouterID()); });
|
|
|
|
|
|
|
|
|
|
|
|
auto sendDiscardMessage = [](llarp::ILinkSession* s) -> bool {
|
|
|
|
Bob.link = llarp::utp::NewServer(
|
|
|
|
// send discard message in reply to complete unit test
|
|
|
|
&crypto, Bob.encryptionKey,
|
|
|
|
|
|
|
|
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
|
|
|
|
|
|
|
|
[&](llarp::ILinkSession*, const llarp_buffer_t& ) -> bool {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
[&](llarp::ILinkSession * s) -> bool {
|
|
|
|
|
|
|
|
if(s->GetRemoteRC().pubkey != Alice.GetRC().pubkey)
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
llarp::LogInfo("bob established with alice");
|
|
|
|
|
|
|
|
logic->queue_job({s, [](void * u) {
|
|
|
|
|
|
|
|
llarp::ILinkSession * self = static_cast<llarp::ILinkSession*>(u);
|
|
|
|
std::array< byte_t, 32 > tmp;
|
|
|
|
std::array< byte_t, 32 > tmp;
|
|
|
|
llarp_buffer_t otherBuf(tmp);
|
|
|
|
llarp_buffer_t otherBuf(tmp);
|
|
|
|
llarp::DiscardMessage discard;
|
|
|
|
llarp::DiscardMessage discard;
|
|
|
|
if(!discard.BEncode(&otherBuf))
|
|
|
|
if(!discard.BEncode(&otherBuf))
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
otherBuf.sz = otherBuf.cur - otherBuf.base;
|
|
|
|
otherBuf.sz = otherBuf.cur - otherBuf.base;
|
|
|
|
otherBuf.cur = otherBuf.base;
|
|
|
|
otherBuf.cur = otherBuf.base;
|
|
|
|
return s->SendMessageBuffer(otherBuf);
|
|
|
|
self->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;
|
|
|
|
|
|
|
|
ManagedBuffer copy{buf};
|
|
|
|
|
|
|
|
if(!msg.BDecode(©.underlying))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!s->GotLIM(&msg))
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Bob.gotLIM = true;
|
|
|
|
|
|
|
|
return 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::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
return crypto.sign(sig, Bob.signingKey, buf);
|
|
|
|
return crypto.sign(sig, Bob.signingKey, buf);
|
|
|
@ -339,18 +319,18 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
|
|
|
|
ASSERT_TRUE(Alice.link->TryEstablishTo(Bob.GetRC()));
|
|
|
|
ASSERT_TRUE(Alice.link->TryEstablishTo(Bob.GetRC()));
|
|
|
|
|
|
|
|
|
|
|
|
RunMainloop();
|
|
|
|
RunMainloop();
|
|
|
|
ASSERT_TRUE(Alice.gotLIM);
|
|
|
|
|
|
|
|
ASSERT_TRUE(Bob.gotLIM);
|
|
|
|
ASSERT_TRUE(Bob.gotLIM);
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
|
|
|
|
Alice.link = llarp::iwp::NewServer(
|
|
|
|
Alice.link = llarp::iwp::NewServer(
|
|
|
|
&crypto, Alice.encryptionKey,
|
|
|
|
&crypto, Alice.encryptionKey,
|
|
|
|
[&]() -> const llarp::RouterContact& { return Alice.GetRC(); },
|
|
|
|
[&]() -> const llarp::RouterContact& { return Alice.GetRC(); },
|
|
|
|
[&](llarp::ILinkSession* s, llarp_buffer_t buf) -> bool {
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
if(Alice.gotLIM)
|
|
|
|
if(Alice.gotLIM)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return AliceGotMessage(buf);
|
|
|
|
return AliceGotMessage(buf);
|
|
|
@ -358,7 +338,8 @@ TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
llarp::LinkIntroMessage msg;
|
|
|
|
llarp::LinkIntroMessage msg;
|
|
|
|
if(!msg.BDecode(&buf))
|
|
|
|
ManagedBuffer copy{buf};
|
|
|
|
|
|
|
|
if(!msg.BDecode(©.underlying))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
if(!s->GotLIM(&msg))
|
|
|
|
if(!s->GotLIM(&msg))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -371,7 +352,7 @@ TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
llarp::LogInfo("alice established with bob");
|
|
|
|
llarp::LogInfo("alice established with bob");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::Signature& sig, llarp_buffer_t buf) -> bool {
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
return crypto.sign(sig, Alice.signingKey, buf);
|
|
|
|
return crypto.sign(sig, Alice.signingKey, buf);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
@ -382,8 +363,8 @@ TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
|
|
|
|
|
|
|
|
auto sendDiscardMessage = [](llarp::ILinkSession* s) -> bool {
|
|
|
|
auto sendDiscardMessage = [](llarp::ILinkSession* s) -> bool {
|
|
|
|
// send discard message in reply to complete unit test
|
|
|
|
// send discard message in reply to complete unit test
|
|
|
|
byte_t tmp[32] = {0};
|
|
|
|
std::array< byte_t, 32 > tmp;
|
|
|
|
auto otherBuf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
|
|
|
llarp_buffer_t otherBuf(tmp);
|
|
|
|
llarp::DiscardMessage discard;
|
|
|
|
llarp::DiscardMessage discard;
|
|
|
|
if(!discard.BEncode(&otherBuf))
|
|
|
|
if(!discard.BEncode(&otherBuf))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -395,9 +376,10 @@ TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
Bob.link = llarp::iwp::NewServer(
|
|
|
|
Bob.link = llarp::iwp::NewServer(
|
|
|
|
&crypto, Bob.encryptionKey,
|
|
|
|
&crypto, Bob.encryptionKey,
|
|
|
|
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
|
|
|
|
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
|
|
|
|
[&](llarp::ILinkSession* s, llarp_buffer_t buf) -> bool {
|
|
|
|
[&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
|
|
|
|
llarp::LinkIntroMessage msg;
|
|
|
|
llarp::LinkIntroMessage msg;
|
|
|
|
if(!msg.BDecode(&buf))
|
|
|
|
ManagedBuffer copy{buf};
|
|
|
|
|
|
|
|
if(!msg.BDecode(©.underlying))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
if(!s->GotLIM(&msg))
|
|
|
|
if(!s->GotLIM(&msg))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -411,7 +393,7 @@ TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
sendDiscardMessage);
|
|
|
|
sendDiscardMessage);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },
|
|
|
|
[&](llarp::Signature& sig, llarp_buffer_t buf) -> bool {
|
|
|
|
[&](llarp::Signature& sig, const llarp_buffer_t& buf) -> bool {
|
|
|
|
return crypto.sign(sig, Bob.signingKey, buf);
|
|
|
|
return crypto.sign(sig, Bob.signingKey, buf);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
|
[&](llarp::ILinkSession* session) {
|
|
|
@ -428,5 +410,5 @@ TEST_F(LinkLayerTest, TestIWPAliceConnectToBob)
|
|
|
|
ASSERT_TRUE(Alice.gotLIM);
|
|
|
|
ASSERT_TRUE(Alice.gotLIM);
|
|
|
|
ASSERT_TRUE(Bob.gotLIM);
|
|
|
|
ASSERT_TRUE(Bob.gotLIM);
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
ASSERT_TRUE(success);
|
|
|
|
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|