Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
464c77f
feat: implement basic proto file
OmegaCreations Jun 8, 2025
268a99a
feat: Duplex stream with specific payload message events.
OmegaCreations Jun 10, 2025
7b7888a
feat: Duplex stream with specific payload message events.
OmegaCreations Jun 10, 2025
6373548
feat: Create typescript interfaces for duplex stream message model
OmegaCreations Jun 10, 2025
255e567
feat: Add description to typescript interfaces
OmegaCreations Jun 10, 2025
7edca58
feat: implement serialization and deserialization methods
OmegaCreations Jun 10, 2025
0485204
feat: add package dependencies and write unit tests for serialization…
OmegaCreations Jun 10, 2025
58666d5
fix: fixed oneof variable naming
OmegaCreations Jun 10, 2025
0118271
feat: Duplex stream with specific payload message events.
OmegaCreations Jun 10, 2025
7c5d552
feat: Create typescript interfaces for duplex stream message model
OmegaCreations Jun 10, 2025
4b18459
feat: implement serialization and deserialization methods
OmegaCreations Jun 10, 2025
dba904c
feat: add package dependencies and write unit tests for serialization…
OmegaCreations Jun 10, 2025
273b8e2
feat: Create grpc wrapper with basic connection manager and central s…
OmegaCreations Jun 10, 2025
6467c55
fix: fix grpc addresses to properly connect both client and central s…
OmegaCreations Jun 10, 2025
1a86d49
fix: refactor comments
OmegaCreations Jun 11, 2025
bec195c
fix: change central system class name to avoid conflicts with central…
OmegaCreations Jun 11, 2025
c6a3f01
feat: implement Connection class and a map storing all receiving and …
OmegaCreations Jun 11, 2025
fb12e55
feat: implement replacing new token for client from central system
OmegaCreations Jun 11, 2025
63faee3
feat: implement token revokation by changing connection status
OmegaCreations Jun 11, 2025
456bf84
fix: remove unnecessary params
OmegaCreations Jun 11, 2025
93c3a51
fix: fix enum naming
OmegaCreations Jun 17, 2025
ff0faf0
fix: fix proto types order based on Bookkeeping standards
OmegaCreations Jun 17, 2025
d207f78
Merge branch 'feature/TKN/OGUI-1702/basic-proto-file' of github.com:A…
OmegaCreations Jun 17, 2025
fb6c39c
fix: add copyright banner
OmegaCreations Jun 17, 2025
8106fe1
Merge branch 'feature/TKN/OGUI-1702/basic-proto-file' of github.com:A…
OmegaCreations Jun 17, 2025
72042c8
fix: add copyright banner and change enum naming convention
OmegaCreations Jun 17, 2025
d762f9f
Merge branch 'feature/TKN/OGUI-1703/basic-typescript-interfaces' of g…
OmegaCreations Jun 17, 2025
b70cf9e
fix: fix serialization comments and tests
OmegaCreations Jun 17, 2025
aff4c59
Merge branch 'feature/TKN/OGUI-1704/data-serialization-utils' of gith…
OmegaCreations Jun 17, 2025
9de3ce5
Merge branch 'dev' into feature/TKN/OGUI-1703/basic-typescript-interf…
graduta Jun 18, 2025
bdba63d
feat: add description comments and implement .listen() instead of aut…
OmegaCreations Jul 8, 2025
326eea5
fix: change enum values to numbers
OmegaCreations Jul 8, 2025
4011499
Merge branch 'feature/TKN/OGUI-1703/basic-typescript-interfaces' of g…
OmegaCreations Jul 8, 2025
5857652
fix: move test directory
OmegaCreations Jul 8, 2025
54447ea
feat: add webui logger instead of console logs and fix paths
OmegaCreations Jul 8, 2025
af429ce
Merge branch 'feature/TKN/OGUI-1703/basic-typescript-interfaces' of g…
OmegaCreations Jul 8, 2025
9db612e
feat: write tests for central system and connection manager
OmegaCreations Jul 9, 2025
ec193ca
Merge branch 'feature/TKN/OGUI-1705/client-central-basic-stream' of g…
OmegaCreations Jul 9, 2025
d0f4dad
feat: muldularize connection management. Add project building.
OmegaCreations Jul 10, 2025
b4a0bf9
fix: fix connection and remove exponential backoff for simplified ver…
OmegaCreations Jul 10, 2025
3b49923
Fix: Unused function import
OmegaCreations Jul 13, 2025
8d9c89a
fix: test setup fixes
OmegaCreations Jul 20, 2025
1081941
Merge branch 'feature/TKN/OGUI-1708/basic-connection-class' of github…
OmegaCreations Jul 20, 2025
b6695a4
fix: fix tscofing for js builds and typescript files/tests runtime
OmegaCreations Jul 28, 2025
e79215c
feat: refactor code for command design pattern
OmegaCreations Aug 4, 2025
90d713d
feat: unit tests for token revokation
OmegaCreations Aug 4, 2025
e079438
feat: implement token revokation logic and testing
OmegaCreations Aug 5, 2025
5527944
feat: implement connection direction info inside of payload
OmegaCreations Aug 5, 2025
090da6b
fix: fix tests
OmegaCreations Aug 7, 2025
fd0e1dd
feat: implement command for new token from central system
OmegaCreations Aug 7, 2025
5965abe
feat: add missing comments, banners and tests
OmegaCreations Aug 7, 2025
4562762
fix: fixed banner processing. removed console logs
OmegaCreations Aug 7, 2025
1fd0579
fix: fix logging
OmegaCreations Aug 16, 2025
079d811
Merge branch 'feature/TKN/OGUI-1705/client-central-basic-stream' of g…
OmegaCreations Aug 16, 2025
99530a8
feat: change parameters to config objects
OmegaCreations Aug 16, 2025
5efb5ca
fix: fix deafult values in config
OmegaCreations Aug 16, 2025
ec36841
feat: add github actions for wrapper tests
OmegaCreations Aug 16, 2025
836ff51
fix: paths
OmegaCreations Aug 16, 2025
c61ac97
fix: pathing
OmegaCreations Aug 16, 2025
351099d
Merge branch 'feature/TKN/OGUI-1710/handle-newly-generated-token' of …
OmegaCreations Aug 16, 2025
ec8ea1a
fix: fix tests
OmegaCreations Aug 16, 2025
6ac9f71
feat: implement simple connection peer to peers
OmegaCreations Aug 27, 2025
5b759d8
fix: refactor ConnectionManager and remove unnecessary code.
OmegaCreations Aug 28, 2025
f49939a
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Aug 28, 2025
d43912a
fix: remove unused imports
OmegaCreations Aug 28, 2025
6ba86f2
fix: remove unnecessary utils
OmegaCreations Aug 31, 2025
2569c5c
fix: remove unused variable
OmegaCreations Aug 31, 2025
dd246bd
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Aug 31, 2025
21fb63e
fix: refactor unit tests
OmegaCreations Aug 31, 2025
957a7be
feat: update unit tests for p2p connections
OmegaCreations Aug 31, 2025
a7b81a2
Potential fix for code scanning alert no. 236: Unused variable, impor…
OmegaCreations Sep 2, 2025
b8edd56
feat: implement reconnection scheduler
OmegaCreations Sep 2, 2025
863438b
fix: fix scheduler
OmegaCreations Sep 3, 2025
542e0f6
fix: fix imports
OmegaCreations Sep 3, 2025
789afb6
Merge branch 'feature/TKN/OGUI-1705/client-central-basic-stream' of g…
OmegaCreations Sep 25, 2025
b866463
feat: implement secure connection and fix unit tests
OmegaCreations Sep 25, 2025
8c7bceb
feat: add testing certificates
OmegaCreations Sep 25, 2025
1ce0588
Potential fix for code scanning alert no. 252: Unused variable, impor…
OmegaCreations Sep 26, 2025
f41266f
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Nov 6, 2025
37a8021
fix: remove duplicates
OmegaCreations Nov 6, 2025
feeb637
fix: unit tests
OmegaCreations Nov 6, 2025
44f58e4
fix: move .gitignore to parent .gitignore
OmegaCreations Nov 6, 2025
c87f1f1
fix: default wrapper port changed to 4100
OmegaCreations Nov 6, 2025
b2f24c6
fix: change private variables naming
OmegaCreations Nov 6, 2025
d043717
fix: rename directories to start with small letters
OmegaCreations Nov 6, 2025
48c51dc
fix: fix imports and add breaklines after banners
OmegaCreations Nov 6, 2025
9ae5c9b
feat: inform about central system address on connection
OmegaCreations Nov 6, 2025
75a9f14
fix: tests testing initializtion of object shouuld have object creati…
OmegaCreations Nov 6, 2025
f6cb712
feat: implement missing descriptions
OmegaCreations Nov 6, 2025
d0c57bf
fix: make sure that proto file enums have number 0 with default, unde…
OmegaCreations Nov 6, 2025
3c82edc
feat: implement eslint and fix its errors
OmegaCreations Nov 6, 2025
6552480
Merge branch 'feature/TKN/OGUI-1710/handle-newly-generated-token' of …
OmegaCreations Nov 11, 2025
95ff34f
Merge branch 'feature/TKN/OGUI-1746/add-github-actions-for-wrapper' o…
OmegaCreations Nov 11, 2025
a253f51
fix: fix files, unit tests and add tests for connection
OmegaCreations Nov 12, 2025
866f599
fix: rebuild package lock
OmegaCreations Nov 12, 2025
b85554f
Merge branch 'dev' into feature/TKN/OGUI-1747/simple-client-p2p-conne…
OmegaCreations Nov 12, 2025
9d05309
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Nov 13, 2025
74af151
Merge branch 'feature/TKN/OGUI-1747/simple-client-p2p-connection' of …
OmegaCreations Nov 13, 2025
3d832ba
fix: fix rebase
OmegaCreations Nov 13, 2025
f0e4643
fix: tests, remove express, fix comments in gRPCWrapper
OmegaCreations Nov 13, 2025
baa9511
fix: tests
OmegaCreations Nov 13, 2025
6d658fb
feat: move peer listening to separate method and util file
OmegaCreations Nov 13, 2025
16a2ec6
fix: remove additional description
OmegaCreations Nov 13, 2025
b742ccc
Merge branch 'dev' into feature/TKN/OGUI-1747/simple-client-p2p-conne…
OmegaCreations Nov 13, 2025
0d22a81
Merge branch 'dev' into feature/TKN/OGUI-1747/simple-client-p2p-conne…
OmegaCreations Nov 16, 2025
1009225
Merge branch 'dev' into feature/TKN/OGUI-1747/simple-client-p2p-conne…
OmegaCreations Nov 18, 2025
a2d72da
Merge branch 'feature/TKN/OGUI-1747/simple-client-p2p-connection' of …
OmegaCreations Nov 18, 2025
3bbc627
feat: rebase, write tests for reconnection schaduler and fix it
OmegaCreations Nov 18, 2025
0eda640
Merge branch 'feature/TKN/OGUI-1754/create-reconnection-scheduler' of…
OmegaCreations Nov 20, 2025
3960bb1
fix: rebase and fix rebase and unit tests
OmegaCreations Nov 20, 2025
2526344
fix: binding in peerListener, imports and unit tests
OmegaCreations Nov 20, 2025
2e5061d
Merge branch 'dev' into feature/TKN/OGUI-1755/secure-connections-with…
OmegaCreations Nov 26, 2025
9237316
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Nov 27, 2025
0e256d6
fix: rebase
OmegaCreations Nov 27, 2025
0e1f7d4
Merge branch 'dev' into feature/TKN/OGUI-1755/secure-connections-with…
OmegaCreations Dec 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Tokenization/backend/wrapper/models/config.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

