 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
5 #ifndef BITCOIN_TEST_UTIL_NET_H
6 #define BITCOIN_TEST_UTIL_NET_H
30 m_nodes.push_back(&
node);
107 assert(
false &&
"Move of Sock into MockSock not allowed.");
116 ssize_t
Send(
const void*,
size_t len,
int)
const override {
return len; }
118 ssize_t
Recv(
void* buf,
size_t len,
int flags)
const override
122 if ((
flags & MSG_PEEK) == 0) {
125 return consume_bytes;
128 int Connect(
const sockaddr*, socklen_t)
const override {
return 0; }
130 std::unique_ptr<Sock>
Accept(sockaddr* addr, socklen_t* addr_len)
const override
132 if (addr !=
nullptr) {
134 memset(addr, 0x00, *addr_len);
135 const socklen_t write_len =
static_cast<socklen_t
>(
sizeof(sockaddr_in));
136 if (*addr_len >= write_len) {
137 *addr_len = write_len;
138 sockaddr_in* addr_in =
reinterpret_cast<sockaddr_in*
>(addr);
139 addr_in->sin_family = AF_INET;
140 memset(&addr_in->sin_addr, 0x05,
sizeof(addr_in->sin_addr));
141 addr_in->sin_port = htons(6789);
144 return std::make_unique<StaticContentsSock>(
"");
147 int GetSockOpt(
int level,
int opt_name,
void* opt_val, socklen_t* opt_len)
const override
149 std::memset(opt_val, 0x0, *opt_len);
153 bool Wait(std::chrono::milliseconds timeout,
155 Event* occurred =
nullptr)
const override
157 if (occurred !=
nullptr) {
158 *occurred = requested;
170 #endif // BITCOIN_TEST_UTIL_NET_H
@ NET_UNROUTABLE
Addresses from these networks are not publicly routable on the global Internet.
SOCKET m_socket
Contained socket.
A mocked Sock alternative that returns a statically contained data upon read and succeeds and ignores...
@ NET_INTERNAL
A set of addresses that represent the hash of a string or FQDN.
int Connect(const sockaddr *, socklen_t) const override
connect(2) wrapper.
@ OUTBOUND_FULL_RELAY
These are the default connections that we use to connect with the network.
Information about a peer.
constexpr NetPermissionFlags ALL_NET_PERMISSION_FLAGS[]
ServiceFlags
nServices flags
ssize_t Send(const void *, size_t len, int) const override
send(2) wrapper.
bool ReceiveMsgFrom(CNode &node, CSerializedNetMsg &ser_msg) const
@ MANUAL
We open manual connections to addresses that users explicitly requested via the addnode RPC or the -a...
RAII helper class that manages a socket.
void SetPeerConnectTimeout(std::chrono::seconds timeout)
A Span is an object that can refer to a contiguous sequence of objects.
void NodeReceiveMsgBytes(CNode &node, Span< const uint8_t > msg_bytes, bool &complete) const
void AddTestNode(CNode &node)
@ INBOUND
Inbound connections are those initiated by a peer.
CConnman(uint64_t seed0, uint64_t seed1, AddrMan &addrman, bool network_active=true)
constexpr ServiceFlags ALL_SERVICE_FLAGS[]
bool Wait(std::chrono::milliseconds timeout, Event requested, Event *occurred=nullptr) const override
Wait for readiness for input (recv) or output (send).
constexpr ConnectionType ALL_CONNECTION_TYPES[]
@ FEELER
Feeler connections are short-lived connections made to check that a node is alive.
std::chrono::seconds m_peer_connect_timeout
virtual bool ProcessMessages(CNode *pnode, std::atomic< bool > &interrupt)=0
Process protocol messages received from a given node.
RecursiveMutex m_nodes_mutex
ssize_t Recv(void *buf, size_t len, int flags) const override
recv(2) wrapper.
std::vector< NodeEvictionCandidate > GetRandomNodeEvictionCandidates(int n_candidates, FastRandomContext &random_context)
@ ADDR_FETCH
AddrFetch connections are short lived connections used to solicit addresses from peers.
@ NET_ONION
TOR (v2 or v3)
void ProcessMessagesOnce(CNode &node)
void Reset() override
Close if non-empty.
~StaticContentsSock() override
@ BLOCK_RELAY
We use block-relay-only connections to help prevent against partition attacks.
StaticContentsSock(const std::string &contents)
const std::string m_contents
std::atomic< bool > flagInterruptMsgProc
NetEventsInterface * m_msgproc
std::unique_ptr< Sock > Accept(sockaddr *addr, socklen_t *addr_len) const override
accept(2) wrapper.
StaticContentsSock & operator=(Sock &&other) override
Move assignment operator, grab the socket from another object and close ours (if set).
ConnectionType
Different types of connections to a peer.
int GetSockOpt(int level, int opt_name, void *opt_val, socklen_t *opt_len) const override
getsockopt(2) wrapper.
constexpr auto ALL_NETWORKS