# Aggregator node

This is the version matching the final requirements where the client are started from the policy execution

## Running the code using Docker

1. To create the Docker Image, run "Dockerfile" using this command: `docker build -f Dockerfile -t server-image .`
2. Create a container from the above image using this command: `docker run -p 8080:8080 -p 5000:5000 -e FLWR_PORT={flwr_port} -e DMLO_PORT={dmlo_port} --name server --rm server-image`
3. The script for the Agg.Node will run automatically, the other nodes will await the Agg.Node if they are started first.

* **Notes**:
- `flwr_port` is the port number that will be used to communicate with the clients on the flower level (8080 for tests).
- `dmlo_port` is teh port number that will be used to communicate with the dmlo (5000 for tests).
- The `-p` flag is used to map the docker ports to the devices ports and should be changed according to the ports used in the simulation (currently set to ports 8080 and 5000).
- The execution can be stopped by opening another terminal and using this command `docker kill server`.
- The "Example files" directory contains examples for json files to be sent to the server. (The list of client IDs sent to the server should be a list of strings and not integers, see the example json file)

* **Below are helper shell commands to simulate server functions triggered by the DMLO (if needed):**

- To send the param file to the server:
`curl -X POST -H "Content-Type: application/json" -d @{file_name}.json {server_ip}:5000/config_server`
- To send the list of eligible clients to the server:
`curl -X POST -H "Content-Type: application/json" -d @{file_name}.json {server_ip}:5000/select_clients`
- To terminate the training:
`curl -X POST -d "" {server_ip}:5000/terminate_app`
