ex_wire v0.1.1 ExWire.Adapter.TCP
Starts a TCP server to handle incoming and outgoing RLPx, DevP2P, Eth Wire connection.
Once this connection is up, it’s possible to add a subscriber to the different packets that are sent over the connection. This is the primary way of handling packets.
Note: incoming connections are not fully tested at this moment. Note: we do not currently store token to restart connections (this upsets some peers)
Link to this section Summary
Functions
Allows a client to subscribe to incoming packets. Subscribers must be in the form
of {module, function, args}, in which case we’ll call module.function(packet, ...args),
or {:server, server_pid} for a GenServer, in which case we’ll send a message
{:packet, packet, peer}
If we receive a send and we have secrets set, we’ll send the message as a framed Eth packet
Handle info will handle when we have inbound communucation from a peer node
Initialize by opening up a gen_tcp connection to given host and port
Client function to send HELLO message after connecting
Client function for sending a packet over to a peer
Starts an outbound peer to peer connection
Client function to subscribe to incoming packets
Link to this section Functions
Allows a client to subscribe to incoming packets. Subscribers must be in the form
of {module, function, args}, in which case we’ll call module.function(packet, ...args),
or {:server, server_pid} for a GenServer, in which case we’ll send a message
{:packet, packet, peer}.
If we receive a send and we have secrets set, we’ll send the message as a framed Eth packet.
However, if we haven’t yet sent a Hello message, we should queue the message and try again later. Most servers will disconnect if we send a non-Hello message as our first message.
Handle info will handle when we have inbound communucation from a peer node.
If we haven’t yet completed our handshake, we’ll await an auth or ack message as appropriate. That is, if we’ve established the connection and have sent an auth message, then we’ll look for an ack. If we listened for a connection, we’ll await an auth message.
TODO: clients may send an auth before (or as) we do, and we should handle this case without error.
Initialize by opening up a gen_tcp connection to given host and port.
We’ll also prepare and send out an authentication message immediately after connecting.
Client function to send HELLO message after connecting.
Client function for sending a packet over to a peer.
Starts an outbound peer to peer connection.
subscribe(pid, {module, atom, list} | {:server, pid}) :: :ok
Client function to subscribe to incoming packets.
A subscription should be in the form of {:server, server_pid}, and we will
send a packet to that server with contents {:packet, packet, peer} for
each received packet.