Code Monkey home page Code Monkey logo

gladius-p2p's People

Contributors

code-merc avatar overtfuture avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gladius-p2p's Issues

Gladius P2P Proposal

Gladius P2P Module Proposal

Gladius is looking to implement our own peer to peer networking solution for our application, we've used others previously that haven't quite fit our needs and we've decided to build our own. Below is a proposal on how we think this should be designed, but we welcome feedback as this isn't just going to be a project for our code, but a general purpose library that other developers can build on top of to create their applications. We've taken inspiration from the Perlin Network's library Noise, so we would like to credit them for some of the design philosophy behind this.

Philosophy

The Gladius P2P Module is going strive to be as agnostic to the purpose of the p2p network as possible. This means we won't be enforcing any type of signature technology, any addressing, or any message structure beyond what is absolutely needed.

Design

Messages

The core of the library will be minimalistic messages. Each message is only required to have a sender, a type, a message, and a checksum field. The message body is left up to the user of the library, and can be signed or unsigned, can be any encoding, or can replicate those fields to be later confirmed by checking the signature.

API

From an API perspective we really enjoyed using Noise, and so we want to continue some of that design in our own application, but obviously with the changes seen in this document.

We're planning on having the below methods to interact with the the network.

Broadcast(message) - Broadcast to all known peers

Broadcast(message, peers...) - Broadcast to these peers specifically

BroadcastRandomly(message, n) - Broadcast to n random peers, useful for anti entropy syncs.

Add(nodeAddress) - Adds a node to the route table

Delete(nodeAddress) - Deletes a node from the route table

NetworkState() - Gets present network state object

RegisterPlugin(plugin) - Registers a user plugin

Listen(address) - Will listen on this address for incoming messages.

Plugins

Every message will be passed to every plugin the user registers, and can be processed based on the type of the incoming message. In our case we will be building a discovery plugin, a latency audit plugin, and a state plugin that uses our existing signature system built on top of Ethereum keys.

We're planning on making the plugin interface look like this, keep in mind that all functions will have access to the network API from above:

NodeAdded(nodeAddress) - Will be called when the network adds a node, this could be through a explicit call to Add by the user or could be from a plugin.

NodeDeleted(nodeAddress) - Could be useful for cleanup, called under same circumstances as NodeAdded

NewMessage(message) - Called when any new message is received by the peer.

Startup() - Called when plugin is initialized

Close() - Called when the network is closed, or plugin is removed.

You can see how something like peer discovery could be built on top of a structure like this, when the first node is added or the network is started, the discovery plugin could reach out to all of the peers it knows and start to send messages to them. The same goes for a state plugin.

Networking

Our code will simply maintain a list of peers and streams, some are writable by default and some are not (this is to allow for potentially unauthorized connections to not be written to unless a plugin specifically wants to). These streams can all be written to by the API exposed above. This gives the developer the flexibility to build most of their discovery as well as message signature systems without having to worry about the networking. We're planning on using KCP to handle the transmission, it will allow us to have fast communication with low overhead, strong encryption support, and the ability to have good reliability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.