# Sophon Gateway

sophon-gateway用于注册钱包,矿工相关信息,也是其它组件和钱包交流的中间桥梁。用于代理从共享组件调用本地组件的请求。

# 快速启动

# 下载代码

git clone https://github.com/ipfs-force-community/sophon-gateway.git

# 编译

make

# 启动服务

./sophon-gateway run

提示

启动成功会在默认的repo目录 ~/.sophon-gateway 中生成 config.tomltoken 两个文件,config.toml 里面是 sophon-gateway 的配置项,token 文件里面存的是 jwt token,给命令行使用

# CLI 操作指南

# 查看帮助

./sophon-gateway -h

NAME:
   sophon-gateway - sophon-gateway for proxy incoming wallet and proof

USAGE:
   sophon-gateway [global options] command [command options] [arguments...]

VERSION:
   0.0.1'+gitc2048fb'

COMMANDS:
   run      start sophon-gateway daemon
   miner    miner cmds
   wallet   wallet cmds
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --listen value  host address and port the worker api will listen on (default: "/ip4/127.0.0.1/tcp/45132")
   --help, -h      show help (default: false)
   --version, -v   print the version (default: false)

# sophon gateway 基础操作

# miner相关

  1. 列出 miner
./sophon-gateway miner list

# res
t01561
t02608
t02082
  1. 查看单个miner状态
./sophon-gateway miner <miner-id>

# res
{
        "Connections": [
                {
                        "Channel": "ddbbd646-f3a2-474b-8457-ea7195cf5765",
                        "Ip": "127.0.0.1:36586",
                        "RequestCount": 0,
                        "CreateTime": "2021-07-20T17:34:33.767108581+08:00"
                }
        ],
        "ConnectionCount": 1
 }

# 钱包相关

  1. 列出钱包
./sophon-gateway wallet list

# res
[
        {
                "Account": "wallet_test1",
                "SupportAccounts": [
                        "testminer"
                ],
                "ConnectStates": [
                        {
                                "Addrs": [
                                        "t3wbwannykivspagunexwwky7eiqg4qa25eoqmgolpkzdz3fidocbjeflbyxqqguyypsekyhqbkj33f657ulla",
                                        "t1zkh45ooidf5zt3yv5o26uugjn5ao4fttsxfgdaq",
                                ],
                                "ChannelId": "016c1010-c56a-4849-89d1-e2b28aecc95a",
                                "Ip": "192.168.5.64:50448",
                                "RequestCount": 0,
                                "CreateTime": "2021-07-19T14:06:50.209609054+08:00"
                        }
                ]
        },
        {
                "Account": "wallet_test2",
                "SupportAccounts": [
                        "wallet_test2"
                ],
                "ConnectStates": [
                        {
                                "Addrs": [
                                        "t3vwbowhnkripgyxdawgwepcwcsqmai5exxetord362wudwr24a3kvgndnpsn6i3md2i23cmjx3rfflvbu7gna",
                                ],
                                "ChannelId": "57971a25-b760-4744-b6c2-af470ab456a9",
                                "Ip": "127.0.0.1:36598",
                                "RequestCount": 0,
                                "CreateTime": "2021-07-20T17:34:33.809502589+08:00"
                        }
                ]
        }
 ]
  1. 查看单个钱包
./sophon-gateway wallet <wallet-account>

# 使用 Gateway 代理对其他线上组件的请求

在不想直接暴露线上组件服务入口,或者简化本地组件的接口配置的情况下,可以选择使用 gateway 代理对其他线上组件的请求。

# 通过配置文件设置代理

在 sophon-gateway 的配置文件中,可以通过配置 NodeMessagerDropletMiner 来设置对应组件的代理地址。

# /config.toml


```toml
Node = "/dns/node/tcp/3453"
Messager = "/dns/messager/tcp/39812"
Droplet = "/dns/market/tcp/41235"
Miner = "/dns/miner/tcp/12308"


[API]
  ListenAddress = "/ip4/127.0.0.1/tcp/45132" # 本地组件wallet和damocles-manager通过长连接和gateway保持通信

.......

# 通过命令行设置代理

sophon-gateway proxy set 
NAME:
   sophon-gateway proxy set - set proxy (or unset proxy by setting a empty url)

USAGE:
   sophon-gateway proxy set [command options] [arguments...]

OPTIONS:
   --type value  specify which type of venus component, to proxy, e.g. AUTH, VENUS, MESSAGER, MINER, DROPLET
# 设置代理
./sophon-gateway proxy set --type AUTH --url /dns/auth/tcp/3453
# 取消代理
./sophon-gateway proxy set --type AUTH --url ""