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
handle_response()
handle_response :: :ok | :activate | :peer_disconnect | {:disconnect, atom} | {:send, struct}
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