![]() |
Bitcoin Core 31.99.0
P2P Digital Currency
|
#include <httpserver.h>
Public Member Functions | |
| std::shared_ptr< Sock > m_sock | GUARDED_BY (m_sock_mutex) |
| Underlying socket. More... | |
| HTTPRemoteClient (HTTPServer::Id id, const CService &addr, std::unique_ptr< Sock > socket) | |
| HTTPRemoteClient (const HTTPRemoteClient &)=delete | |
| HTTPRemoteClient & | operator= (const HTTPRemoteClient &)=delete |
| bool | ReadRequest (HTTPRequest &req) |
| Try to read an HTTP request from the receive buffer. More... | |
| bool | MaybeSendBytesFromBuffer () EXCLUSIVE_LOCKS_REQUIRED(!m_send_mutex |
| Push data (if there is any) from client's m_send_buffer to the connected socket. More... | |
Public Attributes | |
| const HTTPServer::Id | m_id |
| ID provided by HTTPServer upon connection and instantiation. More... | |
| const CService | m_addr |
| Remote address of connected client. More... | |
| const std::string | m_origin |
| IP:port of connected client, cached for logging purposes. More... | |
| std::vector< std::byte > | m_recv_buffer {} |
| In lieu of an intermediate transport class like p2p uses, we copy data from the socket buffer to the client object and attempt to read HTTP requests from here. More... | |
| std::deque< std::unique_ptr< HTTPRequest > > | m_req_queue |
| Requests from a client must be processed in the order in which they were received, blocking on a per-client basis. More... | |
| std::atomic_bool | m_req_busy {false} |
| Set to true by the I/O thread when a request is popped off and passed to a worker thread, reset to false by the worker thread. More... | |
| std::atomic_bool | m_send_ready {false} |
| Set true by worker threads after writing a response to m_send_buffer. More... | |
| Mutex | m_sock_mutex |
Mutex that serializes the Send() and Recv() calls on m_sock. More... | |
| std::atomic_bool | m_connection_busy {true} |
| Initialized to true while server waits for first request from client. More... | |
| std::atomic_bool | m_keep_alive {false} |
| Client has requested to keep the connection open after all requests have been responded to. More... | |
| std::atomic_bool | m_disconnect {false} |
| Flag this client for disconnection on next loop. More... | |
| std::atomic< SteadySeconds > | m_idle_since |
| Timestamp of last send or receive activity, used for -rpcservertimeout. More... | |
| bool | !m_sock_mutex |
| Mutex | m_send_mutex |
| Response data destined for this client. More... | |
| std::vector< std::byte > m_send_buffer | GUARDED_BY (m_send_mutex) |
Definition at line 447 of file httpserver.h.
|
inlineexplicit |
Definition at line 533 of file httpserver.h.
|
delete |
| std::vector< std::byte > m_send_buffer http_bitcoin::HTTPRemoteClient::GUARDED_BY | ( | m_send_mutex | ) |
| std::shared_ptr< Sock > m_sock http_bitcoin::HTTPRemoteClient::GUARDED_BY | ( | m_sock_mutex | ) |
Underlying socket.
shared_ptr (instead of unique_ptr) is used to avoid premature close of the underlying file descriptor by one thread while another thread is poll(2)-ing it for activity.
| bool http_bitcoin::HTTPRemoteClient::MaybeSendBytesFromBuffer | ( | ) |
Push data (if there is any) from client's m_send_buffer to the connected socket.
Definition at line 1116 of file httpserver.cpp.
|
delete |
| bool http_bitcoin::HTTPRemoteClient::ReadRequest | ( | HTTPRequest & | req | ) |
Try to read an HTTP request from the receive buffer.
| [in] | req | A HTTPRequest to read into |
Definition at line 1098 of file httpserver.cpp.
| bool http_bitcoin::HTTPRemoteClient::!m_sock_mutex |
Definition at line 551 of file httpserver.h.
| const CService http_bitcoin::HTTPRemoteClient::m_addr |
Remote address of connected client.
Definition at line 454 of file httpserver.h.
| std::atomic_bool http_bitcoin::HTTPRemoteClient::m_connection_busy {true} |
Initialized to true while server waits for first request from client.
Set to false after data is written to m_send_buffer and then that buffer is flushed to client. Reset to true when we receive new request data from client. Checked during DisconnectClients() and set by read/write operations called in either the HTTPServer I/O loop or by a worker thread during an "optimistic send". m_connection_busy=true can be overridden by m_disconnect=true (we disconnect).
Definition at line 514 of file httpserver.h.
| std::atomic_bool http_bitcoin::HTTPRemoteClient::m_disconnect {false} |
Flag this client for disconnection on next loop.
Either we have encountered a permanent error, or both sides of the socket are done with the connection, e.g. our reply to a "Connection: close" request has been sent. Might be set in a worker thread or in the I/O thread. When set to true we disconnect, possibly overriding all other disconnect flags.
Definition at line 526 of file httpserver.h.
| const HTTPServer::Id http_bitcoin::HTTPRemoteClient::m_id |
ID provided by HTTPServer upon connection and instantiation.
Definition at line 451 of file httpserver.h.
| std::atomic<SteadySeconds> http_bitcoin::HTTPRemoteClient::m_idle_since |
Timestamp of last send or receive activity, used for -rpcservertimeout.
Due to optimistic sends it may be updated in either a worker thread or in the I/O thread. It is checked in the I/O thread to disconnect idle clients.
Definition at line 531 of file httpserver.h.
| std::atomic_bool http_bitcoin::HTTPRemoteClient::m_keep_alive {false} |
Client has requested to keep the connection open after all requests have been responded to.
Set by (potentially multiple) worker threads and checked in the HTTPServer I/O loop. m_keep_alive=true can be overridden by HTTPServer.m_disconnect_all_clients (we disconnect).
Definition at line 519 of file httpserver.h.
| const std::string http_bitcoin::HTTPRemoteClient::m_origin |
IP:port of connected client, cached for logging purposes.
Definition at line 457 of file httpserver.h.
| std::vector<std::byte> http_bitcoin::HTTPRemoteClient::m_recv_buffer {} |
In lieu of an intermediate transport class like p2p uses, we copy data from the socket buffer to the client object and attempt to read HTTP requests from here.
Definition at line 464 of file httpserver.h.
| std::atomic_bool http_bitcoin::HTTPRemoteClient::m_req_busy {false} |
Set to true by the I/O thread when a request is popped off and passed to a worker thread, reset to false by the worker thread.
Definition at line 474 of file httpserver.h.
| std::deque<std::unique_ptr<HTTPRequest> > http_bitcoin::HTTPRemoteClient::m_req_queue |
Requests from a client must be processed in the order in which they were received, blocking on a per-client basis.
We won't process the next request in the queue if we are currently busy handling a previous request.
Definition at line 470 of file httpserver.h.
| Mutex http_bitcoin::HTTPRemoteClient::m_send_mutex |
Response data destined for this client.
Written to by http worker threads, read and erased by HTTPServer I/O thread
Definition at line 481 of file httpserver.h.
| std::atomic_bool http_bitcoin::HTTPRemoteClient::m_send_ready {false} |
Set true by worker threads after writing a response to m_send_buffer.
Set false by the HTTPServer I/O thread after flushing m_send_buffer. Checked in the HTTPServer I/O loop to avoid locking m_send_mutex if there's nothing to send.
Definition at line 490 of file httpserver.h.
| Mutex http_bitcoin::HTTPRemoteClient::m_sock_mutex |
Mutex that serializes the Send() and Recv() calls on m_sock.
Reading from the client occurs in the I/O thread but writing back to a client may occur in a worker thread.
Definition at line 497 of file httpserver.h.