Sign inSign up

blocknetdx/exrproxy

By blocknetdx

Updated about 3 years ago

Blocknet Enterprise XRouter reverse proxy

Image
0

3.6K

blocknetdx/exrproxy repository overview

Blocknet Enterprise XRouter Proxy

https://github.com/blocknetdx/exrproxy https://hub.docker.com/r/blocknetdx/exrproxy

The XRouter Proxy acts as a reverse proxy (similar to a load balancer) for all your XRouter services and oracles. The reverse proxy is comprised of an nginx web server and a uwsgi python handler. This repository is officially supported by the Blocknet core team. Please feel free to submit any issues or requests.

In order for your requests to be properly validated by the XRouter network you will need to specify your Service Node's private key. Note* this is not a wallet private key and as a result no coin private keys should be used. This is a unique Service Node key that's not associated with any funds. Do not specify any coin private keys in these configurations.

Quick setup

XRouter Proxy is designed to work in docker a environment, although this is not a mandatory requirement. A uwsgi.ini configuration file is required to hook up the services and oracles that need to be exposed through the proxy.

Please adjust the uwsgi.ini file below to work with your desired setup. processes and threads indicate how you can leverage multi-threading on the server to support more simultaneous requests. Keep in mind performance is directly related to your hardware capabilities.

/opt/uwsgiconf/uwsgi.ini

# SPV sample configuration file
[uwsgi]
processes = 8
threads = 2

# Place your Service Node private key here (this is not a wallet private key!)
# Allows the XRouter Proxy to sign packets on your Service Node's behalf
# DO NOT SHARE THIS KEY
set-ph = SERVICENODE_PRIVKEY=cV1bo3ME3qvw9Sxzo72skbFsAQ6ihyT6F8VXMe8mzv6EJoqFVXMV

#  mainnet or testnet
set-ph = BLOCKNET_CHAIN=testnet

# Handle XRouter payments
set-ph = HANDLE_PAYMENTS=true
set-ph = HANDLE_PAYMENTS_RPC_HOSTIP=192.168.1.25
set-ph = HANDLE_PAYMENTS_RPC_PORT=41419
set-ph = HANDLE_PAYMENTS_RPC_USER=user
set-ph = HANDLE_PAYMENTS_RPC_PASS=pass
set-ph = HANDLE_PAYMENTS_RPC_VER=2.0

# Sample SPV RPC configuration
set-ph = RPC_BLOCK_HOSTIP=192.168.1.25
set-ph = RPC_BLOCK_PORT=41419
set-ph = RPC_BLOCK_USER=user
set-ph = RPC_BLOCK_PASS=pass
set-ph = RPC_BLOCK_VER=2.0

# Sample XCloud plugin configuration
set-ph = URL_SomeCustomPlugin_HOSTIP=192.168.1.5
set-ph = URL_SomeCustomPlugin_PORT=8080

Start the xrouter proxy container

docker run -d --name=xrproxy -p 9090:80 -v=/opt/uwsgiconf:/opt/uwsgi/conf blocknetdx/exrproxy:latest

Test if proxy is running

curl -X POST -H "content-type: application/json" --data-binary '[]' 127.0.0.1:9090/

Test if endpoint is running

curl -X POST -H "content-type: application/json" --data-binary '[]' 127.0.0.1:9090/xr/BLOCK/xrGetBlockCount

uwsgi.ini configuration

The nginx python web application responsible for reverse proxying to XRouter endpoints, obtains configuration options from the uwsgi.ini file. This file should be used to wire up and connect backend endpoints to the XRouter Proxy web server.

SPV RPC endpoint

Format: RPC_[CURRENCY]_[VAR]

Supported options:

OptionDescription
RPC_[CURRENCY]_HOSTIPIp address of the endpoint
RPC_[CURRENCY]_PORTEndpoint's port number
RPC_[CURRENCY]_USERRPC username
RPC_[CURRENCY]_PASSRPC password
RPC_[CURRENCY]_VERRPC json version (ETH, parity and geth typically require "2.0")
set-ph = RPC_BLOCK_HOSTIP=192.168.1.25
set-ph = RPC_BLOCK_PORT=41414
set-ph = RPC_BLOCK_USER=user
set-ph = RPC_BLOCK_PASS=pass
set-ph = RPC_BLOCK_VER=2.0
XCloud Plugin RPC endpoint

Format: RPC_[PLUGIN_NAME]_[VAR]

The main difference between SPV and XCloud plugin RPC configurations is the additional _METHOD variable in the XCloud plugin config.

Supported options:

