Giter Site home page Giter Site logo

simple-p2p-network's Introduction

Simple p2p network

This is a simple p2p network that uses a blockchain to store data. It is a simple implementation of a blockchain and is not intended to be used in production. I use this project to learn about blockchain and p2p networks.

Consensus

In this project, I use snowball consensus algorithm to reach consensus. Snowball is a consensus algorithm that is used in the avalanche protocol. It is a probabilistic consensus algorithm that is used to reach consensus in a p2p network. It is a simple algorithm that is easy to implement and understand. It is also a good algorithm to use to learn about consensus algorithms.

Network

In the p2p network, each node will choose some nodes as their neighbors

             +------+
    +------->+ node +<------+
    |        +------+       |
    |                       |
    v                       v
+---+--+                 +--+---+
| node |                 | node |
+---+--+                 +--+---+
    ^                       ^
    |                       |
    |        +------+       |
    +------->+ node +<------+
             +------+

Peer

A peer is a node in the network. Each peer has a blockchain and a list of neighbors. The blockchain is used to store data and the neighbors are used to communicate with other peers. We use gRPC to communicate between peers. Each peer has a gRPC server that listens for requests from other peers. Each peer also has a gRPC client that is used to send requests to other peers.

                                gRPC
                                  |
                                  v       +----+
                       +-----connection-->+peer|
                       |                  +----+
                       |
                       |
                       |
                   +---+--+               +----+
+----Service---+-->+ node +--connection-->+peer|
|PeerManager   |   +---+--+               +----+
|MessageManager|       |
+--------------+       |
                       |
                       |                  +----+
                       +-----connection-->+peer|
                                          +----+

Build and run

To build and run the project, you need to have go installed on your machine. You can download go from here.

To build the project, run the following command in the root directory of the project

go build -o build/startnode cmd/startnode/main.go

To run the project, run the following command in the root directory of the project

./build/startnode -port 5000 -neighbors localhost:5001,localhost:5002

simple-p2p-network's People

Contributors

ponlv avatar

Watchers

 avatar  avatar

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.