From 19e3b9c642f54840591fb256b806afeff3de1cea Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 23 Jul 2018 17:38:29 +1000 Subject: [PATCH] * more hidden service code * begin lokinet api --- CMakeLists.txt | 1 - doc/lokinet_api_v0.txt | 1 + include/llarp/codel.hpp | 2 +- include/llarp/iwp/inbound_message.hpp | 6 +- include/llarp/iwp/server.hpp | 84 ++++++++-------- include/llarp/iwp/session.hpp | 2 +- include/llarp/logger.hpp | 2 + include/llarp/messages/hidden_service.hpp | 16 --- include/llarp/path.hpp | 3 + include/llarp/routing/handler.hpp | 4 +- include/llarp/service/endpoint.hpp | 8 +- include/llarp/service/frame.hpp | 28 ------ include/llarp/service/protocol.hpp | 6 +- include/lokinet/lokinet.hpp | 60 ++++++++++++ llarp/iwp/frame_state.cpp | 7 +- llarp/iwp/session.cpp | 9 +- llarp/iwp/transit_message.cpp | 8 +- llarp/path.cpp | 19 +++- llarp/pathset.cpp | 7 +- llarp/routing/path_transfer.cpp | 3 +- llarp/service/endpoint.cpp | 113 +++++++++++++++++++--- llarp/service/frame.cpp | 8 -- llarp/service/protocol.cpp | 9 ++ llarp/transit_hop.cpp | 2 + 24 files changed, 275 insertions(+), 133 deletions(-) create mode 100644 doc/lokinet_api_v0.txt delete mode 100644 include/llarp/messages/hidden_service.hpp delete mode 100644 include/llarp/service/frame.hpp create mode 100644 include/lokinet/lokinet.hpp delete mode 100644 llarp/service/frame.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2081f5f7d..b197d4033 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,7 +242,6 @@ set(LIB_SRC llarp/service/address.cpp llarp/service/context.cpp llarp/service/endpoint.cpp - llarp/service/frame.cpp llarp/service/lookup.cpp llarp/service/protocol.cpp llarp/service/tag.cpp diff --git a/doc/lokinet_api_v0.txt b/doc/lokinet_api_v0.txt new file mode 100644 index 000000000..02db168e8 --- /dev/null +++ b/doc/lokinet_api_v0.txt @@ -0,0 +1 @@ +insert lokinet api overview here \ No newline at end of file diff --git a/include/llarp/codel.hpp b/include/llarp/codel.hpp index 7492c330f..f30e7cccb 100644 --- a/include/llarp/codel.hpp +++ b/include/llarp/codel.hpp @@ -47,7 +47,7 @@ namespace llarp template < typename T, typename GetTime, typename PutTime, typename Compare, typename Mutex_t = std::mutex, - typename Lock_t = std::unique_lock< Mutex_t >, + typename Lock_t = std::lock_guard< std::mutex >, llarp_time_t dropMs = 5, llarp_time_t initialIntervalMs = 100 > struct CoDelQueue { diff --git a/include/llarp/iwp/inbound_message.hpp b/include/llarp/iwp/inbound_message.hpp index 6524b54c8..8b83b9b6f 100644 --- a/include/llarp/iwp/inbound_message.hpp +++ b/include/llarp/iwp/inbound_message.hpp @@ -18,10 +18,10 @@ struct InboundMessage } bool - operator>(const InboundMessage &other) const + operator<(const InboundMessage &other) const { // order in ascending order for codel queue - return msgid > other.msgid; + return msgid < other.msgid; } llarp_buffer_t @@ -42,7 +42,7 @@ struct InboundMessage struct OrderCompare { bool - operator()(const InboundMessage *left, const InboundMessage *right) + operator()(const InboundMessage *left, const InboundMessage *right) const { return left->msgid < right->msgid; } diff --git a/include/llarp/iwp/server.hpp b/include/llarp/iwp/server.hpp index 101a1e04e..9319bf019 100644 --- a/include/llarp/iwp/server.hpp +++ b/include/llarp/iwp/server.hpp @@ -114,20 +114,6 @@ struct llarp_link TickSessions() { auto now = llarp_time_now_ms(); - std::set< llarp::Addr > remove; - { - lock_t lock(m_sessions_Mutex); - - for(auto &itr : m_sessions) - { - llarp_link_session *s = itr.second; - if(s && s->Tick(now)) - remove.insert(itr.first); - } - } - for(const auto &addr : remove) - RemoveSessionByAddr(addr); - { lock_t lock(m_PendingSessions_Mutex); auto itr = m_PendingSessions.begin(); @@ -135,31 +121,49 @@ struct llarp_link { if(itr->second->timedout(now)) { + itr->second->done(); + delete itr->second; itr = m_PendingSessions.erase(itr); } else ++itr; } } + { + lock_t lock(m_sessions_Mutex); + auto itr = m_sessions.begin(); + while(itr != m_sessions.end()) + { + if(itr->second->Tick(now)) + { + itr->second->done(); + delete itr->second; + itr = m_sessions.erase(itr); + } + else + ++itr; + } + } } static bool sendto(llarp_link *serv, const byte_t *pubkey, llarp_buffer_t buf) { - // lock_t lock(serv->m_Connected_Mutex); - auto itr = serv->m_Connected.find(pubkey); - if(itr != serv->m_Connected.end()) + llarp_link_session *link = nullptr; { - // lock_t innerlock(serv->m_sessions_Mutex); - auto inner_itr = serv->m_sessions.find(itr->second); - if(inner_itr != serv->m_sessions.end()) + lock_t lock(serv->m_Connected_Mutex); + auto itr = serv->m_Connected.find(pubkey); + if(itr != serv->m_Connected.end()) { - llarp_link_session *link = inner_itr->second; - return link->sendto(buf); + lock_t innerlock(serv->m_sessions_Mutex); + auto inner_itr = serv->m_sessions.find(itr->second); + if(inner_itr != serv->m_sessions.end()) + { + link = inner_itr->second; + } } } - - return false; + return link && link->sendto(buf); } void @@ -229,15 +233,20 @@ struct llarp_link void iterate_sessions(std::function< bool(llarp_link_session *) > visitor) { + auto now = llarp_time_now_ms(); std::list< llarp_link_session * > slist; { lock_t lock(m_sessions_Mutex); - for(const auto &itr : m_sessions) + auto itr = m_sessions.begin(); + while(itr != m_sessions.end()) { - slist.push_back(itr.second); + // if not timing out soon add to list to iterate on + if(!itr->second->timedout(now, 11500)) + slist.push_back(itr->second); + ++itr; } } - for(auto s : slist) + for(auto &s : slist) if(!visitor(s)) return; } @@ -246,32 +255,31 @@ struct llarp_link handle_logic_pump(void *user) { llarp_link *self = static_cast< llarp_link * >(user); - self->iterate_sessions([](llarp_link_session *s) -> bool { - s->TickLogic(); + auto now = llarp_time_now_ms(); + self->iterate_sessions([now](llarp_link_session *s) -> bool { + s->TickLogic(now); return true; }); - self->pumpingLogic = false; + // self->pumpingLogic = false; } void PumpLogic() { - if(pumpingLogic) - return; - pumpingLogic = true; + // if(pumpingLogic) + // return; + // pumpingLogic = true; llarp_logic_queue_job(logic, {this, &handle_logic_pump}); } void - RemoveSessionByAddr(const llarp::Addr &addr) + RemoveSession(llarp_link_session *s) { lock_t lock(m_sessions_Mutex); - auto itr = m_sessions.find(addr); + auto itr = m_sessions.find(s->addr); if(itr != m_sessions.end()) { - llarp::LogDebug("removing session ", addr); - UnmapAddr(addr); - llarp_link_session *s = itr->second; + UnmapAddr(s->addr); s->done(); m_sessions.erase(itr); delete s; diff --git a/include/llarp/iwp/session.hpp b/include/llarp/iwp/session.hpp index 1bfca0fe4..7f5cc292e 100644 --- a/include/llarp/iwp/session.hpp +++ b/include/llarp/iwp/session.hpp @@ -86,7 +86,7 @@ struct llarp_link_session // process inbound and outbound queues (logic thread) void - TickLogic(); + TickLogic(llarp_time_t now); // this is called from net thread void diff --git a/include/llarp/logger.hpp b/include/llarp/logger.hpp index c2d035e42..d2bb6c260 100644 --- a/include/llarp/logger.hpp +++ b/include/llarp/logger.hpp @@ -78,9 +78,11 @@ namespace llarp std::time_t t; std::time(&t); std::string tag = fname; + /* auto pos = tag.rfind('/'); if(pos != std::string::npos) tag = tag.substr(pos + 1); + */ ss << std::put_time(std::localtime(&t), "%F %T") << " " << tag; auto sz = tag.size() % 8; while(sz--) diff --git a/include/llarp/messages/hidden_service.hpp b/include/llarp/messages/hidden_service.hpp deleted file mode 100644 index b417f81d2..000000000 --- a/include/llarp/messages/hidden_service.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef LLARP_MESSAGES_HIDDEN_SERIVCE_HPP -#define LLARP_MESSAGES_HIDDEN_SERIVCE_HPP - -#include - -namespace llarp -{ - namespace routing - { - struct HiddenServiceFrame : public IMessage - { - }; - } // namespace routing -} // namespace llarp - -#endif \ No newline at end of file diff --git a/include/llarp/path.hpp b/include/llarp/path.hpp index fcfada9c8..50f815184 100644 --- a/include/llarp/path.hpp +++ b/include/llarp/path.hpp @@ -259,6 +259,9 @@ namespace llarp const PathID_t& TXID() const; + RouterID + Endpoint() const; + const PathID_t& RXID() const; diff --git a/include/llarp/routing/handler.hpp b/include/llarp/routing/handler.hpp index 02069953f..a7f41d385 100644 --- a/include/llarp/routing/handler.hpp +++ b/include/llarp/routing/handler.hpp @@ -4,7 +4,7 @@ #include #include #include -#include + #include #include #include @@ -21,7 +21,7 @@ namespace llarp llarp_router *r) = 0; virtual bool - HandleHiddenServiceFrame(const HiddenServiceFrame *msg) + HandleHiddenServiceFrame(const service::ProtocolFrame *msg) { return false; } diff --git a/include/llarp/service/endpoint.hpp b/include/llarp/service/endpoint.hpp index e670a9823..e10ddd0a2 100644 --- a/include/llarp/service/endpoint.hpp +++ b/include/llarp/service/endpoint.hpp @@ -1,7 +1,6 @@ #ifndef LLARP_SERVICE_ENDPOINT_HPP #define LLARP_SERVICE_ENDPOINT_HPP #include -#include #include #include #include @@ -58,7 +57,7 @@ namespace llarp HandleGotIntroMessage(const llarp::dht::GotIntroMessage* msg); bool - HandleHiddenServiceFrame(const llarp::routing::HiddenServiceFrame* msg); + HandleHiddenServiceFrame(const llarp::service::ProtocolFrame* msg); /// return true if we have an established path to a hidden service bool @@ -90,6 +89,11 @@ namespace llarp void ShiftIntroduction(); + /// tick internal state + /// return true to remove otherwise don't remove + bool + Tick(llarp_time_t now); + /// encrypt asynchronously and send to remote endpoint from us void AsyncEncryptAndSendTo(llarp_buffer_t D, ProtocolType protocol); diff --git a/include/llarp/service/frame.hpp b/include/llarp/service/frame.hpp deleted file mode 100644 index 11e598d2b..000000000 --- a/include/llarp/service/frame.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef LLARP_SERVICE_FRAME_HPP -#define LLARP_SERVICE_FRAME_HPP -#include -#include -#include - -namespace llarp -{ - namespace service - { - struct DataFrame : public llarp::IBEncodeMessage - { - llarp::Encrypted D; - llarp::PubKey H; - llarp::KeyExchangeNonce N; - uint64_t S = 0; - llarp::Signature Z; - - bool - BEncode(llarp_buffer_t* buf) const; - - bool - DecodeKey(llarp_buffer_t key, llarp_buffer_t* val); - }; - } // namespace service -} // namespace llarp - -#endif \ No newline at end of file diff --git a/include/llarp/service/protocol.hpp b/include/llarp/service/protocol.hpp index d80c494e4..474a54841 100644 --- a/include/llarp/service/protocol.hpp +++ b/include/llarp/service/protocol.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -41,7 +42,7 @@ namespace llarp }; /// outer message - struct ProtocolFrame : public llarp::IBEncodeMessage + struct ProtocolFrame : public llarp::routing::IMessage { llarp::Encrypted D; uint64_t S = 0; @@ -67,6 +68,9 @@ namespace llarp bool Verify(llarp_crypto* c, byte_t* signingkey); + + bool + HandleMessage(llarp::routing::IMessageHandler* h, llarp_router* r) const; }; } // namespace service } // namespace llarp diff --git a/include/lokinet/lokinet.hpp b/include/lokinet/lokinet.hpp new file mode 100644 index 000000000..39501ab14 --- /dev/null +++ b/include/lokinet/lokinet.hpp @@ -0,0 +1,60 @@ +#ifndef LOKINET_LOKINET_HPP +#define LOKINET_LOKINET_HPP +#include +#include +#include +#include +#include + +namespace lokinet +{ + struct API_PImpl; + struct RPCMessage : public llarp::IBEncodeMessage + { + }; + + /// a persisting anonymized session to a serive node + struct Handle + { + llarp::RouterID remote; + + bool + Send(const RPCMessage* msg); + + RPCMessage* + Recv(); + + typedef std::shared_ptr< Handle > Ptr; + + private: + API_PImpl* m_Impl; + }; + + struct Client + { + void + Run(); + }; + + struct IMessageHandler + { + virtual RPCMessage* + HandleMessage(const RPCMessage* inmsg) = 0; + }; + + struct Server_PImpl; + struct Server + { + Server(const uint8_t* secretkey, IMessageHandler* h); + ~Server(); + + void + Run(); + + private: + Server_PImpl* m_Impl; + }; + +} // namespace lokinet + +#endif \ No newline at end of file diff --git a/llarp/iwp/frame_state.cpp b/llarp/iwp/frame_state.cpp index ecbaaab96..b87483ff2 100644 --- a/llarp/iwp/frame_state.cpp +++ b/llarp/iwp/frame_state.cpp @@ -21,18 +21,15 @@ frame_state::process_inbound_queue() InboundMessage::OrderCompare > q; recvqueue.Process(q); - bool increment = false; while(q.size()) { // TODO: is this right? auto &front = q.top(); - // the items are already sorted anyways so this doesn't really do much if(front->msgid < nextMsgID && nextMsgID - front->msgid > 1) { - // re queue + // re-queue because of an ordering gap recvqueue.Put(front); - nextMsgID = front->msgid; } else { @@ -373,7 +370,7 @@ frame_state::queue_tx(uint64_t id, transit_message *msg) { tx.insert(std::make_pair(id, msg)); msg->generate_xmit(sendqueue, txflags); - msg->retransmit_frags(sendqueue, txflags); + // msg->retransmit_frags(sendqueue, txflags); } void diff --git a/llarp/iwp/session.cpp b/llarp/iwp/session.cpp index f5bd6978d..8bc51061f 100644 --- a/llarp/iwp/session.cpp +++ b/llarp/iwp/session.cpp @@ -246,7 +246,7 @@ handle_verify_introack(iwp_async_introack *introack) // invalid signature llarp::LogError("introack verify failed from ", link->addr); link->serv->remove_intro_from(link->addr); - link->serv->RemoveSessionByAddr(link->addr); + link->serv->RemoveSession(link); return; } link->EnterState(llarp_link_session::eIntroAckRecv); @@ -379,7 +379,7 @@ llarp_link_session::on_intro_ack(const void *buf, size_t sz) { // too big? llarp::LogError("introack too big"); - serv->RemoveSessionByAddr(addr); + serv->RemoveSession(this); return; } serv->put_intro_from(this); @@ -412,7 +412,7 @@ llarp_link_session::get_parent() } void -llarp_link_session::TickLogic() +llarp_link_session::TickLogic(llarp_time_t now) { std::queue< iwp_async_frame * > q; decryptedFrames.Process(q); @@ -489,8 +489,7 @@ handle_verify_session_start(iwp_async_session_start *s) // verify fail // TODO: remove session? llarp::LogWarn("session start verify failed from ", self->addr); - self->serv->RemoveSessionByAddr(self->addr); - + self->serv->RemoveSession(self); return; } self->send_LIM(); diff --git a/llarp/iwp/transit_message.cpp b/llarp/iwp/transit_message.cpp index 97b42ce53..4c1846228 100644 --- a/llarp/iwp/transit_message.cpp +++ b/llarp/iwp/transit_message.cpp @@ -67,19 +67,21 @@ transit_message::should_send_ack(llarp_time_t now) const { if(msginfo.numfrags() == 0) return true; - return now - lastRetransmit > 250; + if(status.count() == 0) + return true; + return now - lastRetransmit > 100; } bool transit_message::should_resend_xmit(llarp_time_t now) const { - return lastAck == 0 && now - started > 1000; + return lastAck == 0 && now - started > 500; } bool transit_message::should_resend_frags(llarp_time_t now) const { - return now - lastAck > 1000 && !completed(); + return lastAck > 0 && now - lastAck > 250 && !completed(); } bool diff --git a/llarp/path.cpp b/llarp/path.cpp index 2edf97b0b..505ee68d1 100644 --- a/llarp/path.cpp +++ b/llarp/path.cpp @@ -304,6 +304,12 @@ namespace llarp m_BuiltHook = func; } + RouterID + Path::Endpoint() const + { + return hops[hops.size() - 1].router.pubkey; + } + const PathID_t& Path::TXID() const { @@ -331,6 +337,8 @@ namespace llarp void Path::Tick(llarp_time_t now, llarp_router* r) { + if(Expired(now)) + return; auto dlt = now - m_LastLatencyTestTime; if(dlt > 5000 && m_LastLatencyTestID == 0) { @@ -404,6 +412,8 @@ namespace llarp // make nonce TunnelNonce N; N.Randomize(); + llarp::LogInfo("send ", buf.sz, " bytes via ", TXID(), " on ", Upstream(), + " to ", Endpoint()); return HandleUpstream(buf, N, r); } @@ -446,14 +456,19 @@ namespace llarp Path::HandlePathLatencyMessage( const llarp::routing::PathLatencyMessage* msg, llarp_router* r) { - if(msg->L == m_LastLatencyTestID) + if(msg->L == m_LastLatencyTestID && status == ePathEstablished) { intro.latency = llarp_time_now_ms() - m_LastLatencyTestTime; llarp::LogInfo("path latency is ", intro.latency, " ms for tx=", TXID(), " rx=", RXID()); m_LastLatencyTestID = 0; + return true; + } + else + { + llarp::LogWarn("unwarrented path latency message via ", Upstream()); + return false; } - return true; } bool diff --git a/llarp/pathset.cpp b/llarp/pathset.cpp index f890e6149..288c46ee6 100644 --- a/llarp/pathset.cpp +++ b/llarp/pathset.cpp @@ -51,8 +51,11 @@ namespace llarp auto itr = m_Paths.begin(); while(itr != m_Paths.end()) { - if(itr->first.first == id) - return itr->second; + if(itr->second->IsReady()) + { + if(itr->second->Endpoint() == id) + return itr->second; + } ++itr; } return nullptr; diff --git a/llarp/routing/path_transfer.cpp b/llarp/routing/path_transfer.cpp index 1a08922bc..a90b2d0c4 100644 --- a/llarp/routing/path_transfer.cpp +++ b/llarp/routing/path_transfer.cpp @@ -61,7 +61,7 @@ namespace llarp PathTransferMessage::HandleMessage(IMessageHandler* h, llarp_router* r) const { - auto path = r->paths.GetByDownstream(r->pubkey(), P); + auto path = r->paths.GetByUpstream(r->pubkey(), P); if(!path) { llarp::LogWarn("No such path for path transfer pathid=", P); @@ -84,6 +84,7 @@ namespace llarp buf.sz = buf.cur - buf.base; buf.cur = buf.base; // send + llarp::LogInfo("Transfer ", buf.sz, " bytes", " to ", P); return path->HandleDownstream(buf, Y, r); } diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 0b57369bf..a822b302b 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -91,6 +91,21 @@ namespace llarp llarp::LogWarn("failed to publish intro set for endpoint ", Name()); } } + // expire pending tx + { + auto itr = m_PendingLookups.begin(); + while(itr != m_PendingLookups.end()) + { + if(itr->second->IsTimedOut(now)) + { + itr->second->HandleResponse({}); + itr = m_PendingLookups.erase(itr); + } + else + ++itr; + } + } + // prefetch tags for(const auto& tag : m_PrefetchTags) { @@ -122,6 +137,21 @@ namespace llarp } } } + + // tick remote sessions + { + auto itr = m_RemoteSessions.begin(); + while(itr != m_RemoteSessions.end()) + { + if(itr->second->Tick(now)) + { + delete itr->second; + itr = m_RemoteSessions.erase(itr); + } + else + ++itr; + } + } } uint64_t @@ -306,6 +336,7 @@ namespace llarp uint64_t tx) : endpoint(parent), remote(addr), txid(tx) { + llarp::LogInfo("New hidden service lookup for ", addr.ToString()); } bool @@ -313,8 +344,15 @@ namespace llarp { if(results.size() == 1) { + llarp::LogInfo("hidden service lookup for ", remote.ToString(), + " success"); endpoint->PutNewOutboundContext(*results.begin()); } + else + { + llarp::LogInfo("no response in hidden service lookup for ", + remote.ToString()); + } delete this; return true; } @@ -355,6 +393,12 @@ namespace llarp Endpoint::EnsurePathToService(const Address& remote, PathEnsureHook hook, llarp_time_t timeoutMS) { + auto path = PickRandomEstablishedPath(); + if(!path) + { + llarp::LogWarn("No outbound path for lookup yet"); + return false; + } { auto itr = m_RemoteSessions.find(remote); if(itr != m_RemoteSessions.end()) @@ -369,11 +413,15 @@ namespace llarp // duplicate return false; } + llarp::LogInfo(Name(), " Ensure Path to ", remote.ToString()); + m_PendingServiceLookups.insert(std::make_pair(remote, hook)); + HiddenServiceAddressLookup* job = new HiddenServiceAddressLookup(this, remote, GenTXID()); m_PendingLookups.insert(std::make_pair(job->txid, job)); - return true; + + return job->SendRequestViaPath(path, Router()); } Endpoint::OutboundContext::OutboundContext(const IntroSet& intro, @@ -385,6 +433,7 @@ namespace llarp { selectedIntro.Clear(); + ShiftIntroduction(); } Endpoint::OutboundContext::~OutboundContext() @@ -506,6 +555,15 @@ namespace llarp Endpoint::OutboundContext::Send(ProtocolFrame& msg) { // in this context we assume the message contents are encrypted + auto now = llarp_time_now_ms(); + if(currentIntroSet.HasExpiredIntros(now)) + { + UpdateIntroSet(); + } + if(selectedIntro.expiresAt <= now || now - selectedIntro.expiresAt > 1000) + { + ShiftIntroduction(); + } auto path = GetPathByRouter(selectedIntro.router); if(path) { @@ -513,8 +571,45 @@ namespace llarp transfer.T = &msg; transfer.Y.Randomize(); transfer.P = selectedIntro.pathID; + llarp::LogInfo("sending frame via ", path->Upstream(), " to ", + path->Endpoint()); path->SendRoutingMessage(&transfer, m_Parent->Router()); } + else + { + llarp::LogWarn("No path to ", selectedIntro.router); + } + } + + void + Endpoint::OutboundContext::UpdateIntroSet() + { + auto path = PickRandomEstablishedPath(); + if(path) + { + uint64_t txid = llarp_randint(); + routing::DHTMessage msg; + msg.M.push_back( + new llarp::dht::FindIntroMessage(currentIntroSet.A.Addr(), txid)); + path->SendRoutingMessage(&msg, m_Parent->Router()); + } + else + { + llarp::LogWarn( + "Cannot update introset no path for outbound session to ", + currentIntroSet.A.Addr().ToString()); + } + } + + bool + Endpoint::OutboundContext::Tick(llarp_time_t now) + { + if(selectedIntro.expiresAt >= now || selectedIntro.expiresAt - now < 5000) + { + UpdateIntroSet(); + } + // TODO: check for expiration + return false; } bool @@ -522,20 +617,10 @@ namespace llarp llarp_rc* cur, size_t hop) { // TODO: don't hard code + llarp::LogInfo("Select hop ", hop); if(hop == 3) { - llarp_time_t lowest = 0xFFFFFFFFFFFFFFFFUL; - Introduction chosen; - // pick intro set with lowest latency - for(const auto& intro : currentIntroSet.I) - { - if(intro.latency < lowest) - { - chosen = intro; - lowest = intro.latency; - } - } - auto localcopy = llarp_nodedb_get_rc(db, chosen.router); + auto localcopy = llarp_nodedb_get_rc(db, selectedIntro.router); if(localcopy) { llarp_rc_copy(cur, localcopy); @@ -546,7 +631,7 @@ namespace llarp // we don't have it? llarp::LogError( "cannot build aligned path, don't have router for introduction ", - chosen); + selectedIntro); return false; } } diff --git a/llarp/service/frame.cpp b/llarp/service/frame.cpp deleted file mode 100644 index ad042f728..000000000 --- a/llarp/service/frame.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include - -namespace llarp -{ - namespace service - { - } -} // namespace llarp \ No newline at end of file diff --git a/llarp/service/protocol.cpp b/llarp/service/protocol.cpp index 61c9735f0..9711a241b 100644 --- a/llarp/service/protocol.cpp +++ b/llarp/service/protocol.cpp @@ -1,3 +1,4 @@ +#include #include #include "buffer.hpp" @@ -132,5 +133,13 @@ namespace llarp return result; } + bool + ProtocolFrame::HandleMessage(llarp::routing::IMessageHandler* h, + llarp_router* r) const + { + llarp::LogInfo("Got hidden service frame"); + return h->HandleHiddenServiceFrame(this); + } + } // namespace service } // namespace llarp \ No newline at end of file diff --git a/llarp/transit_hop.cpp b/llarp/transit_hop.cpp index 4c526c5da..bf48d1c21 100644 --- a/llarp/transit_hop.cpp +++ b/llarp/transit_hop.cpp @@ -59,6 +59,8 @@ namespace llarp // rewind buf.sz = buf.cur - buf.base; buf.cur = buf.base; + llarp::LogInfo("Send ", buf.sz, + " bytes routing message from trasnit hop"); return HandleDownstream(buf, N, r); }