This project consists of two main components: node-client
and node-coordinator
. The goal is to synchronize the clocks of multiple node-client
instances using a node-coordinator
.
node-client/ ├── clock-endpoints.js ├── clock.js ├── Dockerfile ├── index.js ├── logs.js ├── package.json └── public/ ├── index.html └── index.js
node-coordinator/ ├── .env ├── clients-endpoints.js ├── index.js ├── logs.js ├── package.json └── public/ ├── index.html ├── index.js └── socket-server.js
-
Open the
.env
file in thenode-coordinator
folder and change the IP to your machine's IP address. -
Open the
index.js
file in thenode-coordinator/public
folder and replace the IP with your machine's IP address:fetch('http://your_ip:5000/createInstance') fetch('http://your_ip:5000/syncNodes', { method: 'PUT' })
-
Navigate to the
node-client
folder:cd node-client
-
Build the Docker image:
docker build -t node-client .
-
Navigate to the
node-coordinator
folder:cd node-coordinator
-
Install dependencies and start the server:
npm install npm start
Open your browser and go to http://your_ip:5000
to view the node-coordinator
interface.
- node-client: Provides endpoints to get and update the clock of each instance.
- node-coordinator: Coordinates clock synchronization across multiple
node-client
instances.
GET /clock
: Retrieves the current time of the clock.PUT /clock
: Updates the clock with a specified adjustment.
POST /clients
: Registers a new client.GET /createInstance
: Creates a newnode-client
instance.PUT /syncNodes
: Synchronizes the clocks of all registered instances.
- Ensure that Docker is installed and running on your machine.
- Make sure the configured IP addresses are accessible on your network.