Skip to content

Instantly share code, notes, and snippets.

@shingonu
Created September 15, 2018 09:09
Show Gist options
  • Select an option

  • Save shingonu/0456bb002e9b2c56334809e629488ea6 to your computer and use it in GitHub Desktop.

Select an option

Save shingonu/0456bb002e9b2c56334809e629488ea6 to your computer and use it in GitHub Desktop.

https://github.com/ethereum/wiki/wiki/%C3%90%CE%9EVp2p-Wire-Protocol

peer-to-peer 커뮤니케이션을 위해, node들은 Ethereum/Whisper/&c를 구동한다. client들은 심플한 wire-protocol에 의해 작동되도록 디자인되어 있다. 이 wire-protocol은 기존의 ÐΞV 기술RLP와 같은 표준을 사용한다.

Low-Level

ÐΞVp2p 노드들은 RLPx를 사용하여 message를 보냄으로써 커뮤니케이션한다. RLPx는 encrypted, authenticated transport protocol이다. 피어는 자신이 원하는 모든 TCP 포트에서 연결을 알리고 허용 할 수 있지만, 기본 TCP가 connection-oriented 매체를 제공하지만, ÐΞVp2p 노드들은 패킷의 관점에서 통신한다. RLPx는 이러한 packet들은 보내거나 받는 facilities를 제공한다.

TODO: https://github.com/ethereum/devp2p/blob/master/rlpx.md (RLPx)

ÐΞVp2p 노드들은 RLPx discovery protocol DHT를 통해 peer들을 찾는다. 클라이언트 특정 RPC API에 피어의 endpoint을 제공하여 피어 연결을 시작할 수도 있다.

  • endpoint: The endpoint is a device or node that is connected to the LAN or WAN and accepts communications back and forth across the network. In a traditional sense, an endpoint can be a modem, hub, bridge, or switch. It also could be data terminal equipment (such as a digital telephone handset, router, or printer) or a host computer (such as a workstation or a server).

Payload Contents

RLP로 인코딩되는 여러 종류의 payload가 존재한다. 이 타입은 RLP의 진입 점에 결정된다. 이는 숫자 값이다.

ÐΞVp2p는 기본 와이어 프로토콜을 통해 임의의 sub-protocol (aka capabilities)을 지원하도록 설계되어있다. 각 sub-protocol에는 필요에 따라 메시지 ID 공간이 제공된다. (이러한 모든 프로토콜은 필요한 메시지 ID 수를 정적으로 지정해야 한다). Hello 메시지의 접속 및 수신 시, 두 피어는 버전을 포함하여 어떤 하위 프로토콜을 공유하는지에 대한 동일한 정보를 가지며, 메시지 ID 공간의 구성에 대한 합의를 형성 할 수 있습니다.

Message ID들은 ID 0x10부터 압축 된 것으로 가정되며 (0x00-0x10은 ΞVp2p 메시지 용으로 예약 됨) 알파벳 순서로 각 공유 (동등 버전, 동등한 이름) 하위 프로토콜에 제공된다. 이 때 공유되지 않은 Sub-protocol은 무시된다. 여러 버전이 동일한 (동등한 이름) 하위 프로토콜로 공유되는 경우, 숫자가 가장 높은 하위 프로토콜이 선택되고 나머지는 무시된다.

P2P

Hello 0x00 [p2pVersion: P, clientId: B, [[cap1: B_3, capVersion1: P], [cap2: B_3, capVersion2: P], ...], listenPort: P, nodeId: B_64] First packet sent over the connection, and sent once by both sides. No other messages may be sent until a Hello is received.

  • p2pVersion Specifies the implemented version of the P2P protocol. Now must be 1.
  • clientId Specifies the client software identity, as a human-readable string (e.g. "Ethereum(++)/1.0.0").
  • cap Specifies a peer capability name as a length-3 ASCII string. Current supported capabilities are eth, shh.
  • capVersion Specifies a peer capability version as a positive integer. Current supported versions are 34 for eth, and 1 for shh.
  • listenPort specifies the port that the client is listening on (on the interface that the present connection traverses). If 0 it indicates the client is not listening.
  • nodeId is the Unique Identity of the node and specifies a 512-bit hash that identifies this node.

Disconnect 0x01 [reason: P] Inform the peer that a disconnection is imminent; if received, a peer should disconnect immediately. When sending, well-behaved hosts give their peers a fighting chance (read: wait 2 seconds) to disconnect to before disconnecting themselves.

  • reason
    

    is an optional integer specifying one of a number of reasons for disconnect:

    • 0x00 Disconnect requested;
    • 0x01 TCP sub-system error;
    • 0x02 Breach of protocol, e.g. a malformed message, bad RLP, incorrect magic number &c.;
    • 0x03 Useless peer;
    • 0x04 Too many peers;
    • 0x05 Already connected;
    • 0x06 Incompatible P2P protocol version;
    • 0x07 Null node identity received - this is automatically invalid;
    • 0x08 Client quitting;
    • 0x09 Unexpected identity (i.e. a different identity to a previous connection/what a trusted peer told us).
    • 0x0a Identity is the same as this node (i.e. connected to itself);
    • 0x0b Timeout on receiving a message (i.e. nothing received since sending last ping);
    • 0x10 Some other reason specific to a subprotocol.

Ping 0x02 [] Requests an immediate reply of Pong from the peer.

Pong 0x03 [] Reply to peer's Ping packet.

NotImplemented (was GetPeers) 0x04

NotImplemented (was Peers) 0x05

Node identity and reputation

The identity of a ÐΞVp2p node is a secp256k1 public key.

Nodes are free to store ratings for given IDs (how useful the node has been in the past) and give preference accordingly. Nodes may also track node IDs (and their provenance) in order to help determine potential man-in-the-middle attacks. Clients are free to mark down new nodes and use the node ID as a means of determining a node's reputation.

Session Management

Upon connecting, all clients (i.e. both sides of the connection) must send a Hello message. Upon receiving the Hello message and verifying compatibility of the network and versions, a session is active and any other P2P messages may be sent.

At any time, a Disconnect message may be sent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment