Skip to content

Commit

Permalink
refactor: references to cloud agent to mediator
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
genaris committed Jan 27, 2025
1 parent 024285d commit 7c37578
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 138 deletions.
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

## Configuration

### Mediator

### Environment variables

At the moment, all configuration is done by environment variables. All of them are optional

| Variable | Description | Default value |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------- |
| AGENT_NAME | Label to show to other DIDComm agents | Test Cloud Agent |
| AGENT_NAME | Label to show to other DIDComm agents | Test DIDComm Mediator |
| AGENT_ENDPOINTS | Comma-separated public endpoint list where agent DIDComm endpoints will be accessible (including protocol and port) | ws://localhost:4000 |
| AGENT_PUBLIC_DID | Agent's public DID (in did:web format) | None |
| AGENT_PORT | Port where DIDComm agent will be running | 4000 |
| AGENT_LOG_LEVEL | Agent log level | 2 (debug) |
| HTTP_SUPPORT | Enable support of incoming DIDComm messages through HTTP transport | true |
| WS_SUPPORT | Enable support of incoming DIDComm messages through WebSocket transport | true |
| WALLET_NAME | Wallet (database) name | test-cloud-agent |
| WALLET_KEY | Wallet base encryption key | 'Test Cloud Agent' |
| WALLET_NAME | Wallet (database) name | test-didcomm-mediator |
| WALLET_KEY | Wallet base encryption key | 'Test DIDComm Mediator' |
| KEY_DERIVATION_METHOD | Wallet key derivation method | ARGON2I_MOD |
| POSTGRES_HOST | PosgreSQL database host | None (use SQLite) |
| POSTGRES_USER | PosgreSQL database username | None |
Expand All @@ -29,13 +30,29 @@ At the moment, all configuration is done by environment variables. All of them a

These variables might be set also in `.env` file in the form of KEY=VALUE (one per line).

### Message Pickup modes

This apps supports a flexible configuration for Message Pickup repositories, allowing users to choose between different persistence methods depending on their needs. This enhancement provides seamless integration with the following repository options:

- **MessagePickupRepositoryClient**: A WebSocket-based repository for distributed environments. It requires a specific server
- **PostgresMessagePickupRepository**: A PostgreSQL-based repository for persistent storage. It is meant for simplicity, so it uses the same Postgres host than mediator's wallet.
- **InMemoryMessagePickupRepository**: An in-memory repository for lightweight setups or testing purposes. It only works when SQLite is used for mediator wallet.

### How to configure

The repository configuration is controlled by these environment variables. The mediator will automatically detect the active variable and initialize the appropriate repository.

1. WebSocket-Based Repository (MessagePickupRepositoryClient): Set the `MPR_WS_URL` environment variable to the WebSocket server URL.
2. PostgreSQL-Based Repository (PostgresMessagePickupRepository): Set the `POSTGRES_HOST` environment variable to the PostgreSQL connection string and `MPR_WS_URL` is null
3. In-Memory Repository (InMemoryMessagePickupRepository): If neither `MPR_WS_URL` and `POSTGRES_HOST` is set, the mediator will default to InMemoryMessagePickupRepository.

## Deploy and run

2060-cloud-agent can be run both locally or containerized.
The DIDComm mediator can be run both locally or containerized.

### Locally

2060-cloud-agent mediator can be built and run on localhost by just setting the corresponding variables and executing:
DIDComm mediator can be built and run on localhost by just setting the corresponding variables and executing:

