diff --git a/docs/wire-protocol.txt b/docs/wire-protocol.txt index 489eb9759..d3756bf21 100644 --- a/docs/wire-protocol.txt +++ b/docs/wire-protocol.txt @@ -5,18 +5,22 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119]. -LLARP supports by default an authenticated message transport over a -datagram based network layer. +LLARP's wire protocol is Internet Wire Protocol (IWP) +The main goal of iwp is to provide an authenticated encrypted +reliable semi-ordered durable datagram transfer protocol supporting +datagrams of larger size than link mtu. -protocol phases: +in iwp there is an initiator who initiates a session to a recipiant. -first phase: proof of flow -second phase: session handshake -thrid phase: data transmission +iwp has 3 phases. the first phase is the proof of flow phase. +the second is a session handshake phase, the third is data transmission. proof of flow: +the purpose of the proof of flow phase is to verify the existence +of the initiator's endpoint. + At any time before the data transfer phase a reject message is sent the session is reset. diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index a02eb5223..dc2c857d8 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -287,34 +287,31 @@ namespace llarp void Router::PersistSessionUntil(const RouterID &remote, llarp_time_t until) { - LogDebug("persist session to ", remote, " until ", until); m_PersistingSessions[remote] = std::max(until, m_PersistingSessions[remote]); + LogDebug("persist session to ", remote, " until ", + m_PersistingSessions[remote]); } bool Router::GetRandomGoodRouter(RouterID &router) { - if(whitelistRouters) - { - const auto sz = lokinetRouters.size(); - auto itr = lokinetRouters.begin(); + auto pick_router = [&](auto &collection) -> bool { + const auto sz = collection.size(); + auto itr = collection.begin(); if(sz == 0) return false; if(sz > 1) std::advance(itr, randint() % sz); router = itr->first; return true; + }; + if(whitelistRouters) + { + pick_router(lokinetRouters); } absl::ReaderMutexLock l(&nodedb()->access); - auto sz = nodedb()->entries.size(); - if(sz == 0) - return false; - auto itr = nodedb()->entries.begin(); - if(sz > 1) - std::advance(itr, randint() % sz); - router = itr->first; - return true; + return pick_router(nodedb()->entries); } void