Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Analysis of Geth 1.6.6v’s P2P network

img img

  • create UDP/TCP listener
  • schedule 2 types of task(discoverTask, dialTask)

img

  • seeding Ethereum nodes into Kademlia DHT

img

  • create Kademlia DHT

img

  • get Ethereum node’s information from local database(level db) for seeding

img

  • get seedCount(default = 30) Ethereum nodes from DB and also hard-coded bootstrap_nodes.
  • insert bootstrap_nodes + DB_nodes into DHT

img

  • keep DHT fresh and do bonding process

    red-box is a goroutine

img

  • use lookup(random target) process to populate DHT
  • validating nodes in DHT with Ping/Pong pakcets(1h)
  • keep the old nodes in DHT in DB(5m)

img

  • connection read loop

img

  • create TCP Listener

img

  • create 50 channel for connection and scheduling

img

  • pass the results of handshake to srv.run goroutine’s channel
  • add peer to eth.peer

img

  • RLPx handshake
  • set both in/outbound connection

img

  • goroutine
  • 2 types Task scheduling(discover, dial)
  • By its channel, add peer and execute

img

  • discoverTask : kademlia-like lookup
  • add nodes into lookupBuf when discoverTask is done
  • dialTask : dialing for setupConnection

img

  • kademlia-like lookup

img

  • Get closest(random Target) 16 nodes from DHT
  • Among these nodes, if there are first-seen-nodes, doing bonding process and insert into db.

img

  • run when running task is below 16
  • MaxDynamicDial(MaxOutboundConn) = ( 1+maxpeer(25) )/2 = 13
  • can add staticNode
  • leftover dialing count = needDynDials
  • extract 6 nodes( needDynDials/2 ) from DHT, and create dialTask
  • if it still require more nodes, extract 7 nodes from lookupBuf, and create dialTask

img

  • Where Inbound connection are actually confirmed
  • Inbound connection is no limited

Attacker create a lot of inbound connection requests to the victim in 20 seconds right after the victim boot.

Thus, to prevent all connection from dominated by adversary connections, in Geth 1.9.24v, they set limit of inbound connections. So if attacker send multiple inbound connection requests, there is a limit! And the victim can still connect with normal nodes by outbound connection. img