Skip to content
This repository has been archived by the owner on Aug 8, 2018. It is now read-only.

Code Walkthrough

heikoheiko edited this page Aug 6, 2015 · 9 revisions

Following a block from the network socket to the hard drive

Note: All links to the code are based on a fixed revision, so we can link line numbers. Code might have changed by now, nonetheless use these revisions when doing updates to this document.

Preconditons

  • the app was configured and started
  • all services registered
  • the discovery protocol discovered some nodes
  • the peermanager successfully connected a node
  • established an encrypted multiplexed session
  • and created a ETHProtocol instance for this peer
  • we are waiting for ingress data in the peer connection

Interpreting network data

Wait for data on the socket: https://github.com/ethereum/pydevp2p/blob/6577016a6f50ce220e20f66c2c8c1eb6dc271b9c/devp2p/peer.py#L208

add the (partial) message to the MultiplexedSession: https://github.com/ethereum/pydevp2p/blob/6577016a6f50ce220e20f66c2c8c1eb6dc271b9c/devp2p/peer.py#L223

try to decode packets (objects representing the equivalent to to a rpc cmd): https://github.com/ethereum/pydevp2p/blob/6577016a6f50ce220e20f66c2c8c1eb6dc271b9c/devp2p/muxsession.py#L66 decode if there is enough data in the buffer https://github.com/ethereum/pydevp2p/blob/6577016a6f50ce220e20f66c2c8c1eb6dc271b9c/devp2p/multiplexer.py#L520 https://github.com/ethereum/pydevp2p/blob/6577016a6f50ce220e20f66c2c8c1eb6dc271b9c/devp2p/multiplexer.py#L426 decrypt https://github.com/ethereum/pydevp2p/blob/6577016a6f50ce220e20f66c2c8c1eb6dc271b9c/devp2p/multiplexer.py#L442 using the cipher https://github.com/ethereum/pydevp2p/blob/6577016a6f50ce220e20f66c2c8c1eb6dc271b9c/devp2p/muxsession.py#L17 which we have in the RLPx session https://github.com/ethereum/pydevp2p/blob/6577016a6f50ce220e20f66c2c8c1eb6dc271b9c/devp2p/rlpxcipher.py#L41