ex_wire v0.1.1 ExWire.Packet behaviour

Packets handle serializing and deserializing framed packet data from the DevP2P and Eth Wire Protocols. They also handle how to respond to incoming packets.

Link to this section Summary

Functions

Returns the module which contains functions to serialize/1, deserialize/1 and handle/1 the given packet_type

Returns the eth id of the given packet based on the struct

Link to this section Types

Link to this type block_hash()
block_hash() :: {binary, integer}
Link to this type block_identifier()
block_identifier() :: binary | integer
Link to this type handle_response()
handle_response ::
  :ok |
  :activate |
  :peer_disconnect |
  {:disconnect, atom} |
  {:send, struct}
Link to this type packet()
packet() :: %{}

Link to this section Functions

Link to this function get_packet_mod(packet_type)
get_packet_mod(integer) :: {:ok, module} | :unknown_packet_type

Returns the module which contains functions to serialize/1, deserialize/1 and handle/1 the given packet_type.

Examples

iex> ExWire.Packet.get_packet_mod(0x00)
{:ok, ExWire.Packet.Hello}

iex> ExWire.Packet.get_packet_mod(0x10)
{:ok, ExWire.Packet.Status}

iex> ExWire.Packet.get_packet_mod(0xFF)
:unknown_packet_type
Link to this function get_packet_type(packet)
get_packet_type(struct) :: {:ok, integer} | :unknown_packet

Returns the eth id of the given packet based on the struct.

Examples

iex> ExWire.Packet.get_packet_type(%ExWire.Packet.Hello{})
{:ok, 0x00}

iex> ExWire.Packet.get_packet_type(%ExWire.Packet.Status{})
{:ok, 0x10}

iex> ExWire.Packet.get_packet_type(%ExWire.Struct.Neighbour{})
:unknown_packet

Link to this section Callbacks

Link to this callback deserialize(arg0)
deserialize(ExRLP.t) :: packet
Link to this callback serialize(packet)
serialize(packet) :: ExRLP.t