Giter Club home page Giter Club logo

centralizedp2p's Introduction

CentralizedP2P

Python version: 3.8.6

A simple program to run a centralized peer-to-peer architecture using sockets and HTTP REST.

Dependencies

It is recommended to use pyenv for managing your python versions.

To install all dependencies related to this project, it is recommended to create a virtual environment and use the requirements.txt file present at this repo. To achieve such goal, run:

# at CentralizedP2P/

# virtual environment
$ python -m venv venv
$ . venv/bin/activate

# install
$ pip install -r requirements.txt

Execution

To execute this program, first you need to start the centralized server for this P2P architecture. To achieve this, run:

# at CentralizedP2P/

$ python src/server.py

Then you can start peers to communicate with the centralized server and between each other. To achieve this, run:

# at CentralizedP2P/

$ python src/server.py <peer_ip:ipv4> <server_ip:ipv4> <action_port:int> <listen_port:int>

Field 'action_port' refers to the port that is used by peer's CLI (main thread).

Field 'listen_port' refers to the port that listens to socket requests (runs in a separated thread).

REST routing

To communicate with the centralized server all peers utilize REST calls with the same format, shown below:

/resource

GET: Retrieve every peer's info registered at database.

# request body
{}

GET: Retrieve peer's info that contains such resource.

# request body
{
    "resource_name": "test.csv"
}

POST: Assign a new resource to a peer.

# request body
{
	"peer_id": "42bb7fb8-8f8d-4c1c-b4df-d97c2e78eb7c",
	"peer_ip": "127.0.0.1",
	"peer_port": 3000,
	"resource_name": "test.csv",
	"resource_path": "./tests",
	"resource_hash": "dea311be2ca928ae1d6ba5ab28b53c60"
}

/heartbeat

POST: Tell server that peer still alive.

{
    "peer_id": "42bb7fb8-8f8d-4c1c-b4df-d97c2e78eb7c"
}

Project architecture

The base architecture is shown below:

image

centralizedp2p's People

Contributors

gabrielcastrosilva avatar henriquekops avatar possebas 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.