export interface CentralSystemConfig {
/** Path to the proto file defining the services. */
protoPath: string;
/** Host/IP to bind the gRPC server on. Defaults to "0.0.0.0" which is docker-friendly. */
host?: string;
/** Port to bind. Defaults to 50051. */
port?: number;
}

export interface gRPCWrapperConfig {
/** Path to the proto file defining the services. */
protoPath: string;
/** Address of the CentralSystem server. */
centralAddress: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import * as grpc from '@grpc/grpc-js';
import * as protoLoader from '@grpc/proto-loader';
import { LogManager } from '@aliceo2/web-ui';
import * as fs from 'fs';
import type { CentralSystemConfig } from '../models/config.model';
import type { DuplexMessageModel } from '../models/message.model';

/**
Expand All @@ -24,11 +26,15 @@ export class CentralSystemWrapper {
// Config
private _protoPath: string;

// Utilities
private _logger = LogManager.getLogger('CentralSystemWrapper');

// Class properties
private _server: grpc.Server;
private _port: number;

// Certificates paths
private _serverCerts: CentralSystemConfig['serverCerts'];

// Utilities
private _logger = LogManager.getLogger('CentralSystemWrapper');

// Clients management
private _clients = new Map<string, grpc.ServerDuplexStream<any, any>>();
Expand All @@ -38,8 +44,15 @@ export class CentralSystemWrapper {
* Initializes the Wrapper for CentralSystem.
* @param port The port number to bind the gRPC server to.
*/
constructor(protoPath: string, private port: number) {
this._protoPath = protoPath;
constructor(config: CentralSystemConfig) {
if (!config.protoPath || !config.serverCerts?.caCertPath || !config.serverCerts?.certPath || !config.serverCerts?.keyPath) {
throw new Error('Invalid CentralSystemConfig provided');
}

this._protoPath = config.protoPath;
this._serverCerts = config.serverCerts;
this._port = config.port ?? 50051;

this._server = new grpc.Server();
this.setupService();
}
Expand Down Expand Up @@ -115,7 +128,7 @@ export class CentralSystemWrapper {

// Handle stream error event
call.on('error', (err) => {
this._logger.infoMessage(`Stream error from client ${clientIp}:`, err);
this._logger.errorMessage(`Stream error from client ${clientIp}:`, err);
this.cleanupClient(peer);
});
}
Expand Down Expand Up @@ -168,10 +181,27 @@ export class CentralSystemWrapper {
* Starts the gRPC server and binds it to the specified in class port.
*/
public listen() {
const addr = `localhost:${this.port}`;
this._server.bindAsync(addr, grpc.ServerCredentials.createInsecure(), (err, _port) => {
const addr = `localhost:${this._port}`;

// Create mTLS secure gRPC server
const caCert = fs.readFileSync(this._serverCerts.caCertPath);
const centralKey = fs.readFileSync(this._serverCerts.keyPath);
const centralCert = fs.readFileSync(this._serverCerts.certPath);

const sslCreds = grpc.ServerCredentials.createSsl(
caCert,
[
{
private_key: centralKey,
cert_chain: centralCert,
},
],
true
);

this._server.bindAsync(addr, sslCreds, (err, _port) => {
if (err) {
this._logger.infoMessage('Server bind error:', err);
this._logger.errorMessage('Server bind error:', err);
return;
}
this._logger.infoMessage(`CentralSytem started listening on ${addr}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,35 @@ export class Connection {
* @param token - The authentication token for the connection.
* @param targetAddress - The unique address of the target client.
* @param direction - The direction of the connection (e.g., sending or receiving).
* @param peerCtor - The constructor for the gRPC client to be used for communication.
* @param caCertPath - Path to the CA certificate file.
* @param clientCertPath - Path to the client certificate file.
* @param clientKeyPath - Path to the client key file.
*/
constructor(token: string, targetAddress: string, direction: ConnectionDirection, peerCtor: any) {
constructor(
token: string,
targetAddress: string,
direction: ConnectionDirection,
peerCtor: any,
private readonly connectionCerts: {
caCert: NonSharedBuffer;
clientCert: NonSharedBuffer;
clientKey: NonSharedBuffer;
}
) {
this._token = token;
this._targetAddress = targetAddress;
this._peerClient = new peerCtor(targetAddress, grpc.credentials.createInsecure());
this.direction = direction;

if (!connectionCerts.caCert || !connectionCerts.clientCert || !connectionCerts.clientKey) {
throw new Error('Connection certificates are required to create a Connection.');
}

// Create grpc credentials
const sslCreds = grpc.credentials.createSsl(this.connectionCerts.caCert, this.connectionCerts.clientKey, this.connectionCerts.clientCert);

this._peerClient = new peerCtor(targetAddress, sslCreds);

this._status = ConnectionStatus.CONNECTED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@

import * as grpc from '@grpc/grpc-js';
import * as protoLoader from '@grpc/proto-loader';
import * as fs from 'fs';
import { CentralConnection } from './CentralConnection';
import { CentralCommandDispatcher } from './eventManagement/CentralCommandDispatcher';
import { Connection } from '../connection/Connection';
import { LogManager } from '@aliceo2/web-ui';
import type { Command, CommandHandler } from 'models/commands.model';
import type { DuplexMessageEvent } from '../../models/message.model';
import { ConnectionDirection } from '../../models/message.model';
import { ConnectionStatus } from '../../models/connection.model';
import { peerListener } from '../../utils/connection/peerListener';
import type { Command, CommandHandler } from 'models/commands.model';
import type { DuplexMessageEvent } from '../../models/message.model';

/**
* Manages the lifecycle and connection logic for a gRPC client communicating with the central system.
Expand All @@ -49,15 +50,23 @@ export class ConnectionManager {
private _peerServer: grpc.Server | undefined;
private _baseAPIPath: string = '';

// Client certificates
private _caCert: NonSharedBuffer;
private _clientCert: NonSharedBuffer;
private _clientKey: NonSharedBuffer;

/**
* Initializes a new instance of the ConnectionManager class.
*
* This constructor sets up the gRPC client for communication with the central system.
*
* @param protoPath - The file path to the gRPC proto definition.
* @param centralAddress - The address of the central gRPC server (default: "localhost:50051").
* @param caCertPath - Path to the CA certificate file.
* @param clientCertPath - Path to the client certificate file.
* @param clientKeyPath - Path to the client key file.
*/
constructor(protoPath: string, centralAddress: string = 'localhost:50051') {
constructor(protoPath: string, centralAddress: string = 'localhost:50051', caCertPath: string, clientCertPath: string, clientKeyPath: string) {
const packageDef = protoLoader.loadSync(protoPath, {
keepCase: true,
longs: String,
Expand All @@ -70,11 +79,18 @@ export class ConnectionManager {
this._wrapper = proto.webui.tokenization;
this._peerCtor = this._wrapper.Peer2Peer;

const client = new this._wrapper.CentralSystem(centralAddress, grpc.credentials.createInsecure());
// Read certs
this._caCert = fs.readFileSync(caCertPath);
this._clientCert = fs.readFileSync(clientCertPath);
this._clientKey = fs.readFileSync(clientKeyPath);

// Create grpc credentials
const sslCreds = grpc.credentials.createSsl(this._caCert, this._clientKey, this._clientCert);
const centralClient = new this._wrapper.CentralSystem(centralAddress, sslCreds);

// Event dispatcher for central system events
this._centralDispatcher = new CentralCommandDispatcher();
this._centralConnection = new CentralConnection(client, this._centralDispatcher, centralAddress);
this._centralConnection = new CentralConnection(centralClient, this._centralDispatcher, centralAddress);
}

/**
Expand Down Expand Up @@ -112,8 +128,28 @@ export class ConnectionManager {
* @param direction Direction of connection
* @param token Optional token for connection
*/
createNewConnection(address: string, direction: ConnectionDirection, token?: string) {
const conn = new Connection(token ?? '', address, direction, this._peerCtor);
public async createNewConnection(address: string, direction: ConnectionDirection, token?: string) {
let conn: Connection | undefined;

// Checks if connection already exists
conn = direction === ConnectionDirection.RECEIVING ? this._receivingConnections.get(address) : this._sendingConnections.get(address);

// Return existing connection if found
if (conn) {
if (token) {
conn.token = token;
}
return conn;
}

// Create new connection
conn = new Connection(token ?? '', address, direction, this._peerCtor, {
caCert: this._caCert,
clientCert: this._clientCert,
clientKey: this._clientKey,
});

conn.status = ConnectionStatus.CONNECTING;

if (direction === ConnectionDirection.RECEIVING) {
this._receivingConnections.set(address, conn);
Expand Down Expand Up @@ -158,7 +194,7 @@ export class ConnectionManager {
}

/** Starts a listener server for p2p connections */
public async listenForPeers(port: number, baseAPIPath?: string): Promise<void> {
public async listenForPeers(port: number, listenerKey: NonSharedBuffer, listenerCert: NonSharedBuffer, baseAPIPath?: string): Promise<void> {
if (baseAPIPath) this._baseAPIPath = baseAPIPath;

if (this._peerServer) {
Expand All @@ -169,11 +205,22 @@ export class ConnectionManager {
this._peerServer = new grpc.Server();
this._peerServer.addService(this._wrapper.Peer2Peer.service, {
Fetch: async (call: grpc.ServerUnaryCall<any, any>, callback: grpc.sendUnaryData<any>) =>
peerListener(call, callback, this._logger, this._receivingConnections, this._peerCtor, this._baseAPIPath),
peerListener(call, callback, this._logger, this._receivingConnections, this.createNewConnection.bind(this), this._baseAPIPath),
});

const sslCreds = grpc.ServerCredentials.createSsl(
this._caCert,
[
{
private_key: listenerKey,
cert_chain: listenerCert,
},
],
true
);

await new Promise<void>((resolve, reject) => {
this._peerServer?.bindAsync(`localhost:${port}`, grpc.ServerCredentials.createInsecure(), (err) => (err ? reject(err) : resolve()));
this._peerServer?.bindAsync(`localhost:${port}`, sslCreds, (err) => (err ? reject(err) : resolve()));
});

this._logger.infoMessage(`Peer server listening on localhost:${port}`);
Expand Down
47 changes: 42 additions & 5 deletions Tokenization/backend/wrapper/src/client/gRPCWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
* or submit itself to any jurisdiction.
*/

import * as fs from 'fs';
import { ConnectionManager } from './connectionManager/ConnectionManager';
import { RevokeTokenHandler } from './commands/revokeToken/revokeToken.handler';
import { ConnectionDirection, DuplexMessageEvent } from '../models/message.model';
import { NewTokenHandler } from './commands/newToken/newToken.handler';
import { LogManager } from '@aliceo2/web-ui';
import type { gRPCWrapperConfig } from '../models/config.model';
import type { Connection } from './connection/Connection';

/**
* @description Wrapper class for managing secure gRPC wrapper.
* Wrapper class for managing secure gRPC wrapper.
*
* @remarks
* This class serves as a high-level abstraction over the underlying
Expand All @@ -34,15 +37,39 @@ import type { Connection } from './connection/Connection';
*/
export class gRPCWrapper {
private _connectionManager: ConnectionManager;
private _listenerKey?: NonSharedBuffer;
private _listenerCert?: NonSharedBuffer;
private _logger = LogManager.getLogger('gRPCWrapper');

/**
* Initializes an instance of gRPCWrapper class.
*
* @param protoPath - The file path to the gRPC proto definition.
* @param centralAddress - The address of the central gRPC server (default: "localhost:4100").
*/
constructor(protoPath: string, centralAddress: string = 'localhost:4100') {
this._connectionManager = new ConnectionManager(protoPath, centralAddress);
constructor(config: gRPCWrapperConfig) {
if (
!config.protoPath ||
!config.centralAddress ||
!config.clientCerts?.caCertPath ||
!config.clientCerts?.certPath ||
!config.clientCerts?.keyPath
) {
throw new Error('Invalid gRPCWrapper configuration provided.');
}

if (config.listenerCertPaths?.keyPath && config.listenerCertPaths?.certPath) {
this._listenerKey = fs.readFileSync(config.listenerCertPaths.keyPath);
this._listenerCert = fs.readFileSync(config.listenerCertPaths.certPath);
}

this._connectionManager = new ConnectionManager(
config.protoPath,
config.centralAddress,
config.clientCerts.caCertPath,
config.clientCerts.certPath,
config.clientCerts.keyPath
);
this._connectionManager.registerCommandHandlers([
{
event: DuplexMessageEvent.MESSAGE_EVENT_REVOKE_TOKEN,
Expand Down Expand Up @@ -83,8 +110,18 @@ export class gRPCWrapper {
* @param baseAPIPath Optional base API path to forward requests to e.g. '/api'.
* @returns A promise that resolves when the p2p listener server is started.
*/
public async listenForPeers(port: number, baseAPIPath?: string): Promise<void> {
return this._connectionManager.listenForPeers(port, baseAPIPath);
public async listenForPeers(port: number, baseAPIPath?: string, listenerCertPaths?: { keyPath: string; certPath: string }): Promise<void> {
if (listenerCertPaths?.keyPath && listenerCertPaths?.certPath) {
this._listenerKey = fs.readFileSync(listenerCertPaths.keyPath);
this._listenerCert = fs.readFileSync(listenerCertPaths.certPath);
}

if (!this._listenerKey || !this._listenerCert) {
this._logger.errorMessage('Listener certificates are required to start P2P listener. Please provide valid paths.');
return;
}

return this._connectionManager.listenForPeers(port, this._listenerKey, this._listenerCert, baseAPIPath);
}

/**
Expand Down
Loading