Remove some .cpp files related to RouterEvents

The motivation is to reduce the raw amount of code required to create
and maintain events.
pull/1167/head
Stephen Shelton 4 years ago
parent 4c6be3c8d1
commit 8a12da8bd5
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

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

@ -1,62 +0,0 @@
#include "dht_event.hpp"
#include "service/intro_set.hpp"
namespace tooling
{
PubIntroReceivedEvent::PubIntroReceivedEvent(
const llarp::RouterID& ourRouter, const llarp::dht::Key_t& from,
const llarp::dht::Key_t& location, uint64_t txid, uint64_t relayOrder)
: RouterEvent("DHT: PubIntroReceivedEvent", ourRouter, true)
, From(from)
, IntrosetLocation(location)
, RelayOrder(relayOrder)
, TxID(txid)
{
}
PubIntroSentEvent::PubIntroSentEvent(const llarp::RouterID& ourRouter,
const llarp::dht::Key_t& introsetPubkey,
const llarp::RouterID& relay,
uint64_t relayIndex)
: RouterEvent("DHT: PubIntroSentEvent", ourRouter, false)
, introsetPubkey(introsetPubkey)
, relay(relay)
, relayIndex(relayIndex)
{
}
std::string
PubIntroSentEvent::ToString() const
{
return RouterEvent::ToString() + " ---- introset pubkey: "
+ introsetPubkey.ShortHex() + ", relay: " + relay.ShortString()
+ ", relayIndex: " + std::to_string(relayIndex);
}
std::string
PubIntroReceivedEvent::ToString() const
{
return RouterEvent::ToString() + "from " + From.ShortHex() + " location="
+ IntrosetLocation.ShortHex() + " order=" + std::to_string(RelayOrder)
+ " txid=" + std::to_string(TxID);
}
GotIntroReceivedEvent::GotIntroReceivedEvent(
const llarp::RouterID& ourRouter_, const llarp::dht::Key_t& from_,
const llarp::service::EncryptedIntroSet& introset_, uint64_t txid_)
: RouterEvent("DHT:: GotIntroReceivedEvent", ourRouter_, true)
, From(from_)
, Introset(introset_)
, TxID(txid_)
{
}
std::string
GotIntroReceivedEvent::ToString() const
{
return RouterEvent::ToString() + "from " + From.ShortHex()
+ " location=" + Introset.derivedSigningKey.ShortHex() + " order="
+ std::to_string(RelayOrder) + " txid=" + std::to_string(TxID);
}
} // namespace tooling

