Fabcoin Core  0.16.2
P2P Digital Currency
RLPXFrameCoder.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  */
23 #pragma once
24 
25 #include <memory>
26 #include <libdevcore/Guards.h>
27 #include <libdevcrypto/ECDHE.h>
28 #include <libdevcrypto/CryptoPP.h>
29 #include "Common.h"
30 
31 namespace dev
32 {
33 namespace p2p
34 {
35 
37 
43 {
44  RLPXFrameInfo() = default;
46  RLPXFrameInfo(bytesConstRef _frameHeader);
47 
48  uint32_t const length;
49  uint8_t const padding;
50 
51  bytes const data;
52  RLP const header;
53 
54  uint16_t const protocolId;
55  bool const multiFrame;
56  uint16_t const sequenceId;
57  uint32_t const totalLength;
58 };
59 
60 class RLPXHandshake;
61 
74 {
75  friend class RLPXFrameIOMux;
76  friend class Session;
77 public:
79  RLPXFrameCoder(RLPXHandshake const& _init);
80 
82  RLPXFrameCoder(bool _originated, h512 const& _remoteEphemeral, h256 const& _remoteNonce, crypto::ECDHE const& _ephemeral, h256 const& _nonce, bytesConstRef _ackCipher, bytesConstRef _authCipher);
83 
84  ~RLPXFrameCoder();
85 
87  void setup(bool _originated, h512 const& _remoteEphemeral, h256 const& _remoteNonce, crypto::ECDHE const& _ephemeral, h256 const& _nonce, bytesConstRef _ackCipher, bytesConstRef _authCipher);
88 
90  void writeFrame(uint16_t _protocolType, bytesConstRef _payload, bytes& o_bytes);
91 
93  void writeFrame(uint16_t _protocolType, uint16_t _seqId, bytesConstRef _payload, bytes& o_bytes);
94 
96  void writeFrame(uint16_t _protocolType, uint16_t _seqId, uint32_t _totalSize, bytesConstRef _payload, bytes& o_bytes);
97 
99  void writeSingleFramePacket(bytesConstRef _packet, bytes& o_bytes);
100 
102  bool authAndDecryptHeader(bytesRef io_cipherWithMac);
103 
105  bool authAndDecryptFrame(bytesRef io_cipherWithMac);
106 
108  h128 egressDigest();
109 
111  h128 ingressDigest();
112 
113 protected:
114  void writeFrame(RLPStream const& _header, bytesConstRef _payload, bytes& o_bytes);
115 
117  void updateEgressMACWithHeader(bytesConstRef _headerCipher);
118 
120  void updateEgressMACWithFrame(bytesConstRef _cipher);
121 
123  void updateIngressMACWithHeader(bytesConstRef _headerCipher);
124 
126  void updateIngressMACWithFrame(bytesConstRef _cipher);
127 
128 private:
129  std::unique_ptr<class RLPXFrameCoderImpl> m_impl;
130 };
131 
132 }
133 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
RLP const header
Header RLP.
bytes const data
Bytes of Header.
std::unique_ptr< class RLPXFrameCoderImpl > m_impl
Base class for all exceptions.
Definition: Exceptions.h:39
Encapsulation of Frame.
std::vector< byte > bytes
Definition: Common.h:75
uint32_t const totalLength
Set to total length of packet in first frame of multiframe packet.
bool const multiFrame
If this frame is part of a sequence.
Class for writing to an RLP bytestream.
Definition: RLP.h:383
Derive DH shared secret from EC keypairs.
Definition: ECDHE.h:37
Encoder/decoder transport for RLPx connection established by RLPXHandshake.
uint8_t const padding
Length of padding which follows .
uint32_t const length
Size of frame (excludes padding). Max: 2**24.
Class for interpreting Recursive Linear-Prefix Data.
Definition: RLP.h:64
uint16_t const protocolId
Protocol ID as negotiated by handshake.
The Session class.
Definition: Session.h:90
Setup inbound or outbound connection for communication over RLPXFrameCoder.
Definition: RLPxHandshake.h:51
uint16_t const sequenceId
Sequence ID of frame.