Skip to content

shortmesh/Client

Repository files navigation

ShortMesh Client

Contents

Installation

MacOS (M-series)

brew install libolm
export LIBRARY_PATH="/opt/homebrew/lib:$LIBRARY_PATH"
export CPATH="/opt/homebrew/include:$CPATH"

Bridge setups

Configure self signing in bridge to avoid error:

failed to decrypt megolm event: no session with given ID found

bridge.conf file:

encryption > self_sign = true

Description

ShortMesh Client is a Matrix protocol client that provides messaging capabilities across multiple Matrix bridges.
The project is built to work with any Matrix homeserver and any number of Matrix bridges can be configured to work on it.

Requirements

  • A running Matrix homeserver
  • Bridges configured on homeserver which can be activated in the conf.yaml file
  • RabbitMQ
  • golang
  • swagger
go install github.com/swaggo/swag/cmd/swag@latest
go get github.com/swaggo/http-swagger
go get github.com/swaggo/files # optional, but useful for serving the swagger files
export PATH=$PATH:$(go env GOPATH)/bin
  • libolm

Mac OS

brew install libolm
export CGO_CFLAGS="-I/opt/homebrew/include"
export CGO_LDFLAGS="-L/opt/homebrew/lib"

Ubuntu

sudo apt install libolm-dev

Running

You can configure the bridges supported by your Homeserver in conf.yaml. The client would try to create Rooms and synchronize for your users for every Bridge it comes across in conf.yaml.

For signal to work please make sure your homeserver is set to put phone numbers in topic

network:
    ...in_topics: true

You can modify the conf.yaml file after you make a copy. Place in the following:

  • homeserver
  • homeserver_domain
  • mas_client_id
  • mas_client_secret
  • db_key #should be a high entropy string
cp conf.yaml.example conf.yaml
swag init
go mod tidy

go run .

Docker Setup

Build and Run

# Build
docker build -t matrix-client .

# Run
docker run -d --name matrix-client -p 8080:8080 \
  -v $(pwd)/db:/app/db \
  -v $(pwd)/downloads:/app/downloads \
  -v $(pwd)/conf.yaml:/app/conf.yaml \
  matrix-client

# View logs
docker logs -f matrix-client

Docker Compose

version: '3.8'

services:
  rabbitmq:
    image: rabbitmq:3-management-alpine
    ports:
      - "5672:5672"
      - "15672:15672"
    environment:
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest

  matrix-client:
    build: .
    ports:
      - "8080:8080"
    volumes:
      - ./db:/app/db
      - ./downloads:/app/downloads
      - ./conf.yaml:/app/conf.yaml
    environment:
      - HOST=0.0.0.0
      - PORT=8080
    depends_on:
      - rabbitmq
docker-compose up -d

# View logs
docker-compose logs -f matrix-client

API docs

You can configure your API address in conf.yaml. This would be same address you can access your generated swagger API docs.

swag init

[host]/docs/index.html

Adding devices Queue

The incoming messages for adding devices routed to the queue:

exchange: "bridges.topic"
binding key: "bridges.topic.add_new_device"
queue name: {username}_add_new_device

Incoming messages Queue

The incoming messages are routed to the queue:

exchange: "contacts.topic"
binding key: "contacts.topic.incoming_messages"
queue name: {username}_incoming_messages

Payload Text|Media

{
    "IsContact": true|false,
    "Type": "",
    "From": "",
    "To": "",
    "Message": "",
    "DeviceId": "",
    "Media": {
        "Content": bytes,
        "Info": {
            "Size": 0 # float64 (Double),
            "MimeType": "",
            "Width": 0, 
            "Height": 0,
            "BlurHash": ""
        }
    }
}

Notes

Postgres issues

Snaypse

server {
    listen 443 ssl http2;
    server_name matrix.example.com;

    ssl_certificate /etc/letsencrypt/live/matrix.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/matrix.example.com/privkey.pem;

    client_max_body_size 50M;

    # IMPORTANT: MAS SHOULD COME BEFORE SYNAPSE FOR REGEX NGINX REASONS

    # MAS-backed client auth routes
    location ~ ^/_matrix/client/(v3|v1)/(login|logout|refresh|auth_metadata|capabilities) {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # Synapse endpoints
    location ~ ^(/_matrix|/_synapse/client|/_synapse/mas) {
        proxy_pass http://127.0.0.1:8008;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    # .well-known
    location /.well-known/matrix/ {
        alias /var/www/matrix/.well-known/matrix/;
        default_type application/json;
        add_header Access-Control-Allow-Origin *;
    }
}

.well-known/client

{
  "m.homeserver": {
    "base_url": "https://matrix.example.com"
  },
  "org.matrix.msc2965.authentication": {
    "issuer": "https://auth.example.com/",
    "account": "https://auth.example.com/account/"
  }
}

MAS

configuration

services:
  matrix-auth-service:
    image: ghcr.io/element-hq/matrix-authentication-service:latest
    container_name: matrix-auth-service
    environment:
      - MAS_CONFIG=/app/config/config.yaml
    ports:
      - "8080:8080"
      - "8081:8081" # health endpoint
    volumes:
      - ./config.yaml:/app/config/config.yaml:ro
    restart: unless-stopped
    network_mode: "host"

config.yaml

http:
  listeners:
  - name: web
    resources:
    - name: discovery
    - name: human
    - name: oauth
    - name: compat
    - name: graphql
    - name: assets
    binds:
      # - address: '[::]:8080'
      - host: 0.0.0.0
        port: 8080
    proxy_protocol: false
  - name: internal
    resources:
    - name: health
    binds:
    - host: localhost
      port: 8081
    proxy_protocol: false
  trusted_proxies:
  - 192.168.0.0/16
  - 172.16.0.0/12
  - 10.0.0.0/10
  - 127.0.0.1/8
  - fd00::/8
  - ::1/128
  public_base: https://auth.example.com/
  issuer: https://auth.example.com/
...
matrix:
  kind: synapse
  homeserver: matrix.example.com
  endpoint: https://matrix.sherlockwisdom.com/
  secret: R8PHHknWdVHIsIgUODRuFcN9XYINtrNO
account:
  password_registration_enabled: true
  password_recovery_enabled: true
  account_deactivation_allowed: true
  login_with_email_allowed: true

TBD

  • When the user logs in on new device, all synced devices get logged out

About

This is a headless Matrix Client

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors