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
Make sure you have a cluster initialized by running
docker swarm init
Then run
docker stack deploy --compose-file <compose-file> kademlia
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.
Any node can told to execute any command by running the following
docker exec -ti <container-name/id> kademliactl <command>
All nodes support the following REST API,
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>
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>"
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.
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