# Open source (self-hosted)

> Affinidi provides an open-sourced DIDComm Mediator implementation based on the DIDComm v2.1 protocol.

Deploying the DIDComm Mediator locally enables you to explore and understand how message handling and encryption work under the hood. It allows you to customise the configuration depending on your requirements.

To deploy the DIDComm Mediator from the open-sourced version, follow the steps below:

## 1. Prerequisites

Before you begin, install the following applications.

- 
Install Rust (1.85.0 2024 Edition) on your machine if you haven’t installed it yet using [this guide](https://www.rust-lang.org/tools/install).

- 
Install Docker on your machine if you haven’t installed it yet using [this guide](https://docs.docker.com/desktop/). We will need this to run Redis instance for the mediator to store messages temporarily and mediator configurations.

## 2. Clone the mediator repository

- Clone the [GitHub repo](https://github.com/affinidi/affinidi-tdk-rs) on your local.

```bash
git clone git@github.com:affinidi/affinidi-tdk-rs.git
```

- Navigate to the crates/affinidi-messaging folder.

```bash
cd affinidi-tdk-rs/crates/affinidi-messaging
```

## 3. Set up the mediator instance

- Run the Redis Docker container using the command below from your terminal:

```bash
docker run --name=redis-local --publish=6379:6379 --hostname=redis --restart=on-failure --detach redis:latest
```

The latest supported version of Redis is version 8.0.

- Run setup_environment to configure the mediator with all the required information to run locally.

```bash
cargo run --bin setup_environment
```

Output from setup_environment

  Important Note

- To the question “Use existing Mediator DID?” during setup, answer “no”. This will generate new DID.

- To the question “Would you like to auto-create some friends?”, answer “yes”. This will generate sample users required to run test and examples.

Select Local Mediator Configuration and follow the on-screen instructions. Upon successful setup, it will generate the following information:

- Mediator DID and secrets.

- Administration DID and secrets.

- SSL Certificates for local development/testing.

- Different users with their DIDs for testing.

- After completing the setup, run the following command to navigate to the affinidi-messaging-mediator directory and start the mediator:

```bash
cd affinidi-messaging-mediator && cargo run
```

- To verify that the mediator is running, open http://localhost:7037/mediator/v1/.well-known/did.json in your web browser. This page should display your local mediator’s DID document.

## 4. Test the mediator connection

The repository provides examples that you can run to test whether the setup was successful. To do this, follow the steps below:

- Open another terminal tab and go to the crates/affinidi-messaging folder.

```bash
cd affinidi-tdk-rs/crates/affinidi-messaging
```

- From the terminal, run the following example.

```bash
cargo run --example mediator_ping
```

The above example will execute a code that authenticates to the mediator and send a ping message. If successful, it sends a pong message back.

## Enable logging

To enable logging to see more information when running the example and to learn more about how it works, set the following environment variables from your terminal.

```bash
export RUST_LOG=none,affinidi_messaging_helpers=debug,affinidi_messaging_sdk=info
```

## What’s next

  [Explore Meeting Place, an implementation of Affinidi Messaging](/products/affinidi-elements/affinidi-messaging/meeting-place.md)

  [Integrate Affinidi Messaging into your applications](/products/affinidi-elements/affinidi-messaging/integration-guides.md)
