ex_wire v0.1.1 ExWire.Packet.Hello

This packet establishes capabilities and etc between two peer to peer clents. This is generally required to be the first signed packet communicated after the handshake is complete.

**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.

Link to this section Summary

Functions

Given an RLP-encoded Hello packet from Eth Wire Protocol, decodes into a Hello struct

Handles a Hello message. We can mark a peer as active for communication after we receive this message

Given a Hello packet, serializes for transport over Eth Wire Protocol

Link to this section Types

Link to this type cap()
cap() :: {String.t, integer}
Link to this type t()
t() :: %ExWire.Packet.Hello{caps: [cap], client_id: String.t, listen_port: integer, node_id: ExWire.node_id, p2p_version: integer}

Link to this section Functions

Link to this function deserialize(rlp)
deserialize(ExRLP.t) :: t

Given an RLP-encoded Hello packet from Eth Wire Protocol, decodes into a Hello struct.

Examples

iex> ExWire.Packet.Hello.deserialize([<<10>>, "Exthereum/Test", [["eth", <<1>>], ["par", <<2>>]], <<55>>, <<5>>])
%ExWire.Packet.Hello{p2p_version: 10, client_id: "Exthereum/Test", caps: [{"eth", 1}, {"par", 2}], listen_port: 55, node_id: <<5>>}

Handles a Hello message. We can mark a peer as active for communication after we receive this message.

Examples

iex> %ExWire.Packet.Hello{p2p_version: 10, client_id: "Exthereum/Test", caps: [["eth", 1], ["par", 2]], listen_port: 5555, node_id: <<5>>}
...> |> ExWire.Packet.Hello.handle()
:activate

# When no caps
iex> %ExWire.Packet.Hello{p2p_version: 10, client_id: "Exthereum/Test", caps: [], listen_port: 5555, node_id: <<5>>}
...> |> ExWire.Packet.Hello.handle()
{:disconnect, :useless_peer}
Link to this function serialize(packet)
serialize(t) :: ExRLP.t

Given a Hello packet, serializes for transport over Eth Wire Protocol.

Examples

iex> %ExWire.Packet.Hello{p2p_version: 10, client_id: "Exthereum/Test", caps: [{"eth", 1}, {"par", 2}], listen_port: 5555, node_id: <<5>>}
...> |> ExWire.Packet.Hello.serialize
[10, "Exthereum/Test", [["eth", 1], ["par", 2]], 5555, <<5>>]