some refactoring of tooling code, added RCGossipReceivedEvent

pull/1184/head
Thomas Winget 4 years ago
parent 912e4267e4
commit c8c66f0a5f

@ -198,8 +198,10 @@ set(LIB_SRC
service/session.cpp
service/tag_lookup_job.cpp
service/tag.cpp
tooling/dht_event.cpp
tooling/router_event.cpp
tooling/dht_event.cpp
tooling/path_event.cpp
tooling/rc_event.cpp
)
if(TRACY_ROOT)

@ -5,6 +5,7 @@
#include <path/path_context.hpp>
#include <router/abstractrouter.hpp>
#include <router/i_rc_lookup_handler.hpp>
#include <tooling/rc_event.hpp>
namespace llarp
{
@ -124,9 +125,12 @@ namespace llarp
{
if(not dht.GetRouter()->rcLookupHandler().CheckRC(rc))
return false;
if(txid == 0)
if(txid == 0) // txid == 0 on gossip
{
dht.GetRouter()->GossipRCIfNeeded(rc);
auto *router = dht.GetRouter();
tooling::RouterEventPtr event = std::make_unique<tooling::RCGossipReceivedEvent>(router->pubkey(), rc);
router->NotifyRouterEvent(std::move(event));
router->GossipRCIfNeeded(rc);
}
}
return true;

@ -13,7 +13,7 @@
#include <util/logging/logger.hpp>
#include <util/meta/memfn.hpp>
#include <util/thread/logic.hpp>
#include <tooling/router_event.hpp>
#include <tooling/path_event.hpp>
#include <functional>
#include <nonstd/optional.hpp>

@ -10,7 +10,7 @@
#include <util/logging/logger.hpp>
#include <util/meta/memfn.hpp>
#include <util/thread/logic.hpp>
#include <tooling/router_event.hpp>
#include <tooling/path_event.hpp>
#include <functional>
#include <utility>

@ -8,7 +8,7 @@
#include <router/abstractrouter.hpp>
#include <util/buffer.hpp>
#include <util/thread/logic.hpp>
#include <tooling/router_event.hpp>
#include <tooling/path_event.hpp>
#include <functional>

@ -29,7 +29,9 @@ namespace llarp
bool
RCGossiper::ShouldGossipOurRC(Time_t now) const
{
return now >= (m_LastGossipedOurRC + GossipOurRCInterval);
bool should = now >= (m_LastGossipedOurRC + GossipOurRCInterval);
LogWarn("ShouldGossipOurRC: ", should);
return should;
}
bool

@ -58,7 +58,11 @@ namespace llarp
, _dht(llarp_dht_context_new(this))
, inbound_link_msg_parser(this)
, _hiddenServiceContext(this)
#ifdef LOKINET_HIVE
, _randomStartDelay(std::chrono::milliseconds((llarp::randint() % 1250) + 1000))
#else
, _randomStartDelay(std::chrono::seconds((llarp::randint() % 30) + 10))
#endif
{
m_keyManager = std::make_shared< KeyManager >();

@ -116,6 +116,12 @@ namespace llarp
return ExtractStatus();
}
std::string
ToString() const
{
return ToJson().dump();
}
bool
BEncode(llarp_buffer_t *buf) const;

@ -0,0 +1,94 @@
#include <tooling/path_event.hpp>
#include <path/path.hpp>
#include <path/transit_hop.hpp>
namespace tooling
{
PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> path)
: RouterEvent("PathAttemptEvent", routerID, false)
, hops(path->hops)
, pathid(path->hops[0].rxID)
{
}
std::string
PathAttemptEvent::ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- [";
size_t i = 0;
for (const auto& hop : hops)
{
i++;
result += llarp::RouterID(hop.rc.pubkey).ShortString();
result += "]";
if (i != hops.size())
{
result += " -> [";
}
}
return result;
}
PathRequestReceivedEvent::PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::TransitHop> hop)
: RouterEvent("PathRequestReceivedEvent", routerID, true)
, prevHop(hop->info.downstream)
, nextHop(hop->info.upstream)
, txid(hop->info.txID)
, rxid(hop->info.rxID)
{
isEndpoint = false;
if (routerID == nextHop)
{
isEndpoint = true;
}
}
std::string
PathRequestReceivedEvent::ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- [";
result += prevHop.ShortString();
result += "] -> [*";
result += routerID.ShortString();
result += "] -> [";
if (isEndpoint)
{
result += "nowhere]";
}
else
{
result += nextHop.ShortString();
result += "]";
}
return result;
}
PathStatusReceivedEvent::PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status)
: RouterEvent("PathStatusReceivedEvent", routerID, true)
, rxid(rxid)
, status(status)
{
}
std::string
PathStatusReceivedEvent::ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- path rxid: " + rxid.ShortHex();
result += ", status: " + std::to_string(status);
return result;
}
} // namespace tooling

