Merge pull request #375 from majestrate/staging

fix unit test
pull/384/head
Jeff 6 years ago committed by GitHub
commit 04f3912ca1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -189,7 +189,7 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
return true; return true;
} }
}, },
[&](llarp::ILinkSession * s) -> bool { [&](llarp::ILinkSession* s) -> bool {
const auto rc = s->GetRemoteRC(); const auto rc = s->GetRemoteRC();
return rc.pubkey == Bob.GetRC().pubkey; return rc.pubkey == Bob.GetRC().pubkey;
}, },
@ -228,12 +228,12 @@ TEST_F(LinkLayerTest, TestUTPAliceRenegWithBob)
Bob.gotLIM = true; Bob.gotLIM = true;
return sendDiscardMessage(s); return sendDiscardMessage(s);
}, },
[&](llarp::ILinkSession * s) -> bool { [&](llarp::ILinkSession* s) -> bool {
if(s->GetRemoteRC().pubkey != Alice.GetRC().pubkey) if(s->GetRemoteRC().pubkey != Alice.GetRC().pubkey)
return false; return false;
llarp::LogInfo("bob established with alice"); llarp::LogInfo("bob established with alice");
return 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 {
success = newrc.pubkey == oldrc.pubkey; success = newrc.pubkey == oldrc.pubkey;
@ -262,10 +262,21 @@ 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*, const llarp_buffer_t& buf) -> bool { [&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
llarp::LinkIntroMessage lim;
llarp_buffer_t copy(buf.base, buf.sz);
if(lim.BDecode(&copy))
{
if(s->GotLIM(&lim))
{
Alice.gotLIM = true;
return true;
}
return false;
}
return AliceGotMessage(buf); return AliceGotMessage(buf);
}, },
[&](llarp::ILinkSession * s) -> bool { [&](llarp::ILinkSession* s) -> bool {
if(s->GetRemoteRC().pubkey != Bob.GetRC().pubkey) if(s->GetRemoteRC().pubkey != Bob.GetRC().pubkey)
return false; return false;
llarp::LogInfo("alice established with bob"); llarp::LogInfo("alice established with bob");
@ -284,24 +295,36 @@ TEST_F(LinkLayerTest, TestUTPAliceConnectToBob)
Bob.link = llarp::utp::NewServer( Bob.link = llarp::utp::NewServer(
&crypto, Bob.encryptionKey, &crypto, Bob.encryptionKey,
[&]() -> const llarp::RouterContact& { return Bob.GetRC(); }, [&]() -> const llarp::RouterContact& { return Bob.GetRC(); },
[&](llarp::ILinkSession*, const llarp_buffer_t& ) -> bool { [&](llarp::ILinkSession* s, const llarp_buffer_t& buf) -> bool {
llarp::LinkIntroMessage lim;
llarp_buffer_t copy(buf.base, buf.sz);
if(lim.BDecode(&copy))
{
if(s->GotLIM(&lim))
{
Bob.gotLIM = true;
return true;
}
return false;
}
return true; return true;
}, },
[&](llarp::ILinkSession * s) -> bool { [&](llarp::ILinkSession* s) -> bool {
if(s->GetRemoteRC().pubkey != Alice.GetRC().pubkey) if(s->GetRemoteRC().pubkey != Alice.GetRC().pubkey)
return false; return false;
llarp::LogInfo("bob established with alice"); llarp::LogInfo("bob established with alice");
logic->queue_job({s, [](void * u) { logic->queue_job({s, [](void* u) {
llarp::ILinkSession * self = static_cast<llarp::ILinkSession*>(u); llarp::ILinkSession* self =
std::array< byte_t, 32 > tmp; static_cast< llarp::ILinkSession* >(u);
llarp_buffer_t otherBuf(tmp); std::array< byte_t, 32 > tmp;
llarp::DiscardMessage discard; llarp_buffer_t otherBuf(tmp);
if(!discard.BEncode(&otherBuf)) llarp::DiscardMessage discard;
return; if(!discard.BEncode(&otherBuf))
otherBuf.sz = otherBuf.cur - otherBuf.base; return;
otherBuf.cur = otherBuf.base; otherBuf.sz = otherBuf.cur - otherBuf.base;
self->SendMessageBuffer(otherBuf); otherBuf.cur = otherBuf.base;
}}); self->SendMessageBuffer(otherBuf);
}});
return true; return true;
}, },
[&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; }, [&](llarp::RouterContact, llarp::RouterContact) -> bool { return true; },

Loading…
Cancel
Save