Skip to content

Commit de1d29b

Browse files
committed
move stuff into details namespace
1 parent d143355 commit de1d29b

File tree

14 files changed

+137
-68
lines changed

14 files changed

+137
-68
lines changed

include/scl/primitives/digest.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,12 @@ namespace scl {
2828

2929
/**
3030
* @brief A digest of some bitsize.
31-
* @tparam Bits the bitsize of the digest
32-
*
33-
* This type is effectively <code>std::array<unsigned char, N / 8</code>.
3431
*/
3532
template <std::size_t BITS>
3633
using Digest = std::array<unsigned char, BITS / 8>;
3734

3835
/**
39-
* @brief Convert a digest to a string.
40-
* @param digest the digest
41-
* @return a hex representation of the digest.
36+
* @brief Convert a digest to a hex string.
4237
*/
4338
template <typename DIGEST>
4439
std::string digestToString(const DIGEST& digest) {

include/scl/simulation/channel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "scl/simulation/context.h"
2525
#include "scl/simulation/transport.h"
2626

27-
namespace scl {
27+
namespace scl::details {
2828

2929
class SimulatedChannel final : public Channel {
3030
public:
@@ -52,6 +52,6 @@ class SimulatedChannel final : public Channel {
5252
std::shared_ptr<Transport> m_transport;
5353
};
5454

55-
} // namespace scl
55+
} // namespace scl::details
5656

5757
#endif // SCL_SIMULATION_CHANNEL_H

include/scl/simulation/channel_id.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ struct ChannelId final {
3939

4040
} // namespace scl
4141

42-
/**
43-
* @brief x
44-
*/
42+
/// @cond
43+
4544
template <>
4645
struct std::hash<scl::ChannelId> {
4746
std::size_t operator()(const scl::ChannelId& channel_id) const {
4847
return channel_id.local ^ (channel_id.remote << 32);
4948
}
5049
};
5150

51+
/// @endcond
52+
5253
#endif // SCL_SIMULATION_CHANNEL_ID_H

include/scl/simulation/context.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "scl/simulation/network_description.h"
2626
#include "scl/simulation/simulator.h"
2727

28-
namespace scl {
28+
namespace scl::details {
2929

3030
class Context;
3131

@@ -34,6 +34,9 @@ class Context;
3434
*/
3535
class SimulatorContext final {
3636
public:
37+
/**
38+
* @brief Create a new simulation context object.
39+
*/
3740
static SimulatorContext create(
3841
NetworkDescription network_desc,
3942
std::vector<Simulator::SimulationHook>&& hooks);
@@ -43,6 +46,9 @@ class SimulatorContext final {
4346
*/
4447
Context getContext(std::size_t id);
4548

49+
/**
50+
* @brief Add an event to
51+
*/
4652
template <typename EVENT, typename... ARGS>
4753
requires(std::is_base_of_v<Event, EVENT>)
4854
void addEvent(std::size_t pid, ARGS... args) {
@@ -125,6 +131,6 @@ inline Context SimulatorContext::getContext(std::size_t id) {
125131
return Context{*this, id};
126132
}
127133

128-
} // namespace scl
134+
} // namespace scl::details
129135

130136
#endif // SCL_SIMULATION_CONTEXT_H

include/scl/simulation/network_description.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,76 @@
2626

2727
namespace scl {
2828

29+
/**
30+
* @brief Describes the characterists of a channel.
31+
*/
2932
struct ChannelDescription final {
33+
/**
34+
* @brief The channel bandwidth, in bits/s.
35+
*/
3036
std::size_t bandwith;
37+
38+
/**
39+
* @brief The channel latency, in microseconds.
40+
*/
3141
std::size_t latency;
42+
43+
/**
44+
* @brief The latency variance, in microseconds.
45+
*/
3246
std::size_t latency_jitter;
47+
48+
/**
49+
* @brief The channel package loss, a value in [0, 1).
50+
*/
3351
float loss;
3452
};
3553

54+
/**
55+
* @brief Describes a network in terms of its channels.
56+
*/
3657
class NetworkDescription final {
3758
public:
59+
/**
60+
* @brief The parameters of a channel at a given point in time.
61+
*/
3862
struct ChannelParameters {
63+
/**
64+
* @brief The current channel bandwidth.
65+
*/
3966
std::size_t bandwidth;
67+
68+
/**
69+
* @brief The current channel latency.
70+
*/
4071
std::size_t latency;
72+
73+
/**
74+
* @brief The current channel packege loss.
75+
*/
4176
float loss;
4277
};
4378

79+
/**
80+
* @brief Create a default LAN network.
81+
*/
4482
static NetworkDescription createDefaultLAN(std::size_t size);
83+
84+
/**
85+
* @brief Create a default WAN network.
86+
*/
4587
static NetworkDescription createDefaultWAN(std::size_t size);
4688

89+
/**
90+
* @brief The size of the network.
91+
*/
4792
std::size_t size() const {
4893
return m_size;
4994
}
5095

96+
/**
97+
* @brief Get the parameters of a particular channel.
98+
*/
5199
ChannelParameters getChannel(ChannelId id);
52100

53101
private:

include/scl/simulation/runtime.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "scl/coro/runtime.h"
2424
#include "scl/simulation/context.h"
2525

26-
namespace scl {
26+
namespace scl::details {
2727

2828
class SimulatorRuntime final : public Runtime {
2929
private:
@@ -60,6 +60,6 @@ class SimulatorRuntime final : public Runtime {
6060
std::list<Coro> m_tq;
6161
};
6262

63-
} // namespace scl
63+
} // namespace scl::details
6464

6565
#endif // SCL_SIMULATION_RUNTIME_H

include/scl/simulation/transport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "scl/simulation/context.h"
2727
#include "scl/time.h"
2828

29-
namespace scl {
29+
namespace scl::details {
3030

3131
class Transport {
3232
public:
@@ -49,6 +49,6 @@ class Transport {
4949
m_pqs;
5050
};
5151

52-
} // namespace scl
52+
} // namespace scl::details
5353

5454
#endif // SCL_SIMULATION_TRANSPORT_H

include/scl/time.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ inline long double timeToMillis(Time::Duration time) {
5353
return duration<long double, std::milli>(time).count();
5454
}
5555

56+
/**
57+
* @brief Clock interface.
58+
*
59+
* Clock is used within protocols to get the time elapsed since the protocol was
60+
* first started. The reason for requiring an interface to get this information
61+
* is because protocols might be run in a simulation, in which case wall-clock
62+
* time wouldn't be accurate.
63+
*/
5664
struct Clock {
5765
virtual ~Clock();
66+
67+
/**
68+
* @brief Read the value of the clock.
69+
*/
5870
virtual Time::Duration read() const = 0;
5971
};
6072

src/scl/simulation/channel.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
#include "scl/simulation/transport.h"
2323
#include "scl/time.h"
2424

25-
void scl::SimulatedChannel::close() {
25+
void scl::details::SimulatedChannel::close() {
2626
m_ctx.addEvent<scl::CloseEvent>(m_ctx.elapsedTime(), m_id);
2727
}
2828

29-
scl::Task<void> scl::SimulatedChannel::send(Packet&& packet) {
29+
scl::Task<void> scl::details::SimulatedChannel::send(Packet&& packet) {
3030
const auto et = m_ctx.elapsedTime();
3131
m_ctx.addEvent<SendEvent>(et, m_id, packet.size());
3232
m_transport->send(et, m_id, std::move(packet));
3333
co_return;
3434
}
3535

36-
scl::Task<void> scl::SimulatedChannel::send(const Packet& packet) {
36+
scl::Task<void> scl::details::SimulatedChannel::send(const Packet& packet) {
3737
const auto et = m_ctx.elapsedTime();
3838
m_ctx.addEvent<SendEvent>(et, m_id, packet.size());
3939
m_transport->send(et, m_id, packet);
@@ -71,10 +71,10 @@ class RecvPendingEvent final : public scl::ChannelEvent {
7171

7272
// Awaitable that checks if the transport is ready.
7373
struct ReadyChecker {
74-
scl::Transport* transport;
74+
scl::details::Transport* transport;
7575
scl::ChannelId id;
7676
RecvPendingEvent* event;
77-
scl::Context& ctx;
77+
scl::details::Context& ctx;
7878

7979
bool operator()() {
8080
const auto is_ready = transport->ready(id);
@@ -91,7 +91,7 @@ struct ReadyChecker {
9191

9292
} // namespace
9393

94-
scl::Task<scl::Packet> scl::SimulatedChannel::recv() {
94+
scl::Task<scl::Packet> scl::details::SimulatedChannel::recv() {
9595
const auto et = m_ctx.elapsedTime();
9696

9797
m_ctx.addEvent<RecvPendingEvent>(et, m_id);
@@ -111,10 +111,10 @@ namespace {
111111

112112
// Ready checker which capable of timing out
113113
struct TimeoutReadyChecker {
114-
scl::Transport* transport;
114+
scl::details::Transport* transport;
115115
scl::ChannelId id;
116116
RecvPendingEvent* event;
117-
scl::Context& ctx;
117+
scl::details::Context& ctx;
118118
scl::Time::Duration timeout_rem;
119119

120120
bool operator()() {
@@ -135,7 +135,7 @@ struct TimeoutReadyChecker {
135135

136136
} // namespace
137137

138-
scl::Task<std::optional<scl::Packet>> scl::SimulatedChannel::recv(
138+
scl::Task<std::optional<scl::Packet>> scl::details::SimulatedChannel::recv(
139139
Time::Duration timeout) {
140140
// const auto et = m_ctx.elapsedTime();
141141

@@ -149,7 +149,7 @@ scl::Task<std::optional<scl::Packet>> scl::SimulatedChannel::recv(
149149
co_return {};
150150
}
151151

152-
scl::Task<bool> scl::SimulatedChannel::poll() {
152+
scl::Task<bool> scl::details::SimulatedChannel::poll() {
153153
const auto et = m_ctx.elapsedTime();
154154
Transport::PollResult pr;
155155

src/scl/simulation/context.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
#include "scl/simulation/event.h"
2121

22-
using namespace scl;
23-
24-
SimulatorContext SimulatorContext::create(
22+
scl::details::SimulatorContext scl::details::SimulatorContext::create(
2523
NetworkDescription network_desc,
2624
std::vector<Simulator::SimulationHook>&& hooks) {
2725
SimulatorContext ctx{network_desc};
@@ -33,7 +31,7 @@ SimulatorContext SimulatorContext::create(
3331
return ctx;
3432
}
3533

36-
void SimulatorContext::runHooks(std::size_t pid, Event* event) {
34+
void scl::details::SimulatorContext::runHooks(std::size_t pid, Event* event) {
3735
for (auto& [trigger, hook] : m_hooks) {
3836
// if the trigger was specified, then the hook is only run if the current
3937
// event matches the trigger type.

0 commit comments

Comments
 (0)