Fabcoin Core  0.16.2
P2P Digital Currency
RLPXSocketIO.h
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16  */
22 #pragma once
23 
24 #include "RLPXFrameWriter.h"
25 namespace ba = boost::asio;
26 namespace bi = boost::asio::ip;
27 
28 namespace dev
29 {
30 namespace p2p
31 {
32 
33 class RLPXSocketIO: public std::enable_shared_from_this<RLPXSocketIO>
34 {
35 public:
36  static uint32_t const MinFrameSize;
37  static uint32_t const MaxPacketSize;
38  static uint16_t const DefaultInitialCapacity;
39 
40  RLPXSocketIO(unsigned _protCount, RLPXFrameCoder& _coder, bi::tcp::socket& _socket, bool _flowControl = true, size_t _initialCapacity = DefaultInitialCapacity);
41 
42  void send(unsigned _protocolType, unsigned _type, RLPStream& _payload);
43 
44  void doWrite();
45 
46 private:
47  static std::vector<RLPXFrameWriter> writers(unsigned _capacity);
48 
49  void deferWrite();
50 
51  void write(size_t _dequed);
52 
53  bool const m_flowControl;
54 
56  bi::tcp::socket& m_socket;
57 
58  std::deque<bytes> m_toSend;
59 
60  std::vector<RLPXFrameWriter> m_writers;
61  std::unique_ptr<ba::deadline_timer> m_congestion;
62 
64  unsigned m_queued = 0;
65  uint32_t m_egressCapacity;
66 };
67 
68 }
69 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
static std::vector< RLPXFrameWriter > writers(unsigned _capacity)
std::deque< bytes > m_toSend
Reusable byte buffer for pending socket writes.
Definition: RLPXSocketIO.h:58
unsigned m_queued
Track total queued packets to ensure single write loop.
Definition: RLPXSocketIO.h:64
RLPXSocketIO(unsigned _protCount, RLPXFrameCoder &_coder, bi::tcp::socket &_socket, bool _flowControl=true, size_t _initialCapacity=DefaultInitialCapacity)
std::unique_ptr< ba::deadline_timer > m_congestion
Scheduled when writes are deferred due to congestion.
Definition: RLPXSocketIO.h:61
std::vector< RLPXFrameWriter > m_writers
Write queues for each protocol. TODO: map to bytes (of capability)
Definition: RLPXSocketIO.h:60
void send(unsigned _protocolType, unsigned _type, RLPStream &_payload)
bi::tcp::socket & m_socket
Definition: RLPXSocketIO.h:56
static uint32_t const MinFrameSize
Definition: RLPXSocketIO.h:36
bool const m_flowControl
True if flow control is enabled.
Definition: RLPXSocketIO.h:53
static uint16_t const DefaultInitialCapacity
Definition: RLPXSocketIO.h:38
void write(size_t _dequed)
RLPXFrameCoder & m_coder
Encoder/decoder of frame payloads.
Definition: RLPXSocketIO.h:55
std::mutex Mutex
Definition: Guards.h:37
Class for writing to an RLP bytestream.
Definition: RLP.h:383
Encoder/decoder transport for RLPx connection established by RLPXHandshake.
static uint32_t const MaxPacketSize
Definition: RLPXSocketIO.h:37