@ -0,0 +1,45 @@
#include "router_event.hpp"
#include <path/path_types.hpp>
namespace tooling
{
struct PathAttemptEvent : public RouterEvent
{
PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> path);
std::string ToString() const override;
std::vector<llarp::path::PathHopConfig> hops;
llarp::PathID_t pathid;
};
struct PathRequestReceivedEvent : public RouterEvent
{
PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::TransitHop> hop);
std::string ToString() const override;
llarp::RouterID prevHop;
llarp::RouterID nextHop;
llarp::PathID_t txid;
llarp::PathID_t rxid;
bool isEndpoint = false;
};
struct PathStatusReceivedEvent : public RouterEvent
{
PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status);
std::string ToString() const override;
llarp::PathID_t rxid;
uint64_t status;
};
} // namespace tooling

@ -0,0 +1,24 @@
#include <tooling/rc_event.hpp>
namespace tooling
{
RCGossipReceivedEvent::RCGossipReceivedEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc)
: RouterEvent("RCGossipReceivedEvent", routerID, true)
, rc(rc)
{
}
std::string
RCGossipReceivedEvent::ToString() const
{
return RouterEvent::ToString() + " ---- other RouterID: " + llarp::RouterID(rc.pubkey).ShortString();
}
std::string
RCGossipReceivedEvent::LongString() const
{
return RouterEvent::ToString() + " ---- RC: " + rc.ToString();
}
} // namespace tooling

@ -0,0 +1,21 @@
#include <tooling/router_event.hpp>
#include <router_contact.hpp>
namespace tooling
{
struct RCGossipReceivedEvent : public RouterEvent
{
RCGossipReceivedEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc);
std::string
ToString() const override;
std::string
LongString() const;
llarp::RouterContact rc;
};
} // namespace tooling

@ -1,8 +1,5 @@
#include <tooling/router_event.hpp>
#include <path/path.hpp>
#include <path/transit_hop.hpp>
namespace tooling
{
@ -22,89 +19,4 @@ namespace tooling
return result;
}
PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> path)
: RouterEvent("PathAttemptEvent", routerID, false)
, hops(path->hops)
, pathid(path->hops[0].rxID)
{
}
std::string
PathAttemptEvent::ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- [";
size_t i = 0;
for (const auto& hop : hops)
{
i++;
result += llarp::RouterID(hop.rc.pubkey).ShortString();
result += "]";
if (i != hops.size())
{
result += " -> [";
}
}
return result;
}
PathRequestReceivedEvent::PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::TransitHop> hop)
: RouterEvent("PathRequestReceivedEvent", routerID, true)
, prevHop(hop->info.downstream)
, nextHop(hop->info.upstream)
, txid(hop->info.txID)
, rxid(hop->info.rxID)
{
isEndpoint = false;
if (routerID == nextHop)
{
isEndpoint = true;
}
}
std::string
PathRequestReceivedEvent::ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- [";
result += prevHop.ShortString();
result += "] -> [*";
result += routerID.ShortString();
result += "] -> [";
if (isEndpoint)
{
result += "nowhere]";
}
else
{
result += nextHop.ShortString();
result += "]";
}
return result;
}
PathStatusReceivedEvent::PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status)
: RouterEvent("PathStatusReceivedEvent", routerID, true)
, rxid(rxid)
, status(status)
{
}
std::string
PathStatusReceivedEvent::ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- path rxid: " + rxid.ShortHex();
result += ", status: " + std::to_string(status);
return result;
}
} // namespace tooling

@ -1,7 +1,6 @@
#pragma once
#include <router_id.hpp>
#include <path/path_types.hpp>
#include <string>
#include <vector>
@ -46,42 +45,4 @@ namespace tooling
using RouterEventPtr = std::unique_ptr<RouterEvent>;
struct PathAttemptEvent : public RouterEvent
{
PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> path);
std::string ToString() const override;
std::vector<llarp::path::PathHopConfig> hops;
llarp::PathID_t pathid;
};
struct PathRequestReceivedEvent : public RouterEvent
{
PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::TransitHop> hop);
std::string ToString() const override;
llarp::RouterID prevHop;
llarp::RouterID nextHop;
llarp::PathID_t txid;
llarp::PathID_t rxid;
bool isEndpoint = false;
};
struct PathStatusReceivedEvent : public RouterEvent
{
PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status);
std::string ToString() const override;
llarp::PathID_t rxid;
uint64_t status;
};
} // namespace tooling