OptionDescription
RPC_[PLUGIN_NAME]_HOSTIPIp address of the endpoint
RPC_[PLUGIN_NAME]_PORTEndpoint's port number
RPC_[PLUGIN_NAME]_USERRPC username
RPC_[PLUGIN_NAME]_PASSRPC password
RPC_[PLUGIN_NAME]_VERRPC json version (ETH, parity and geth typically require "2.0")
RPC_[PLUGIN_NAME]_METHODRPC method to be called
set-ph = RPC_BLOCK_HOSTIP=192.168.1.25
set-ph = RPC_BLOCK_PORT=41414
set-ph = RPC_BLOCK_USER=user
set-ph = RPC_BLOCK_PASS=pass
set-ph = RPC_BLOCK_VER=2.0
set-ph = RPC_BLOCK_METHOD=getblockcount
URL endpoint

Format: URL_[PLUGIN_NAME]_[VAR]

Supported options:

OptionDescription
URL_[PLUGIN_NAME]_HOSTIPPlugin ip address (for docker specify container ip address)
URL_[PLUGIN_NAME]_PORTPlugin's port number
set-ph = URL_LTCGetBlockCount_HOSTIP=172.17.0.2
set-ph = URL_LTCGetBlockCount_PORT=9332

NGINX configs for XCloud Plugins

An nginx config file can be used to expose an XCloud plugin through the XRouter Proxy server. This is an alternative setup and will bypass the built in python handler. The tradeoff is that the proxy will not sign return packets, however, you have full control of handling the request without any middleware. By default the XRouter protocol expects plugins to exist at the endpoint /xrs/PluginName.

These nginx XCloud plugins bypass the internal reverse proxy handler that we've provided, as a result you will be responsible for signing requests with the proper Service Node key manually as well as handling any payments from XRouter clients. If you do not want to do this, consider using the URL endpoint plugin type that we've provided in the default reverse proxy handler.

The XRouter Proxy container has a volume that mounts to /etc/nginx, the conf.d directory in here is where all nginx XCloud plugin endpoints are installed. This can be mounted via a docker volume:

# Assumes this directory exists: /opt/nginxconfs/conf.d/xcloud
docker run -v=/opt/nginxconfs:/etc/nginx blocknetdx/exrproxy:latest

Sample nginx XCloud plugin conf: /opt/nginxconfs/conf.d/xcloud/LTCGetBlockCount.conf

location = /xrs/LTCGetBlockCount {
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
    proxy_pass http://192.168.1.5:9091;
}

Handle XRouter Payments

The XRouter protocol allows Service Nodes to charge for specific services. The payment transaction is included along with the request packet. XRouter Proxy can handle submitting this to the Blocknet network on your behalf. Currently all XRouter fees are paid in BLOCK. XRouter Proxy will require the RPC credentials for the client responsible for handling the payment transaction.

Supported options:

OptionDescription
HANDLE_PAYMENTSSpecify true (1) or false (0)
HANDLE_PAYMENTS_ENFORCESpecify true (1) or false (0). Enforces payment (may slow down requests)
HANDLE_PAYMENTS_RPC_HOSTIPIp address of the endpoint
HANDLE_PAYMENTS_RPC_PORTEndpoint's port number
HANDLE_PAYMENTS_RPC_USERRPC username
HANDLE_PAYMENTS_RPC_PASSRPC password
HANDLE_PAYMENTS_RPC_VERRPC json version

In /opt/uwsgiconf/uwsgi.ini

set-ph = HANDLE_PAYMENTS=true
set-ph = HANDLE_PAYMENTS_ENFORCE=false
set-ph = HANDLE_PAYMENTS_RPC_HOSTIP=192.168.1.25
set-ph = HANDLE_PAYMENTS_RPC_PORT=41414
set-ph = HANDLE_PAYMENTS_RPC_USER=user
set-ph = HANDLE_PAYMENTS_RPC_PASS=pass
set-ph = HANDLE_PAYMENTS_RPC_VER=2.0

Docker

https://hub.docker.com/r/blocknetdx/exrproxy/tags

Volumes that can be used with the XRouter Proxy container:

VolumeDescription
/opt/uwsgi/confShould contain the uwsgi.ini config
/etc/nginxContains all the nginx configuration files. Specifically any custom XCloud plugin endpoints
Full docker run example w/ volumes:
docker run -d --name=xrproxy -p 9090:80 -v=/opt/uwsgiconf:/opt/uwsgi/conf -v=/opt/nginxconfs:/etc/nginx blocknetdx/exrproxy:latest
Build Dockerfile
docker build --build-arg cores=4 -t blocknetdx/exrproxy:latest . 

License

MIT License

Copyright (c) 2019-2020 The Blocknet developers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Tag summary

Content type

Image

Digest

sha256:8a18b44a2

Size

274 MB

Last updated

about 3 years ago

docker pull blocknetdx/exrproxy