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
- 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).
- 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.
- The last endpoint will reflect the status of the network, returning a list of encoded strings.
see more details about the implementation on wiki
- 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
.
POST /join
- Request body
{
"id": 1,
"capacity": 2,
}
- Response
{
"message":"successfully joined",
"error":false,
"data":1
}
DELETE /leave/1
- Response
{
"message":"successfully left",
"error":false,
"data":1
}
GET /trace
- Response
{
"message":"trace received",
"error":false,
"data":["1(0/2)"]
}
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 |
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
Followed clean architecture to organize the code.