@ -13,9 +13,9 @@ namespace llarp
})
.def("ReadFile", &RouterContact::Read)
.def("WriteFile", &RouterContact::Write)
.def("ToString", [](const RouterContact* const rc) -> std::string {
return rc->ToJson().dump();
})
.def("ToString", &RouterContact::ToString)
.def("__str__", &RouterContact::ToString)
.def("__repr__", &RouterContact::ToString)
.def("Verify", [](const RouterContact* const rc) -> bool {
const llarp_time_t now = llarp::time_now_ms();
return rc->Verify(now);

@ -3,6 +3,8 @@
#include "tooling/router_event.hpp"
#include "tooling/dht_event.hpp"
#include "tooling/path_event.hpp"
#include "tooling/rc_event.hpp"
#include <messages/relay_status.hpp>
#include <path/path.hpp>
@ -46,6 +48,10 @@ namespace tooling
.def_readonly("location", &GotIntroReceivedEvent::Introset)
.def_readonly("relayOrder", &GotIntroReceivedEvent::RelayOrder)
.def_readonly("txid", &GotIntroReceivedEvent::TxID);
py::class_<RCGossipReceivedEvent, RouterEvent>(mod, "RCGossipReceivedEvent")
.def_readonly("rc", &RCGossipReceivedEvent::rc)
.def("LongString", &RCGossipReceivedEvent::LongString);
}
} // namespace tooling

@ -1,10 +1,11 @@
if (WITH_HIVE)
add_custom_target(hive_build DEPENDS ${STATIC_LIB} pyllarp)
add_custom_target(hive ${CMAKE_COMMAND} -E
env PYTHONPATH="$ENV{PYTHONPATH}:${CMAKE_BINARY_DIR}/pybind"
${PYTHON_EXECUTABLE} -m pytest
${CMAKE_CURRENT_SOURCE_DIR}/hive
DEPENDS
${STATIC_LIB} pyllarp)
hive_build)
endif()
set(GTEST_EXE testAll)

@ -3,10 +3,33 @@ import hive
import pytest
@pytest.fixture(scope="session")
def HiveTenTen():
def HiveTenRTenC():
router_hive = hive.RouterHive(n_relays=10, n_clients=10, netid="hive")
router_hive.Start()
yield router_hive
router_hive.Stop()
@pytest.fixture(scope="session")
def HiveThirtyRTenC():
router_hive = hive.RouterHive(n_relays=30, n_clients=10, netid="hive")
router_hive.Start()
yield router_hive
router_hive.Stop()
@pytest.fixture()
def HiveArbitrary():
router_hive = None
def _make(n_relays=10, n_clients=10, netid="hive"):
nonlocal router_hive
router_hive = hive.RouterHive(n_relays=30, n_clients=10, netid="hive")
router_hive.Start()
return router_hive
yield _make
router_hive.Stop()

@ -161,15 +161,15 @@ class RouterHive(object):
print("Starting relays")
self.hive.StartRelays()
sleep(1)
sleep(0.2)
self.hive.ForEachRelay(lambda r: self.MakeEndpoint(r, self.onGotEndpoint))
print("Sleeping 5 seconds before starting clients")
sleep(5)
print("Sleeping 1 seconds before starting clients")
sleep(1)
self.hive.StartClients()
sleep(1)
sleep(0.2)
self.hive.ForEachClient(lambda r: self.MakeEndpoint(r, self.onGotEndpoint))
def Stop(self):
@ -241,4 +241,4 @@ if __name__ == '__main__':
print_events = False
parser.add_argument('--print-events', dest="print_events", action='store_true')
args = parser.parse_args()
main(print_each_event = args.print_events)
main(n_relays=30, print_each_event = args.print_events)

@ -1,11 +1,11 @@
from time import time
def test_path_builds(HiveTenTen):
h = HiveTenTen
def test_path_builds(HiveArbitrary):
h = HiveArbitrary(n_relays=30, n_clients=10)
start_time = time()
cur_time = start_time
test_duration = 10 #seconds
test_duration = 5 #seconds
log_attempts = True

Loading…
Cancel
Save