Create a system where multiple clients generate unique prime numbers and add them to a shared pool managed by a server. The communication between clients and server happens via TCP, and each client signs the prime numbers to ensure they come from a trusted source.
-
Server:
- Maintains a shared pool of prime numbers.
- Verifies the uniqueness of received prime numbers.
- Keeps track of which client sent which prime number.
- Implements a signature verification mechanism.
- Supports multiple clients concurrently.
- Implements Round Robin mechanism (optional).
-
Clients:
- Generate unique prime numbers continuously.
- Generate a private/public key pair for signing messages.
- Send public key to the server upon connection.
- Sign each prime number before sending to the server.
- Supports optional Round Robin communication.
- src/
- main.ts: Entry point of the application.
- app.module.ts: Root module.
- client/: Client module and service.
- server/: Server service.
- util/: Helper functions and configuration.
- test/: Contains unit and E2E tests.
- Node.js (version 14 or higher)
- npm package manager
- Docker (optional, for containerization)
-
Clone the repository:
git clone https://github.com/yourusername/prime-number-pooling.git
-
Navigate to the project directory:
cd prime-number-pooling
-
Install dependencies:
npm install
-
Build the application:
npm run build
-
Start the application:
npm run start:prod
Or, for development with watch mode:
npm run start:dev
-
Build the Docker image:
docker build -t prime_app .
-
Run the Docker container:
docker run -p 3000:3000 prime_app
Or, using Docker Compose:
docker-compose up --build
Run unit tests using Jest: -> npm run test
Run E2E tests: -> npm run test:e2e
Application configurations can be adjusted in the AppConfig
class located at src/util/config/appConfig.ts
.
- host: Server host (default: '127.0.0.1')
- port: Server port (default: 3000)
- clientCount: Number of clients to spawn.
- primeLimit: Total number of prime numbers to collect before stopping.
- useRoundRobin: Enable or disable Round Robin mechanism.
- clientPingInterval: Interval for client ping messages.
- primeGenerationInterval: Interval between prime number generations.
The application uses NestJS's built-in logging mechanism. Logs for client and server activities are output to the console.
- Node.js
- NestJS
- TypeScript
- Crypto module for key generation and signing
- Jest for testing
- Docker for containerization
This project is licensed under the MIT License - see the LICENSE file for details.