xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
detail
WSInfoSub.h
1
#pragma once
2
3
#include <xrpld/rpc/Role.h>
4
5
#include <xrpl/beast/net/IPAddressConversion.h>
6
#include <xrpl/json/json_writer.h>
7
#include <xrpl/server/InfoSub.h>
8
#include <xrpl/server/WSSession.h>
9
10
#include <
cstddef
>
11
#include <
memory
>
12
#include <
string
>
13
#include <
string_view
>
14
#include <
utility
>
15
16
namespace
xrpl
{
17
18
class
WSInfoSub
:
public
InfoSub
19
{
20
std::weak_ptr<WSSession>
ws_
;
21
std::string
user_
;
22
std::string
fwdfor_
;
23
24
public
:
25
WSInfoSub
(
Source
& source,
std::shared_ptr<WSSession>
const
& ws) :
InfoSub
(source),
ws_
(ws)
26
{
27
auto
const
& h = ws->request();
28
if
(
ipAllowed
(
29
beast::IPAddressConversion::fromAsio
(ws->remoteEndpoint()).address(),
30
ws->port().secureGatewayNetsV4,
31
ws->port().secureGatewayNetsV6))
32
{
33
auto it = h.find(
"X-User"
);
34
if (it != h.end())
35
user_ = it->value();
36
fwdfor_ = std::string(::xrpl::forwardedFor(h));
37
}
38
}
39
40
[[nodiscard]]
std::string_view
41
user
()
const
42
{
43
return
user_
;
44
}
45
46
[[nodiscard]]
std::string_view
47
forwardedFor
()
const
48
{
49
return
fwdfor_
;
50
}
51
52
void
53
send
(
json::Value
const
& jv,
bool
)
override
54
{
55
auto
sp =
ws_
.lock();
56
if
(!sp)
57
return
;
58
boost::beast::multi_buffer sb;
59
json::stream
(jv, [&](
void
const
* data,
std::size_t
n) {
60
sb.commit(boost::asio::buffer_copy(sb.prepare(n), boost::asio::buffer(data, n)));
61
});
62
auto
m =
std::make_shared
<
StreambufWSMsg
<
decltype
(sb)>>(std::move(sb));
63
sp->send(m);
64
}
65
};
66
67
}
// namespace xrpl
std::string
std::string_view
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::InfoSub::Source
Abstracts the source of subscription data.
Definition
InfoSub.h:107
xrpl::InfoSub::InfoSub
InfoSub(Source &source)
Definition
libxrpl/server/InfoSub.cpp:76
xrpl::StreambufWSMsg
Definition
WSSession.h:55
xrpl::WSInfoSub::fwdfor_
std::string fwdfor_
Definition
WSInfoSub.h:22
xrpl::WSInfoSub::WSInfoSub
WSInfoSub(Source &source, std::shared_ptr< WSSession > const &ws)
Definition
WSInfoSub.h:25
xrpl::WSInfoSub::ws_
std::weak_ptr< WSSession > ws_
Definition
WSInfoSub.h:20
xrpl::WSInfoSub::user
std::string_view user() const
Definition
WSInfoSub.h:41
xrpl::WSInfoSub::user_
std::string user_
Definition
WSInfoSub.h:21
xrpl::WSInfoSub::forwardedFor
std::string_view forwardedFor() const
Definition
WSInfoSub.h:47
xrpl::WSInfoSub::send
void send(json::Value const &jv, bool) override
Definition
WSInfoSub.h:53
cstddef
std::make_shared
T make_shared(T... args)
memory
json::stream
void stream(json::Value const &jv, Write const &write)
Stream compact JSON to the specified function.
Definition
json_writer.h:285
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::ipAllowed
bool ipAllowed(beast::ip::Address const &remoteIp, std::vector< boost::asio::ip::network_v4 > const &nets4, std::vector< boost::asio::ip::network_v6 > const &nets6)
True if remoteIp is in any of adminIp.
Definition
Role.cpp:42
std::shared_ptr
std::size_t
string
string_view
beast::IPAddressConversion::fromAsio
static ip::Endpoint fromAsio(boost::asio::ip::address const &address)
Definition
IPAddressConversion.h:45
utility
std::weak_ptr
Generated by
1.17.0