Fabcoin Core  0.16.2
P2P Digital Currency
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
dev::p2p::RLPXHandshake Class Reference

Setup inbound or outbound connection for communication over RLPXFrameCoder. More...

#include <RLPxHandshake.h>

Inheritance diagram for dev::p2p::RLPXHandshake:
[legend]
Collaboration diagram for dev::p2p::RLPXHandshake:
[legend]

Public Member Functions

 RLPXHandshake (Host *_host, std::shared_ptr< RLPXSocket > const &_socket)
 Setup incoming connection. More...
 
 RLPXHandshake (Host *_host, std::shared_ptr< RLPXSocket > const &_socket, NodeID _remote)
 Setup outbound connection. More...
 
 ~RLPXHandshake ()
 
void start ()
 Start handshake. More...
 
void cancel ()
 Aborts the handshake. More...
 

Protected Types

enum  State {
  Error = -1, New, AckAuth, AckAuthEIP8,
  WriteHello, ReadHello, StartSession
}
 Sequential states of handshake. More...
 

Protected Member Functions

void writeAuth ()
 Write Auth message to socket and transitions to AckAuth. More...
 
void readAuth ()
 Reads Auth message from socket and transitions to AckAuth. More...
 
void readAuthEIP8 ()
 Continues reading Auth message in EIP-8 format and transitions to AckAuthEIP8. More...
 
void setAuthValues (Signature const &sig, Public const &remotePubk, h256 const &remoteNonce, uint64_t remoteVersion)
 Derives ephemeral secret from signature and sets members after Auth has been decrypted. More...
 
void writeAck ()
 Write Ack message to socket and transitions to WriteHello. More...
 
void writeAckEIP8 ()
 Write Ack message in EIP-8 format to socket and transitions to WriteHello. More...
 
void readAck ()
 Reads Auth message from socket and transitions to WriteHello. More...
 
void readAckEIP8 ()
 Continues reading Ack message in EIP-8 format and transitions to WriteHello. More...
 
void error ()
 Closes connection and ends transitions. More...
 
virtual void transition (boost::system::error_code _ech=boost::system::error_code())
 Performs transition for m_nextState. More...
 

Protected Attributes

boost::posix_time::milliseconds const c_timeout = boost::posix_time::milliseconds(1800)
 Timeout for remote to respond to transition events. Enforced by m_idleTimer and refreshed by transition(). More...
 
State m_nextState = New
 Current or expected state of transition. More...
 
bool m_cancel = false
 Will be set to true if connection was canceled. More...
 
Hostm_host
 Host which provides m_alias, protocolVersion(), m_clientVersion, caps(), and TCP listenPort(). More...
 
NodeID m_remote
 Node id of remote host for socket. More...
 
bool m_originated = false
 True if connection is outbound. More...
 
bytes m_auth
 Buffers for encoded and decoded handshake phases. More...
 
bytes m_authCipher
 Ciphertext of egress or ingress Auth message. More...
 
bytes m_ack
 Plaintext of egress or ingress Ack message. More...
 
bytes m_ackCipher
 Ciphertext of egress or ingress Ack message. More...
 
bytes m_handshakeOutBuffer
 Frame buffer for egress Hello packet. More...
 
bytes m_handshakeInBuffer
 Frame buffer for ingress Hello packet. More...
 
crypto::ECDHE m_ecdhe
 Ephemeral ECDH secret and agreement. More...
 
h256 m_nonce
 Nonce generated by this host for handshake. More...
 
Public m_remoteEphemeral
 Remote ephemeral public key. More...
 
h256 m_remoteNonce
 Nonce generated by remote host for handshake. More...
 
uint64_t m_remoteVersion
 
std::unique_ptr< RLPXFrameCoderm_io
 Used to read and write RLPx encrypted frames for last step of handshake authentication. More...
 
std::shared_ptr< RLPXSocketm_socket
 Socket. More...
 
boost::asio::deadline_timer m_idleTimer
 Timer which enforces c_timeout. More...
 

Friends

