Code Monkey home page Code Monkey logo

p2p's Introduction

Introduction

This is an experimental work to build a unstructured P2P network using Java and Netty.

It has following capabilities:

  • Join to the P2P network
  • Leave the network
  • List peers in the network
  • Leader election

P2P network is unstructured. Once a peer is started, it can join by connecting to any of the peers in the network.

To maintain connectivity of the P2P network, each peer connects to more than one peer in the network randomly.

Peers send periodic keep alive messages to their neighbours to notify them about their presence. If a peer does not receive a message from a neighbour for a configured amount of time, it drops the connection.

A peer can discover other peers in the network with a Ping-Pong process by sending a Ping message to its neighbours and waiting for the Pong messages for some time. This message also contains how many hops it can go over the network. When a peer receives a Ping message from a neighbour, it replies with a Pong message and dispatches the Ping message to its own neighbours after decreasing the hop count.

This mechanism is a very basic implementation of the Ping-Pong mechanism described in the Gnutella P2P network protocol v0.4. To read more about Gnutella, please see The Annotated Gnutella Protocol Specification v0.4 and Gnutella Wikipedia.

In the image below, you can see a Ping-Pong flow.

Ping Pong

It also implements Bully Algorithm for leader election. Since bully algorithm assumes a fully connected network under the hood, it is users' responsibility to create a connection between each peer before running the election.

All network messages are sent with a fire-and-forget manner without any acknowledgement or retry system.

You can see available configuration options in Config class. Main class is also here.

Build

This is a very simple Maven project which requires Java 8.

It can be compiled with mvn clean compile and final jar can be produced with mvn clean package.

Run

You can start a peer by starting a java process with the produced jar file as follows:

java -jar -DpeerName=Peer1 p2p.jar -n Peer1 -b 50670

This command starts a peer with name Peer1 and binds it to port 50670. It is the user's responsibility to guarantee uniqueness among names of the peers.

-DpeerName=... is not necessary if you change default logging configuration of the project.

After starting the peer, you can type help to see available commands.

Contribution is welcomed

This project is only tested by starting peers in terminal and creating connections among them. Therefore, unit tests and integration tests are welcomed.

p2p's People

Contributors

metanet avatar

Watchers

 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.