alexdovzhanyn / elixium_core

A privacy-preserving decentralized application network
https://www.elixiumnetwork.org/
281 stars 37 forks source link

Implement p2p #44

Closed alexdovzhanyn closed 6 years ago

alexdovzhanyn commented 6 years ago

This fixes #6 by implementing a peer-to-peer network.

I've written a pretty simple binary protocol that peers can use to communicate with each other, called "Ghost". There's a whitepaper / spec for the protocol that'll be posted soon, but the most important things to note about the protocol are:

Peer Initialization

When a peer is started, it needs to connect to the network. There are a few ways a peer can go about connecting to the rest of the Elixium network, first it spawns 10 processes that are connection handlers, then:

  1. If it is the first time the peer has ever started, it will reach out to the bootstrapping server, and will receive a list of IP addresses of peers already within the network. It will attempt a connection to some of these peers. For each of the successful connections it makes, it stores the IP address locally, so that it can re-connect to that peer in the future.

  2. If the peer has been started before, it will first check its local registry of peers and try to connect to them.

Each (if any) of the handlers that don't successfully connect to a peer will set up a listener, and allow other peers to connect to them.