```
yarn build
Expand All @@ -45,42 +62,40 @@ yarn start
Upon a successful start, the following lines should be read in log:

```
INFO: Cloud Agent initialized OK
INFO: DIDComm Mediator Agent initialized OK
```

### Using docker

First of all, a docker image must be created by doing:

```
docker build -t 2060-cloud-agent:[tag] .
docker build -t didcomm-mediator:[tag] .
```

Then, a container can be created and deployed:

```
docker run -e AGENT_NAME=... -e AGENT_ENDPOINT=... -e AGENT_PUBLIC_DID=yyy -e AGENT_PORT=xxx -p yyy:xxx 2060-cloud-agent:[tag]
docker run -e AGENT_NAME=... -e AGENT_ENDPOINT=... -e AGENT_PUBLIC_DID=yyy -e AGENT_PORT=xxx -p yyy:xxx didcomm-mediator:[tag]
```

where yyy is an publicly accesible port from the host machine.

This one will run default command, which launches the mediator. If you want to run a VDR Proxy, you can override this command and use `yarn vdrproxy`.
## How to test

# How to testing

## Testing with Agent Clients
### Testing with Agent Clients

For more details, see the [Client-Agent test](/src/test/Client-Agent/README.md).

## Testing massive message between Agents Clients
### Testing massive message between Agents Clients

For more details, see the [Massive Message Sender test](/src/test/Send-Messages/README.md).

## Test Load balancer with Cloud agent live mode with message repository DB pub/sub and postgres wallets
### Test a load balancer with multiple agent instances supporting Message Pickup in Live mode

- The porpuse is to be able to test the cloud agent live mode implemented with postgres for storage messagePickup, pub/sub for comunication instances and postgres for storage wallets, to do this you must do running docker compose locate on root of project file called [docker-comopose-lb.yml]
The purpose is to be able to test DIDComm mediator in a multi-instance environment, using Postgres as a backend for both Agent wallet and Message Pickup queue.

### Setup
#### Setup

1. You should be set IP local in the file nginx.conf locate on ngnix folder a section upstream

Expand All @@ -97,18 +112,3 @@ server IP-HOST:4002;
docker compose -f docker-compose-lb.yml up --build
```

## Didcomm Mediator: Configurable Message Pickup Repository

The Didcomm Mediator now supports flexible configuration for message pickup repositories, allowing users to choose between different persistence methods depending on their needs. This enhancement provides seamless integration with the following repository options:

- MessagePickupRepositoryClient: A WebSocket-based repository for distributed environments.
- PostgresMessagePickupRepository: A PostgreSQL-based repository for persistent storage. It is meant for simplicity, so it uses the same Postgres host than mediator's wallet.
- InMemoryMessagePickupRepository: An in-memory repository for lightweight setups or testing purposes. It only works when SQLite is used for mediator wallet.

### How to configure

The repository configuration is controlled by these environment variables. The mediator will automatically detect the active variable and initialize the appropriate repository.

1. WebSocket-Based Repository (MessagePickupRepositoryClient): Set the `MPR_WS_URL` environment variable to the WebSocket server URL.
2. PostgreSQL-Based Repository (PostgresMessagePickupRepository): Set the `POSTGRES_HOST` environment variable to the PostgreSQL connection string and `MPR_WS_URL` is null
3. In-Memory Repository (InMemoryMessagePickupRepository): If neither `MPR_WS_URL` and `POSTGRES_HOST` is set, the mediator will default to InMemoryMessagePickupRepository.
24 changes: 12 additions & 12 deletions docker-compose-lb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ services:
volumes:
- ~/data/dm/postgres:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=cloud-agent
- POSTGRES_USER=cloud-agent
- POSTGRES_PASSWORD=didcomm-mediator
- POSTGRES_USER=didcomm-mediator