@ -9,51 +9,87 @@ namespace tooling
{
struct PubIntroSentEvent : public RouterEvent
{
PubIntroSentEvent(const llarp::RouterID& ourRouter,
const llarp::dht::Key_t& introsetPubkey,
const llarp::RouterID& relay, uint64_t relayIndex);
llarp::dht::Key_t introsetPubkey;
llarp::RouterID relay;
uint64_t relayIndex;
PubIntroSentEvent(
const llarp::RouterID& ourRouter,
const llarp::dht::Key_t& introsetPubkey_,
const llarp::RouterID& relay_,
uint64_t relayIndex_)
: RouterEvent("DHT: PubIntroSentEvent", ourRouter, false)
, introsetPubkey(introsetPubkey_)
, relay(relay_)
, relayIndex(relayIndex_)
{
}
std::string
ToString() const override;
ToString() const
{
return RouterEvent::ToString() + " ---- introset pubkey: "
+ introsetPubkey.ShortHex() + ", relay: " + relay.ShortString()
+ ", relayIndex: " + std::to_string(relayIndex);
}
};
struct PubIntroReceivedEvent : public RouterEvent
{
PubIntroReceivedEvent(const llarp::RouterID& ourRouter,
const llarp::dht::Key_t& from,
const llarp::dht::Key_t& location, uint64_t txid,
uint64_t relayOrder);
llarp::dht::Key_t from;
llarp::dht::Key_t location;
uint64_t txid;
uint64_t relayOrder;
PubIntroReceivedEvent(
const llarp::RouterID& ourRouter,
const llarp::dht::Key_t& from_,
const llarp::dht::Key_t& location_,
uint64_t txid_,
uint64_t relayOrder_)
: RouterEvent("DHT: PubIntroReceivedEvent", ourRouter, true)
, from(from_)
, location(location_)
, txid(txid_)
, relayOrder(relayOrder_)
{
}
llarp::dht::Key_t From;
llarp::dht::Key_t IntrosetLocation;
uint64_t RelayOrder;
uint64_t TxID;
std::string
ToString() const override;
ToString() const override
{
return RouterEvent::ToString() + "from " + from.ShortHex() + " location="
+ location.ShortHex() + " order=" + std::to_string(relayOrder)
+ " txid=" + std::to_string(txid);
}
};
struct GotIntroReceivedEvent : public RouterEvent
{
// TODO: thought: why not just use the original message object here?
// TODO: question: what ties this to the actual logic that knows an event
// occurred?
GotIntroReceivedEvent(const llarp::RouterID& ourRouter,
const llarp::dht::Key_t& from,
const llarp::service::EncryptedIntroSet& introset,
uint64_t txid);
llarp::dht::Key_t From;
llarp::service::EncryptedIntroSet Introset;
uint64_t RelayOrder;
uint64_t TxID;
GotIntroReceivedEvent(
const llarp::RouterID& ourRouter_,
const llarp::dht::Key_t& from_,
const llarp::service::EncryptedIntroSet& introset_,
uint64_t txid_)
: RouterEvent("DHT:: GotIntroReceivedEvent", ourRouter_, true)
, From(from_)
, Introset(introset_)
, TxID(txid_)
{
}
std::string
ToString() const override;
ToString() const override
{
return RouterEvent::ToString() + "from " + From.ShortHex()
+ " location=" + Introset.derivedSigningKey.ShortHex() + " order="
+ std::to_string(RelayOrder) + " txid=" + std::to_string(TxID);
}
};
struct FindRouterEvent : public RouterEvent
@ -66,15 +102,15 @@ namespace tooling
uint64_t version;
FindRouterEvent(
const llarp::RouterID& ourRouter,
const llarp::dht::FindRouterMessage& msg)
: RouterEvent("DHT: FindRouterEvent", ourRouter, true)
, from(msg.From)
, targetKey(msg.targetKey)
, iterative(msg.iterative)
, exploritory(msg.exploritory)
, txid(msg.txid)
, version(msg.version)
const llarp::RouterID& ourRouter,
const llarp::dht::FindRouterMessage& msg)
: RouterEvent("DHT: FindRouterEvent", ourRouter, true)
, from(msg.From)
, targetKey(msg.targetKey)
, iterative(msg.iterative)
, exploritory(msg.exploritory)
, txid(msg.txid)
, version(msg.version)
{
}

@ -1,118 +0,0 @@
#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;
}
PathBuildRejectedEvent::PathBuildRejectedEvent(
const llarp::RouterID& routerID,
const llarp::PathID_t rxid_,
const llarp::RouterID& rejectedBy_)
: RouterEvent("PathBuildRejectedEvent", routerID, false)
, rxid(rxid_)
, rejectedBy(rejectedBy_)
{
}
std::string
PathBuildRejectedEvent::ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- path rxid: " + rxid.ShortHex();
result += ", rejectedBy: " + rejectedBy.ShortString();
return result;
}
} // namespace tooling

@ -1,65 +1,147 @@
#include "router_event.hpp"
#include <path/path_types.hpp>
#include <path/path.hpp>
#include <path/transit_hop.hpp>
namespace tooling
{
struct PathAttemptEvent : public RouterEvent
{
PathAttemptEvent(const llarp::RouterID& routerID,
std::shared_ptr< const llarp::path::Path > path);
std::vector< llarp::path::PathHopConfig > hops;
llarp::PathID_t pathid;
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
ToString() const override;
ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- [";
std::vector< llarp::path::PathHopConfig > hops;
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;
}
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);
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(routerID == nextHop ? true : false)
{
}
std::string
ToString() const override;
llarp::PathID_t rxid;
std::string
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;
}
uint64_t status;
};
struct PathBuildRejectedEvent : public RouterEvent
struct PathStatusReceivedEvent : public RouterEvent
{
PathBuildRejectedEvent(const llarp::RouterID& routerID,
const llarp::PathID_t rxid,
const llarp::RouterID& rejectedBy);
llarp::PathID_t rxid;
uint64_t status;
PathStatusReceivedEvent(
const llarp::RouterID& routerID,
const llarp::PathID_t rxid_,
uint64_t status_)
: RouterEvent("PathStatusReceivedEvent", routerID, true)
, rxid(rxid_)
, status(status_)
{
}
std::string
ToString() const override;
ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- path rxid: " + rxid.ShortHex();
result += ", status: " + std::to_string(status);
return result;
}
};
struct PathBuildRejectedEvent : public RouterEvent
{
llarp::PathID_t rxid;
llarp::RouterID rejectedBy;
PathBuildRejectedEvent(
const llarp::RouterID& routerID,
const llarp::PathID_t rxid_,
const llarp::RouterID& rejectedBy_)
: RouterEvent("PathBuildRejectedEvent", routerID, false)
, rxid(rxid_)
, rejectedBy(rejectedBy_)
{
}
std::string
ToString() const
{
std::string result = RouterEvent::ToString();
result += "---- path rxid: " + rxid.ShortHex();
result += ", rejectedBy: " + rejectedBy.ShortString();
return result;
}
};
} // namespace tooling

