ex_wire v0.1.1 ExWire.Packet.Disconnect

Disconnect is when a peer wants to end a connection for a reason.

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

Link to this section Summary

Functions

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

Returns a string interpretation of a reason for disconnect

Handles a Disconnect message. We are instructed to disconnect, which we’ll abide by

Creates a new disconnect message with given reason. This function raises if reason is not a known reason

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

Link to this section Types

Link to this type t()
t() :: %ExWire.Packet.Disconnect{reason: integer}

Link to this section Functions

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

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

Examples

iex> ExWire.Packet.Disconnect.deserialize([<<0x0b>>])
%ExWire.Packet.Disconnect{reason: :timeout_on_receiving_message}
Link to this function get_reason_msg(reason)
get_reason_msg(integer) :: String.t

Returns a string interpretation of a reason for disconnect.

Examples

iex> ExWire.Packet.Disconnect.get_reason_msg(:timeout_on_receiving_message)
"timeout on receiving a message"

Handles a Disconnect message. We are instructed to disconnect, which we’ll abide by.

Examples

iex> %ExWire.Packet.GetBlockBodies{hashes: [<<5>>, <<6>>]}
...> |> ExWire.Packet.GetBlockBodies.handle()
:ok

Creates a new disconnect message with given reason. This function raises if reason is not a known reason.

Examples

iex> ExWire.Packet.Disconnect.new(:too_many_peers)
%ExWire.Packet.Disconnect{reason: :too_many_peers}

iex> ExWire.Packet.Disconnect.new(:something_else)
** (RuntimeError) Invalid reason
Link to this function serialize(packet)
serialize(t) :: ExRLP.t

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

Examples

iex> %ExWire.Packet.Disconnect{reason: :timeout_on_receiving_message}
...> |> ExWire.Packet.Disconnect.serialize
[0x0b]