ex_wire v0.1.1 ExWire.Message.Neighbours

A wrapper for ExWire’s Neighbours message.

Link to this section Summary

Functions

Decodes a given message binary, which is assumed to be an RLP encoded list of elements

Given a Neighbours message, encodes it so it can be sent on the wire in RLPx

Callback implementation for ExWire.Message.message_id/0

Neighbours messages do not specify a destination

Link to this section Types

Link to this type t()
t() :: %ExWire.Message.Neighbours{nodes: [ExWire.Struct.Neighbour.t], timestamp: integer}

Link to this section Functions

Link to this function decode(data)
decode(binary) :: t

Decodes a given message binary, which is assumed to be an RLP encoded list of elements.

Examples

iex> ExWire.Message.Neighbours.decode([
...>   [],
...>   2
...> ] |> ExRLP.encode)
%ExWire.Message.Neighbours{
  nodes: [],
  timestamp: 2,
}

iex> ExWire.Message.Neighbours.decode([
...>   [[<<1,2,3,4>>, <<>>, <<5>>, <<7, 7>>]],
...>   2
...> ] |> ExRLP.encode)
%ExWire.Message.Neighbours{
  nodes: [%ExWire.Struct.Neighbour{endpoint: %ExWire.Struct.Endpoint{ip: [1,
          2, 3, 4], tcp_port: 5, udp_port: nil}, node: <<7, 7>>}],
  timestamp: 2,
}

iex> ExWire.Message.Neighbours.decode([
...>   [[<<1,2,3,4>>, <<>>, <<5>>, <<7, 7>>], [<<5,6,7,8>>, <<6>>, <<>>, <<8, 8>>]],
...>   2
...> ] |> ExRLP.encode)
%ExWire.Message.Neighbours{
  nodes: [
    %ExWire.Struct.Neighbour{endpoint: %ExWire.Struct.Endpoint{ip: [1, 2, 3, 4], tcp_port: 5, udp_port: nil}, node: <<7, 7>>},
    %ExWire.Struct.Neighbour{endpoint: %ExWire.Struct.Endpoint{ip: [5, 6, 7, 8], tcp_port: nil, udp_port: 6}, node: <<8, 8>>}
  ],
  timestamp: 2,
}

iex> ExWire.Message.Neighbours.decode([1] |> ExRLP.encode)
** (MatchError) no match of right hand side value: [<<1>>]
Link to this function encode(neighbours)
encode(t) :: binary

Given a Neighbours message, encodes it so it can be sent on the wire in RLPx.

Examples

iex> ExWire.Message.Neighbours.encode(%ExWire.Message.Neighbours{nodes: [], timestamp: 1})
...> |> ExRLP.decode()
[[], <<1>>]

iex> ExWire.Message.Neighbours.encode(%ExWire.Message.Neighbours{nodes: [
...>   %ExWire.Struct.Neighbour{endpoint: %ExWire.Struct.Endpoint{ip: [1, 2, 3, 4], tcp_port: 5, udp_port: nil}, node: <<7, 7>>},
...>   %ExWire.Struct.Neighbour{endpoint: %ExWire.Struct.Endpoint{ip: [5, 6, 7, 8], tcp_port: nil, udp_port: 6}, node: <<8, 8>>}],
...>   timestamp: 1})
...> |> ExRLP.decode()
[[[<<1,2,3,4>>, <<>>, <<0, 5>>, <<7, 7>>], [<<5,6,7,8>>, <<0, 6>>, <<>>, <<8, 8>>]], <<1>>]

Callback implementation for ExWire.Message.message_id/0.

Link to this function to(message)
to(t) :: Endpoint.t | nil

Neighbours messages do not specify a destination.

Examples

iex> ExWire.Message.Neighbours.to(%ExWire.Message.Neighbours{nodes: [], timestamp: 1})
nil