mirror of https://github.com/oxen-io/lokinet
done for the day
This commit is contained in:
parent
c5d4e37f59
commit
e58f2c521e
|
@ -52,21 +52,19 @@ def main():
|
|||
config['netdb'] = {
|
||||
'dir': 'netdb'
|
||||
}
|
||||
config['connect'] = {}
|
||||
|
||||
for otherid in range(args.connect):
|
||||
otherid = (nodeid + otherid) % args.svc
|
||||
name = svcNodeName(otherid)
|
||||
config['connect'][name] = os.path.join(
|
||||
basedir, name, 'rc.signed')
|
||||
|
||||
config['network'] = {
|
||||
'type' : 'null'
|
||||
}
|
||||
d = os.path.join(args.dir, svcNodeName(nodeid))
|
||||
if not os.path.exists(d):
|
||||
os.mkdir(d)
|
||||
fp = os.path.join(d, 'daemon.ini')
|
||||
with open(fp, 'w') as f:
|
||||
config.write(f)
|
||||
if nodeid > 0:
|
||||
f.write("[bootstrap]\nadd-node={}\n".format(os.path.join(basedir,svcNodeName(0), 'rc.signed')))
|
||||
|
||||
|
||||
for nodeid in range(args.clients):
|
||||
config = CP()
|
||||
|
||||
|
@ -78,13 +76,9 @@ def main():
|
|||
config['netdb'] = {
|
||||
'dir': 'netdb'
|
||||
}
|
||||
config['connect'] = {}
|
||||
for otherid in range(args.connect):
|
||||
otherid = (nodeid + otherid) % args.svc
|
||||
name = svcNodeName(otherid)
|
||||
config['connect'][name] = os.path.join(
|
||||
basedir, name, 'rc.signed')
|
||||
|
||||
config['network'] = {
|
||||
'type' : 'null'
|
||||
}
|
||||
d = os.path.join(args.dir, clientNodeName(nodeid))
|
||||
if not os.path.exists(d):
|
||||
os.mkdir(d)
|
||||
|
@ -95,6 +89,7 @@ def main():
|
|||
fp = os.path.join(d, 'daemon.ini')
|
||||
with open(fp, 'w') as f:
|
||||
config.write(f)
|
||||
f.write("[bootstrap]\nadd-node={}\n".format(os.path.join(basedir,svcNodeName(0), 'rc.signed')))
|
||||
with open(hiddenservice, 'w') as f:
|
||||
f.write('''[test-service]
|
||||
tag=test
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace llarp
|
|||
using GetRCFunc = std::function< const llarp::RouterContact&(void) >;
|
||||
|
||||
/// handler of session established
|
||||
using SessionEstablishedHandler = std::function< void(ILinkSession*) >;
|
||||
using SessionEstablishedHandler = std::function< void(llarp::RouterContact) >;
|
||||
|
||||
/// handles close of all sessions with pubkey
|
||||
using SessionClosedHandler = std::function< void(llarp::RouterID) >;
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace llarp
|
|||
std::function< const Addr &(void) > GetRemoteEndpoint;
|
||||
|
||||
// get remote rc
|
||||
std::function< const llarp::RouterContact &(void) > GetRemoteRC;
|
||||
std::function< llarp::RouterContact(void) > GetRemoteRC;
|
||||
|
||||
/// handle a valid LIM
|
||||
std::function< bool(const LinkIntroMessage *msg) > GotLIM;
|
||||
|
|
|
@ -580,7 +580,7 @@ namespace llarp
|
|||
return this->IsTimedOut(now) || this->state == eClose;
|
||||
};
|
||||
GetPubKey = std::bind(&Session::RemotePubKey, this);
|
||||
GetRemoteRC = std::bind(&Session::RemoteRC, this);
|
||||
GetRemoteRC = [&]() -> llarp::RouterContact { return this->remoteRC; };
|
||||
GetLinkLayer = std::bind(&Session::GetParent, this);
|
||||
|
||||
lastActive = parent->Now();
|
||||
|
@ -632,12 +632,6 @@ namespace llarp
|
|||
GotLIM = std::bind(&Session::InboundLIM, this, std::placeholders::_1);
|
||||
}
|
||||
|
||||
const RouterContact&
|
||||
Session::RemoteRC() const
|
||||
{
|
||||
return remoteRC;
|
||||
}
|
||||
|
||||
ILinkLayer*
|
||||
Session::GetParent()
|
||||
{
|
||||
|
@ -699,10 +693,11 @@ namespace llarp
|
|||
Close();
|
||||
return false;
|
||||
}
|
||||
llarp::LogDebug("Sent reply LIM");
|
||||
if(!DoKeyExchange(Crypto()->transport_dh_client, txKey, replymsg.N,
|
||||
remoteRC.enckey, parent->RouterEncryptionSecret()))
|
||||
|
||||
return false;
|
||||
llarp::LogDebug("Sent reply LIM");
|
||||
gotLIM = true;
|
||||
EnterState(eSessionReady);
|
||||
}
|
||||
|
@ -943,25 +938,25 @@ namespace llarp
|
|||
Alive();
|
||||
if(st == eSessionReady)
|
||||
{
|
||||
parent->MapAddr(remoteRC.pubkey, this);
|
||||
parent->SessionEstablished(this);
|
||||
parent->MapAddr(remoteRC.pubkey.data(), this);
|
||||
parent->SessionEstablished(remoteRC);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
Session::VerifyThenDecrypt(const byte_t* buf)
|
||||
Session::VerifyThenDecrypt(const byte_t* ptr)
|
||||
{
|
||||
llarp::LogDebug("verify then decrypt ", remoteAddr);
|
||||
ShortHash digest;
|
||||
|
||||
auto hbuf = InitBuffer(buf + FragmentHashSize,
|
||||
auto hbuf = InitBuffer(ptr + FragmentHashSize,
|
||||
FragmentBufferSize - FragmentHashSize);
|
||||
if(!Crypto()->hmac(digest.data(), hbuf, rxKey))
|
||||
{
|
||||
llarp::LogError("keyed hash failed");
|
||||
return false;
|
||||
}
|
||||
ShortHash expected(buf);
|
||||
ShortHash expected(ptr);
|
||||
if(expected != digest)
|
||||
{
|
||||
llarp::LogError("Message Integrity Failed: got ", digest, " from ",
|
||||
|
@ -969,13 +964,13 @@ namespace llarp
|
|||
return false;
|
||||
}
|
||||
|
||||
auto in = InitBuffer(buf + FragmentOverheadSize,
|
||||
auto in = InitBuffer(ptr + FragmentOverheadSize,
|
||||
FragmentBufferSize - FragmentOverheadSize);
|
||||
|
||||
auto out = Buffer(rxFragBody);
|
||||
|
||||
// decrypt
|
||||
if(!Crypto()->xchacha20_alt(out, in, rxKey, buf + FragmentHashSize))
|
||||
if(!Crypto()->xchacha20_alt(out, in, rxKey, ptr + FragmentHashSize))
|
||||
{
|
||||
llarp::LogError("failed to decrypt message from ", remoteAddr);
|
||||
return false;
|
||||
|
@ -1005,15 +1000,19 @@ namespace llarp
|
|||
llarp::LogError("fragment body too big");
|
||||
return false;
|
||||
}
|
||||
if(msgid < m_NextRXMsgID)
|
||||
return false;
|
||||
m_NextRXMsgID = msgid;
|
||||
|
||||
// get message
|
||||
auto& inbound = m_RecvMsgs[msgid];
|
||||
// set next message
|
||||
m_NextRXMsgID = std::max(msgid, m_NextRXMsgID);
|
||||
if(m_RecvMsgs.find(msgid) == m_RecvMsgs.end())
|
||||
m_RecvMsgs.emplace(std::make_pair(msgid, InboundMessage{}));
|
||||
|
||||
auto itr = m_RecvMsgs.find(msgid);
|
||||
// add message activity
|
||||
inbound.lastActive = parent->Now();
|
||||
itr->second.lastActive = parent->Now();
|
||||
// append data
|
||||
if(!inbound.AppendData(out.cur, length))
|
||||
if(!itr->second.AppendData(out.cur, length))
|
||||
{
|
||||
llarp::LogError("inbound buffer is full");
|
||||
return false; // not enough room
|
||||
|
@ -1022,15 +1021,16 @@ namespace llarp
|
|||
bool result = true;
|
||||
if(remaining == 0)
|
||||
{
|
||||
llarp_buffer_t buf = itr->second.buffer;
|
||||
// resize
|
||||
inbound.buffer.sz = inbound.buffer.cur - inbound.buffer.base;
|
||||
buf.sz = buf.cur - buf.base;
|
||||
// rewind
|
||||
inbound.buffer.cur = inbound.buffer.base;
|
||||
buf.cur = buf.base;
|
||||
// process buffer
|
||||
llarp::LogDebug("got message ", msgid, " from ", remoteAddr);
|
||||
result = parent->HandleMessage(this, inbound.buffer);
|
||||
result = parent->HandleMessage(this, buf);
|
||||
// get rid of message buffer
|
||||
m_RecvMsgs.erase(msgid);
|
||||
itr = m_RecvMsgs.erase(itr);
|
||||
}
|
||||
// mutate key
|
||||
if(msgid)
|
||||
|
|
|
@ -55,7 +55,13 @@ namespace llarp
|
|||
MessageBuffer _msg;
|
||||
|
||||
/// for accessing message buffer
|
||||
llarp_buffer_t buffer = llarp::Buffer(_msg);
|
||||
llarp_buffer_t buffer = llarp::InitBuffer(_msg.data(), _msg.size());
|
||||
|
||||
bool
|
||||
operator==(const InboundMessage& other) const
|
||||
{
|
||||
return buffer.base == other.buffer.base;
|
||||
}
|
||||
|
||||
/// return true if this inbound message can be removed due to expiration
|
||||
bool
|
||||
|
@ -231,10 +237,6 @@ namespace llarp
|
|||
const Addr&
|
||||
RemoteEndpoint() const;
|
||||
|
||||
/// get remote rc
|
||||
const RouterContact&
|
||||
RemoteRC() const;
|
||||
|
||||
/// get parent link
|
||||
ILinkLayer*
|
||||
GetParent();
|
||||
|
|
|
@ -179,9 +179,9 @@ llarp_findOrCreateEncryption(llarp::Crypto *crypto, const char *fpath,
|
|||
namespace llarp
|
||||
{
|
||||
void
|
||||
Router::OnSessionEstablished(llarp::ILinkSession *session)
|
||||
Router::OnSessionEstablished(llarp::RouterContact rc)
|
||||
{
|
||||
async_verify_RC(session->GetRemoteRC(), session->GetLinkLayer());
|
||||
async_verify_RC(rc, nullptr);
|
||||
}
|
||||
|
||||
Router::Router(struct llarp_threadpool *_tp, struct llarp_ev_loop *_netloop,
|
||||
|
|
|
@ -191,7 +191,7 @@ namespace llarp
|
|||
~Router();
|
||||
|
||||
void
|
||||
OnSessionEstablished(llarp::ILinkSession *from);
|
||||
OnSessionEstablished(llarp::RouterContact rc);
|
||||
|
||||
bool
|
||||
HandleRecvLinkMessageBuffer(llarp::ILinkSession *from, llarp_buffer_t msg);
|
||||
|
|
|
@ -161,24 +161,13 @@ TEST_F(UTPTest, TestAliceAndBob)
|
|||
return false;
|
||||
if(!s->GotLIM(&msg))
|
||||
return false;
|
||||
Alice.gotLIM = true;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
[&](llarp::Signature& sig, llarp_buffer_t buf) -> bool {
|
||||
return crypto.sign(sig, Alice.signingKey, buf);
|
||||
},
|
||||
[&](llarp::ILinkSession* session) {
|
||||
ASSERT_EQ(session->GetRemoteRC(), Bob.GetRC());
|
||||
llarp::DiscardMessage msg;
|
||||
byte_t tmp[32] = {0};
|
||||
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
||||
ASSERT_TRUE(msg.BEncode(&buf));
|
||||
buf.sz = buf.cur - buf.base;
|
||||
buf.cur = buf.base;
|
||||
ASSERT_TRUE(session->SendMessageBuffer(buf));
|
||||
ASSERT_TRUE(session->SendMessageBuffer(buf));
|
||||
},
|
||||
[&](llarp::RouterContact rc) { ASSERT_EQ(rc, Bob.GetRC()); },
|
||||
[&](llarp::ILinkSession* session) {
|
||||
ASSERT_FALSE(session->IsEstablished());
|
||||
Stop();
|
||||
|
@ -207,17 +196,7 @@ TEST_F(UTPTest, TestAliceAndBob)
|
|||
[&](llarp::Signature& sig, llarp_buffer_t buf) -> bool {
|
||||
return crypto.sign(sig, Bob.signingKey, buf);
|
||||
},
|
||||
[&](llarp::ILinkSession* session) {
|
||||
ASSERT_EQ(session->GetRemoteRC(), Alice.GetRC());
|
||||
llarp::DiscardMessage msg;
|
||||
byte_t tmp[32] = {0};
|
||||
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
||||
ASSERT_TRUE(msg.BEncode(&buf));
|
||||
buf.sz = buf.cur - buf.base;
|
||||
buf.cur = buf.base;
|
||||
ASSERT_TRUE(session->SendMessageBuffer(buf));
|
||||
ASSERT_TRUE(session->SendMessageBuffer(buf));
|
||||
},
|
||||
[&](llarp::RouterContact rc) { ASSERT_EQ(rc, Alice.GetRC()); },
|
||||
[&](llarp::ILinkSession* session) {
|
||||
ASSERT_FALSE(session->IsEstablished());
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue