wharfkit / antelope

Core types, client interfaces, and other tools for working with Antelope-based blockchains.
Other
44 stars 23 forks source link

Add P2P protocol types and client #51

Closed wanderingbort closed 1 year ago

wanderingbort commented 1 year ago

This PR adds the wire types for the antelope P2P protocol as well as a basic client that can send P2P messages and an automated heartbeat (if desired).

Since there is no shared "socket" implementation between browsers and node environments, the client expects implementors to provide an implementation for the P2PProvider interface. This interface matches the node Socket type. However, the antelope P2P protocol over a TCP connection can arrive in-order but fragmented. There is a utility class provided that accepts/produces envelopes in the antelope P2P over TCP format and handles re-assembly.

A node specific example looks like this :

const socket = new Socket();
socket.connect(...);

const provider = new SimpleEnvelopeP2PProvider(socket);
const client = new P2PClient({provider});

client.on('message', (m:P2P.NetMessage) => {
   ...
});

client.send(P2P.HandshakeMessage.from({
   ...
});
aaroncox commented 1 year ago

This is quite awesome!

I spent some time this morning before my first meeting just experimenting with the code and connecting with our public p2p nodes. I managed to get connected, handshaking, then syncing/deserializing a handful of blocks in less than 30 minutes.

The possibilities this sort of connectivity offers from a JS context has my head spinning a bit, in the best way possible! Look forward to reviewing this more, and getting @jnordberg's perspective on it as well.

wanderingbort commented 1 year ago

Thanks for the pointer to the browser tests @jnordberg they are green now 😄

wanderingbort commented 1 year ago

I see the prettier failures... on it

jnordberg commented 1 year ago

Still had some Buffer references left, took the liberty to fix them. This is good to merge once you merge in my PR to your PR :D https://github.com/wanderingbort/eosio-core/pull/1

jnordberg commented 1 year ago

Published in version 0.6.9