Skip to content

Uzama/p2p-network-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

P2P Network Simulator

A REST API application to simulate a p2p network with a tree topology. Following are the endpoints to interact with the program using HTTP calls

  1. The first one is where a node can request to join the p2p network. In this step we just assign the node to the best-fitting parent (the node with the most free capacity).
  2. With the second endpoint, the node can communicate to the service that it is leaving the network. In this case, we want to reorder the current node tree (not all the network) to build the solution where the tree has the fewest number of depth levels.
  3. The last endpoint will reflect the status of the network, returning a list of encoded strings.

see more details about the implementation on wiki

How to start

  • Make sure you have installed latest version of docker and docker engine is up and running.
  • Clone the service locally and navigate to project root directory.
  • To run the service, type docker compose up and enter.
  • Make sure service is up and running.
  • Now you can send request to the service at localhost:8080.

API Reference

Join

  POST /join
  • Request body
    {
        "id": 1,
        "capacity": 2,
    }
  • Response
    {
        "message":"successfully joined",
        "error":false,
        "data":1
    }

Leave

  DELETE /leave/1
  • Response
    {
        "message":"successfully left",
        "error":false,
        "data":1
    }

Trace

  GET /trace
  • Response
    {
        "message":"trace received",
        "error":false,
        "data":["1(0/2)"]
    }  

Status Codes

Service returns the following status codes in its API:

Status Code Description
200 OK
201 CREATED
202 ACCEPTED
400 BAD REQUEST
422 UN PROCESSABLE ENTITY

Unit Tests

To see unit test overall coverage and the coverage of each function, run the following commands

    go test -coverprofile unite-test-cover.out ./...
    go tool cover -func unite-test-cover.out

Coding Standards

Followed clean architecture to organize the code.