didcomm-mediator-1:
build: .
Expand All @@ -19,12 +19,12 @@ services:
environment:
#- AGENT_PUBLIC_DID=did:web:10.82.14.176%3A4000
#- AGENT_ENDPOINTS=ws://10.82.14.176:4000
- AGENT_NAME=2060 Cloud Agent - Dev
- WALLET_NAME=2060-cloud-agent-dev
- WALLET_KEY=2060-cloud-agent-dev
- AGENT_NAME=2060 DIDComm mediator - Dev
- WALLET_NAME=2060-didcomm-mediator-dev
- WALLET_KEY=2060-didcomm-mediator-dev
- POSTGRES_HOST=postgres
- POSTGRES_USER=cloud-agent
- POSTGRES_PASSWORD=cloud-agent
- POSTGRES_USER=didcomm-mediator
- POSTGRES_PASSWORD=didcomm-mediator
- KEY_DERIVATION_METHOD=ARGON2I_MOD
#- MPR_WS_URL=ws://192.168.10.13:3100
#- MAX_RECEIVE_BYTES=1000000
Expand All @@ -47,12 +47,12 @@ services:
environment:
#- AGENT_PUBLIC_DID=did:web:10.82.14.176%3A4000
#- AGENT_ENDPOINTS=ws://10.82.14.176:4000
- AGENT_NAME=2060 Cloud Agent - Dev
- WALLET_NAME=2060-cloud-agent-dev
- WALLET_KEY=2060-cloud-agent-dev
- AGENT_NAME=2060 DIDComm Mediator - Dev
- WALLET_NAME=2060-didcomm-mediator-dev
- WALLET_KEY=2060-didcomm-mediator-dev
- POSTGRES_HOST=postgres
- POSTGRES_USER=cloud-agent
- POSTGRES_PASSWORD=cloud-agent
- POSTGRES_USER=didcomm-mediator
- POSTGRES_PASSWORD=didcomm-mediator
- KEY_DERIVATION_METHOD=ARGON2I_MOD
#- MPR_WS_URL=ws://192.168.10.13:3100
#- MAX_RECEIVE_BYTES=1000000
Expand Down
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ services:
volumes:
- ~/data/dm/postgres:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=cloud-agent
- POSTGRES_USER=cloud-agent
- POSTGRES_PASSWORD=didcomm-mediator
- POSTGRES_USER=didcomm-mediator

didcomm-mediator-1:
build: .
Expand All @@ -19,12 +19,12 @@ services:
environment:
#- AGENT_PUBLIC_DID=did:web:10.82.14.176%3A4000
#- AGENT_ENDPOINTS=ws://10.82.14.176:4000
- AGENT_NAME=2060 Cloud Agent - Dev
- WALLET_NAME=2060-cloud-agent-dev
- WALLET_KEY=2060-cloud-agent-dev
- AGENT_NAME=2060 DIDComm Mediator - Dev
- WALLET_NAME=2060-didcomm-mediator-dev
- WALLET_KEY=2060-didcomm-mediator-dev
- POSTGRES_HOST=postgres
- POSTGRES_USER=cloud-agent
- POSTGRES_PASSWORD=cloud-agent
- POSTGRES_USER=didcomm-mediator
- POSTGRES_PASSWORD=didcomm-mediator
- KEY_DERIVATION_METHOD=ARGON2I_MOD
- FIREBASE_CFG_FILE=/config/firebase-cfg.json
#- MPR_WS_URL=ws://192.168.10.13:3100
Expand Down
22 changes: 13 additions & 9 deletions src/agent/CloudAgent.ts → src/agent/DidCommMediatorAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,28 @@ import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import { PushNotificationsFcmModule } from '@credo-ts/push-notifications'
import { MessageForwardingStrategy } from '@credo-ts/core/build/modules/routing/MessageForwardingStrategy'

type CloudAgentModules = {
type DidCommMediatorAgentModules = {
askar: AskarModule
connections: ConnectionsModule
mediator: MediatorModule
messagePickup: MessagePickupModule
pushNotifications: PushNotificationsFcmModule
}

interface AgentOptions<ServiceAgentModules> {
interface AgentOptions<Modules> {
config: InitConfig
modules?: ServiceAgentModules
modules?: Modules
dependencies: AgentDependencies
}

export class CloudAgent extends Agent<CloudAgentModules> {
export class DidCommMediatorAgent extends Agent<DidCommMediatorAgentModules> {
public did?: string

public constructor(options: AgentOptions<CloudAgentModules>, did?: string, dependencyManager?: DependencyManager) {
public constructor(
options: AgentOptions<DidCommMediatorAgentModules>,
did?: string,
dependencyManager?: DependencyManager
) {
super(options, dependencyManager)
this.did = did
}
Expand All @@ -49,14 +53,14 @@ export interface CloudAgentOptions {
postgresUser?: string
postgresPassword?: string
postgresHost?: string
postgresMessagePickupDatabaseName?: string
messagePickupPostgresDatabaseName?: string
}

export const createCloudAgent = (
export const createMediator = (
options: CloudAgentOptions,
messagePickupRepository: MessagePickupRepository
): CloudAgent => {
return new CloudAgent(
): DidCommMediatorAgent => {
return new DidCommMediatorAgent(
{
config: options.config,
dependencies: options.dependencies,
Expand Down
Loading

0 comments on commit 7c37578

Please sign in to comment.