xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
server
detail
BasePeer.h
1
#pragma once
2
3
#include <xrpl/beast/utility/Journal.h>
4
#include <xrpl/beast/utility/WrappedSink.h>
5
#include <xrpl/server/Port.h>
6
#include <xrpl/server/detail/LowestLayer.h>
7
#include <xrpl/server/detail/io_list.h>
8
9
#include <boost/asio.hpp>
10
11
#include <
atomic
>
12
#include <
chrono
>
13
#include <
string
>
14
#include <
utility
>
15
16
namespace
xrpl
{
17
18
// Common part of all peers
19
template
<
class
Handler,
class
Impl>
20
class
BasePeer
:
public
IOList::Work
21
{
22
protected
:
23
using
ClockType
=
std::chrono::system_clock
;
24
using
ErrorCode
= boost::system::error_code;
25
using
EndpointType
= boost::asio::ip::tcp::endpoint;
26
using
WaitableTimer
= boost::asio::basic_waitable_timer<ClockType>;
27
28
Port
const
&
port_
;
29
Handler&
handler_
;
30
EndpointType
remoteAddress_
;
31
beast::WrappedSink
sink_
;
32
beast::Journal
const
j_
;
33
34
boost::asio::executor_work_guard<boost::asio::executor>
work_
;
35
boost::asio::strand<boost::asio::executor>
strand_
;
36
37
public
:
38
// NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
39
BasePeer
(
40
Port
const
& port,
41
Handler& handler,
42
boost::asio::executor
const
& executor,
43
EndpointType
remoteAddress,
44
beast::Journal
journal);
45
46
void
47
close
()
override
;
48
49
private
:
50
Impl&
51
impl
()
52
{
53
return
*
static_cast<
Impl*
>
(
this
);
54
}
55
};
56
57
//------------------------------------------------------------------------------
58
59
template
<
class
Handler,
class
Impl>
60
BasePeer<Handler, Impl>::BasePeer
(
61
Port
const
& port,
62
Handler& handler,
63
boost::asio::executor
const
& executor,
64
EndpointType
remoteAddress,
65
beast::Journal
journal)
66
:
port_
(port)
67
,
handler_
(handler)
68
,
remoteAddress_
(
std
::move(remoteAddress))
69
,
sink_
(
70
journal.sink(),
71
[] {
72
static
std::atomic<unsigned>
kID{0};
73
return
"##"
+
std::to_string
(++kID) +
" "
;
74
}())
75
, j_(sink_)
76
, work_(boost::asio::make_work_guard(executor))
77
, strand_(boost::asio::make_strand(executor))
78
{
79
}
80
81
template
<
class
Handler,
class
Impl>
82
void
83
BasePeer<Handler, Impl>::close
()
84
{
85
if
(!
strand_
.running_in_this_thread())
86
return
post(
strand_
, [self =
impl
().shared_from_this()] { self->close(); });
87
ErrorCode
ec;
88
xrpl::getLowestLayer
(
impl
().ws_).socket().close(ec);
89
}
90
91
}
// namespace xrpl
atomic
chrono
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::WrappedSink
Wraps a Journal::Sink to prefix its output with a string.
Definition
WrappedSink.h:19
xrpl::BasePeer::work_
boost::asio::executor_work_guard< boost::asio::executor > work_
Definition
BasePeer.h:34
xrpl::BasePeer::strand_
boost::asio::strand< boost::asio::executor > strand_
Definition
BasePeer.h:35
xrpl::BasePeer::port_
Port const & port_
Definition
BasePeer.h:28
xrpl::BasePeer::EndpointType
boost::asio::ip::tcp::endpoint EndpointType
Definition
BasePeer.h:25
xrpl::BasePeer::WaitableTimer
boost::asio::basic_waitable_timer< ClockType > WaitableTimer
Definition
BasePeer.h:26
xrpl::BasePeer::sink_
beast::WrappedSink sink_
Definition
BasePeer.h:31
xrpl::BasePeer::BasePeer
BasePeer(Port const &port, Handler &handler, boost::asio::executor const &executor, EndpointType remoteAddress, beast::Journal journal)
Definition
BasePeer.h:60
xrpl::BasePeer::ErrorCode
boost::system::error_code ErrorCode
Definition
BasePeer.h:24
xrpl::BasePeer::handler_
Handler & handler_
Definition
BasePeer.h:29
xrpl::BasePeer::impl
Impl & impl()
Definition
BasePeer.h:51
xrpl::BasePeer::remoteAddress_
EndpointType remoteAddress_
Definition
BasePeer.h:30
xrpl::BasePeer::j_
beast::Journal const j_
Definition
BasePeer.h:32
xrpl::BasePeer::ClockType
std::chrono::system_clock ClockType
Definition
BasePeer.h:23
xrpl::BasePeer::close
void close() override
Definition
BasePeer.h:83
xrpl::IOList::Work
Definition
io_list.h:22
std
STL namespace.
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::getLowestLayer
decltype(auto) getLowestLayer(T &t) noexcept
Definition
LowestLayer.h:9
string
xrpl::Port
Configuration information for a Server listening port.
Definition
Port.h:29
std::chrono::system_clock
std::to_string
T to_string(T... args)
utility
Generated by
1.17.0