@ -1,43 +0,0 @@
#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();
}
RCGossipSentEvent::RCGossipSentEvent(const llarp::RouterID& routerID,
const llarp::RouterContact& rc)
: RouterEvent("RCGossipSentEvent", routerID, true), rc(rc)
{
}
std::string
RCGossipSentEvent::ToString() const
{
return RouterEvent::ToString() + " ---- sending RC for RouterID: "
+ llarp::RouterID(rc.pubkey).ShortString();
}
std::string
RCGossipSentEvent::LongString() const
{
return RouterEvent::ToString() + " ---- RC: " + rc.ToString();
}
} // namespace tooling

@ -1,3 +1,5 @@
#pragma once
#include <tooling/router_event.hpp>
#include <router_contact.hpp>
@ -7,13 +9,23 @@ namespace tooling
struct RCGossipReceivedEvent : public RouterEvent
{
RCGossipReceivedEvent(const llarp::RouterID& routerID,
const llarp::RouterContact& rc);
const llarp::RouterContact& rc_)
: RouterEvent("RCGossipReceivedEvent", routerID, true), rc(rc_)
{
}
std::string
ToString() const override;
ToString() const override
{
return RouterEvent::ToString()
+ " ---- other RouterID: " + llarp::RouterID(rc.pubkey).ShortString();
}
std::string
LongString() const;
LongString() const
{
return RouterEvent::ToString() + " ---- RC: " + rc.ToString();
}
llarp::RouterContact rc;
};
@ -21,13 +33,23 @@ namespace tooling
struct RCGossipSentEvent : public RouterEvent
{
RCGossipSentEvent(const llarp::RouterID& routerID,
const llarp::RouterContact& rc);
const llarp::RouterContact& rc_)
: RouterEvent("RCGossipSentEvent", routerID, true), rc(rc_)
{
}
std::string
ToString() const override;
ToString() const override
{
return RouterEvent::ToString() + " ---- sending RC for RouterID: "
+ llarp::RouterID(rc.pubkey).ShortString();
}
std::string
LongString() const;
LongString() const
{
return RouterEvent::ToString() + " ---- RC: " + rc.ToString();
}
llarp::RouterContact rc;
};

@ -1,22 +0,0 @@
#include <tooling/router_event.hpp>
namespace tooling
{
RouterEvent::RouterEvent(std::string eventType, llarp::RouterID routerID,
bool triggered)
: eventType(eventType), routerID(routerID), triggered(triggered)
{
}
std::string
RouterEvent::ToString() const
{
std::string result;
result += eventType;
result += " [";
result += routerID.ShortString();
result += "] -- ";
return result;
}
} // namespace tooling

@ -28,12 +28,23 @@ namespace tooling
struct RouterEvent
{
RouterEvent(std::string eventType, llarp::RouterID routerID,
bool triggered);
bool triggered)
: eventType(eventType), routerID(routerID), triggered(triggered)
{
}
virtual ~RouterEvent() = default;
virtual std::string
ToString() const;
ToString() const
{
std::string result;
result += eventType;
result += " [";
result += routerID.ShortString();
result += "] -- ";
return result;
}
const std::string eventType;

@ -47,10 +47,10 @@ namespace tooling
py::class_< PubIntroReceivedEvent, RouterEvent >(mod,
"DhtPubIntroReceivedEvent")
.def_readonly("from", &PubIntroReceivedEvent::From)
.def_readonly("location", &PubIntroReceivedEvent::IntrosetLocation)
.def_readonly("relayOrder", &PubIntroReceivedEvent::RelayOrder)
.def_readonly("txid", &PubIntroReceivedEvent::TxID);
.def_readonly("from", &PubIntroReceivedEvent::from)
.def_readonly("location", &PubIntroReceivedEvent::location)
.def_readonly("relayOrder", &PubIntroReceivedEvent::relayOrder)
.def_readonly("txid", &PubIntroReceivedEvent::txid);
py::class_< GotIntroReceivedEvent, RouterEvent >(mod,
"DhtGotIntroReceivedEvent")

Loading…
Cancel
Save