class RLPXFrameCoder
 

Detailed Description

Setup inbound or outbound connection for communication over RLPXFrameCoder.

RLPx Spec: https://github.com/ethereum/devp2p/blob/master/rlpx.md#encrypted-handshake

Todo:
Implement StartSession transition via lambda which is passed to constructor.

Thread Safety Distinct Objects: Safe. Shared objects: Unsafe.

Definition at line 51 of file RLPxHandshake.h.

Member Enumeration Documentation

Sequential states of handshake.

Enumerator
Error 
New 
AckAuth 
AckAuthEIP8 
WriteHello 
ReadHello 
StartSession 

Definition at line 72 of file RLPxHandshake.h.

Constructor & Destructor Documentation

dev::p2p::RLPXHandshake::RLPXHandshake ( Host _host,
std::shared_ptr< RLPXSocket > const &  _socket 
)
inline

Setup incoming connection.

Definition at line 57 of file RLPxHandshake.h.

Here is the call graph for this function:

dev::p2p::RLPXHandshake::RLPXHandshake ( Host _host,
std::shared_ptr< RLPXSocket > const &  _socket,
NodeID  _remote 
)
inline

Setup outbound connection.

Definition at line 60 of file RLPxHandshake.h.

Here is the call graph for this function:

dev::p2p::RLPXHandshake::~RLPXHandshake ( )
inline

Definition at line 62 of file RLPxHandshake.h.

Member Function Documentation

void RLPXHandshake::cancel ( )

Aborts the handshake.

Definition at line 218 of file RLPxHandshake.cpp.

Here is the caller graph for this function:

void RLPXHandshake::error ( )
protected

Closes connection and ends transitions.

Definition at line 226 of file RLPxHandshake.cpp.

void RLPXHandshake::readAck ( )
protected

Reads Auth message from socket and transitions to WriteHello.

Definition at line 167 of file RLPxHandshake.cpp.

Here is the call graph for this function:

void RLPXHandshake::readAckEIP8 ( )
protected

Continues reading Ack message in EIP-8 format and transitions to WriteHello.

Definition at line 188 of file RLPxHandshake.cpp.

Here is the call graph for this function:

void RLPXHandshake::readAuth ( )
protected

Reads Auth message from socket and transitions to AckAuth.

Definition at line 110 of file RLPxHandshake.cpp.

Here is the call graph for this function:

void RLPXHandshake::readAuthEIP8 ( )
protected

Continues reading Auth message in EIP-8 format and transitions to AckAuthEIP8.

Definition at line 133 of file RLPxHandshake.cpp.

Here is the call graph for this function:

void RLPXHandshake::setAuthValues ( Signature const &  sig,
Public const &  remotePubk,
h256 const &  remoteNonce,
uint64_t  remoteVersion 
)
protected

Derives ephemeral secret from signature and sets members after Auth has been decrypted.

Definition at line 100 of file RLPxHandshake.cpp.

Here is the call graph for this function:

void dev::p2p::RLPXHandshake::start ( )
inline

Start handshake.

Definition at line 65 of file RLPxHandshake.h.

Here is the call graph for this function:

void RLPXHandshake::transition ( boost::system::error_code  _ech = boost::system::error_code())
protectedvirtual

Performs transition for m_nextState.

This pointer will be freed if there is an error otherwise it will be passed to Host which will take ownership.

authenticate and decrypt header

check frame size

rlp of header has protocol-type, sequence-id[, total-packet-size]

read padded frame and mac

Reimplemented in TestHandshake.

Definition at line 237 of file RLPxHandshake.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void RLPXHandshake::writeAck ( )
protected

Write Ack message to socket and transitions to WriteHello.

Definition at line 57 of file RLPxHandshake.cpp.

Here is the call graph for this function:

void RLPXHandshake::writeAckEIP8 ( )
protected

Write Ack message in EIP-8 format to socket and transitions to WriteHello.

Definition at line 75 of file RLPxHandshake.cpp.

Here is the call graph for this function:

void RLPXHandshake::writeAuth ( )
protected

