Giter Site home page Giter Site logo

thedenisnikulin / poc_p2p_blockchain_project Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 70 KB

Proof-of-Concept Peer-to-Peer Blockchain Network built with sockets

License: MIT License

Python 100.00%
blockchain socket-programming threading python3 p2p socket

poc_p2p_blockchain_project's Introduction

PoC P2P Blockchain Network

I like the idea of bitcoin and blockchain. This is a basic proof-of-concept blockchain that I've built. It is based on a peer-to-peer decentralized TCP network.

Warning! It is working only on Windows for now.

Table of contents

  1. Description
  2. Features
  3. Technologies used
  4. How to use

Description

Class structure

  • Blockchain
  • Block
  • Transaction
  • Server
  • Client
  • SuperPeer
  • Peer

The P2P network is based on Client and Server classes.

  • Server:
  1. waits for client to connect,
  2. accepts connection,
  3. adds client to list of clients (= list of peers),
  4. broadcasts the list to all the clients (lets clients know about new client),
  5. listens to client messages
  • Client:
  1. connects to the server
  2. lets user interact with the program logic (i.e. blockchain and networking)
  3. listens to server messages

The core logic lies in two concepts: Peer and SuperPeer

Peer - a classic peer, it's just a client
SuperPeer - a super peer, it's both client and server

How it all works together

  1. first, program becomes a Peer
  2. it tries to connect to the SuperPeer by public address, which is stored in server_tracker.txt
  3. if connection is established successfully, it remains Peer
  4. if it can't connect to the SuperPeer for some reason (most likely there's no SuperPeer to connect to), it becomes a SuperPeer itself and stores its address in server_tracker.txt for other peers to connect

If something is not clear for you, check out the source code. I tried to write as much comments as possible to make it easier to understand.


Features

  • Self-repairing network. When SuperPeer disables/disconnects, one of peers becomes SuperPeer, which makes it impossible to stop the network.
  • Persistent state. Blockchain saves its state across all peers even when SuperPeer disconnects.
  • Data broadcasting. All the data is broadcasted between peers.
  • CLI interface. A convenient interface built with PyInquirer.
  • Blockchain implementation. This blockchain implementation is similar to original Bitcoin's blockchain, but I simplified some stuff.

Technologies used

  • Data serialization - pickle
  • CLI interface - PyInquirer
  • Parallelism - threading
  • Networking - socket
  • Hashes - hashlib

How to use

  • Download project
git clone https://github.com/thedenisnikulin/poc_p2p_blockchain_project.git
  • Install dependencies
pip install -r ./requirements.txt
  • Run
python src/main.py

poc_p2p_blockchain_project's People

Contributors

thedenisnikulin avatar

Stargazers

 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.