Skip to content

astrberg/d7024e-kademlia

 
 

Repository files navigation

d7024e-kademlia

Running

Compose

There are two variants of the services, dev (development) and prod (production). The dev service supports hot reloading (whereas prod does not) but has a larger image size than the prod variant. What variant is used can be specified by passing either docker-compose-dev.yml or docker-compose-prod.yml to the relevant <compose-file> option.

To run one or more node using compose run

docker-compose -f <compose-file> up --build --scale kademlia=10

Swarm

Make sure you have a cluster initialized by running

docker swarm init

Then run

docker stack deploy --compose-file <compose-file> kademlia

Initilizing the nodes

To initilize the nodes running in the containers once you have a single or multiple containers running can be done by executing the following script

sh scripts/init-cluster.sh

This script makes sure that every node except one has the same known node in its routing table (the known node is the only member of the Kademlia network at this point) each node then joins the network, one at a time, using the known node.

Executing commands

Any node can told to execute any command by running the following

docker exec -ti <container-name/id> kademliactl <command>

REST API

All nodes support the following REST API,

Method: GET, endpoint: /objects/{hash}/:

The {hash} portion of the HTTP path is to be substituted for the hash of the object. A successful call should result in the contents of the object being responded with.

Example:

curl <container-ip>:8080/objects/<hash>
Method: POST, endpoint: /objects:

Each message sent to the endpoint must contain a data object in its HTTP body. If the operation is successful, the node will reply with 201 CREATED containing both the contents of the uploaded object and a Location: /objects/{hash} header, where {hash} will be substituted for the hash of the uploaded object.

Example:

curl -X POST <container-ip>:8080/objects -d "<content>"

Setting log level

The containers source the log level from the LOG_LEVEL variable in the current environment. This variable can be set in either the file .env in project root, or directly through the command line as such:

LOG_LEVEL=<log_level> docker-compose up ...

See zerolog documentation for available levels.

Testing

Tests can be run and coverage generated by running

go test ./... -coverprofile=coverage.out

The total coverage can then be seen by running

go tool cover -func coverage.out

About

P2P Distributed Data Store

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.8%
  • Other 1.2%