Write Auth message to socket and transitions to AckAuth.

Definition at line 31 of file RLPxHandshake.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

friend class RLPXFrameCoder
friend

Definition at line 53 of file RLPxHandshake.h.

Member Data Documentation

boost::posix_time::milliseconds const dev::p2p::RLPXHandshake::c_timeout = boost::posix_time::milliseconds(1800)
protected

Timeout for remote to respond to transition events. Enforced by m_idleTimer and refreshed by transition().

Definition at line 114 of file RLPxHandshake.h.

bytes dev::p2p::RLPXHandshake::m_ack
protected

Plaintext of egress or ingress Ack message.

Definition at line 128 of file RLPxHandshake.h.

bytes dev::p2p::RLPXHandshake::m_ackCipher
protected

Ciphertext of egress or ingress Ack message.

Definition at line 129 of file RLPxHandshake.h.

bytes dev::p2p::RLPXHandshake::m_auth
protected

Buffers for encoded and decoded handshake phases.

Plaintext of egress or ingress Auth message.

Definition at line 126 of file RLPxHandshake.h.

bytes dev::p2p::RLPXHandshake::m_authCipher
protected

Ciphertext of egress or ingress Auth message.

Definition at line 127 of file RLPxHandshake.h.

bool dev::p2p::RLPXHandshake::m_cancel = false
protected

Will be set to true if connection was canceled.

Definition at line 117 of file RLPxHandshake.h.

crypto::ECDHE dev::p2p::RLPXHandshake::m_ecdhe
protected

Ephemeral ECDH secret and agreement.

Definition at line 133 of file RLPxHandshake.h.

bytes dev::p2p::RLPXHandshake::m_handshakeInBuffer
protected

Frame buffer for ingress Hello packet.

Definition at line 131 of file RLPxHandshake.h.

bytes dev::p2p::RLPXHandshake::m_handshakeOutBuffer
protected

Frame buffer for egress Hello packet.

Definition at line 130 of file RLPxHandshake.h.

Host* dev::p2p::RLPXHandshake::m_host
protected

Host which provides m_alias, protocolVersion(), m_clientVersion, caps(), and TCP listenPort().

Definition at line 119 of file RLPxHandshake.h.

boost::asio::deadline_timer dev::p2p::RLPXHandshake::m_idleTimer
protected

Timer which enforces c_timeout.

Definition at line 145 of file RLPxHandshake.h.

std::unique_ptr<RLPXFrameCoder> dev::p2p::RLPXHandshake::m_io
protected

Used to read and write RLPx encrypted frames for last step of handshake authentication.

Passed onto Host which will take ownership.

Definition at line 142 of file RLPxHandshake.h.

State dev::p2p::RLPXHandshake::m_nextState = New
protected

Current or expected state of transition.

Definition at line 116 of file RLPxHandshake.h.

h256 dev::p2p::RLPXHandshake::m_nonce
protected

Nonce generated by this host for handshake.

Definition at line 134 of file RLPxHandshake.h.

bool dev::p2p::RLPXHandshake::m_originated = false
protected

True if connection is outbound.

Definition at line 123 of file RLPxHandshake.h.

NodeID dev::p2p::RLPXHandshake::m_remote
protected

Node id of remote host for socket.

Public address of remote host.

Definition at line 122 of file RLPxHandshake.h.

Public dev::p2p::RLPXHandshake::m_remoteEphemeral
protected

Remote ephemeral public key.

Definition at line 136 of file RLPxHandshake.h.

h256 dev::p2p::RLPXHandshake::m_remoteNonce
protected

Nonce generated by remote host for handshake.

Definition at line 137 of file RLPxHandshake.h.

uint64_t dev::p2p::RLPXHandshake::m_remoteVersion
protected

Definition at line 138 of file RLPxHandshake.h.

std::shared_ptr<RLPXSocket> dev::p2p::RLPXHandshake::m_socket
protected

Socket.

Definition at line 144 of file RLPxHandshake.h.


The documentation for this class was generated from the following files: