Skip to content

skycoin/skycoin-service-discovery

Repository files navigation

Skycoin Service Discovery

The Skycoin service discovery allows registering services to be discovered by other participants in the Skywire network. Currently it allows registration and discovery of

  • VPNs
  • Socks proxies
  • public visors

Dependencies

service-discovery is written in golang and uses redis and postgres as databases (both required).

  • Golang (version 1.19 or higher is required).
  • Redis (only version 5.0.8 is tested with service-discovery).

Run tests

You can run integration tests of the service discovery with the following command:

make test

This requires docker to be installed on the system and runnable from the user invoking the command.

Run

Ensure redis-server is running. If it is installed locally, one can just run:

redis-server

Alternatively, you can run redis in a docker container:

docker run -d -p 6379:6379 --name redis redis

Ensure postgresql is running with postgres as username, password and database. You can run it by docker as follow:

docker run --name postgres -e POSTGRES_USERNAME=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DATABASE=postgres -p 5432:5432 -d postgres

Assuming redis is bound to redis://localhost:6379, we can run service-discovery to serve on :8000 with:

PG_USER=postgres PG_PASSWORD=postgres PG_DATABASE=postgres go run ./cmd/service-discovery/service-discovery.go --redis="redis://localhost:6379" --addr=":8000"

Running in test mode

The proxy service registration and de-registration endpoints require us to use specialised html header fields for authentication/authorization. When testing, this can be a pain. To disable auth completely, run proxy-server with the --test flag:

go run ./cmd/service-discovery/service-discovery.go --test

Running with metrics on

To expose a Victoria Metrics endpoint for skycoin-service-discovery un it with the -m or --metrics flag.

PG_USER=postgres PG_PASSWORD=postgres PG_DATABASE=postgres go run ./cmd/service-discovery/service-discovery.go -m localhost:9099

Build Docker Image

To build docker image use

$ docker build -f Dockerfile -t skycoin/service-discovery:test .

Help

This prints the help menu and exits.

go run ./cmd/service-discovery/service-discovery.go --help

HTTP API

Data structures

All HTTP request and response bodies uses the JSON data format.

Here is the JSON representation of a proxy service entry:

{
  // 'addr' is the skywire address of the proxy service.
  // The format is <public-key>:<uint16-port>
  "addr": "02263cf7f643a6e6e59484e13723e654b8921aa3da3626e7a58bd1d3d08e3b60e9:1234",

  // 'geo' contains the geolocation of the proxy service.
  // It will be omitted if empty.
  "geo": {
    "lat": 37.4224764, // latitude
    "lon": -122.0842499, // longitude
    "country": "NZ", // 2 letter country code (ISO 3166-1 alpha-2) (omitted if empty)
    "region": "" // Region/state short code (FIPS or ISO) (omitted if empty)
  }
}

GET /api/services

Obtains a JSON array of all proxy service entries.

Example:

Request: GET /api/services

Response body:

[
  {
    "address": "02263cf7f643a6e6e59484e13723e654b8921aa3da3626e7a58bd1d3d08e3b60e9:6001",
    "geo": {
      "lat": 37.4224764,
      "lon": -122.0842499
    }    
  },
  {
    "address": "02263cf7f643a6e6e59484e13723e654b8921aa3da3626e7a58bd1d3d08e3b60e9:6002"
  },
  {
    "address": "02263cf7f643a6e6e59484e13723e654b8921aa3da3626e7a58bd1d3d08e3b60e9:6003"
  }
]

GET /api/services/{skywire-address}

Obtains a single proxy service entry.
{skywire-address} is of format: <public-key>:<uint16-port>

Example:

Request: GET /api/services/02263cf7f643a6e6e59484e13723e654b8921aa3da3626e7a58bd1d3d08e3b60e9:6001

Response body:

{
  "address": "02263cf7f643a6e6e59484e13723e654b8921aa3da3626e7a58bd1d3d08e3b60e9:6001",
  "geo": {
    "lat": 37.4224764,
    "lon": -122.0842499
  }    
}

POST /api/services/{skywire-address}

Registers/updates a proxy service entry.
{skywire-address} is of format: <public-key>:<uint16-port>

Example:

Request: POST /api/services/02263cf7f643a6e6e59484e13723e654b8921aa3da3626e7a58bd1d3d08e3b60e9:6001

Request body:

{
  "address": "02263cf7f643a6e6e59484e13723e654b8921aa3da3626e7a58bd1d3d08e3b60e9:6001",
  "geo": {
    "lat": 37.4224764,
    "lon": -122.0842499
  }    
}

Response body:

The server will return the saved proxy service entry.

If the request has no "geo" field, the server may fill the field using the requester's IP address.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published