Skip to content

Commit

Permalink
【BOX v0.5 voucher】
Browse files Browse the repository at this point in the history
1,优化与agent的连接
2,eth,btc等掉线重连
3,添加密码验证
4,优化配置文件
  • Loading branch information
john committed Aug 15, 2018
1 parent f7accae commit d08c22c
Show file tree
Hide file tree
Showing 19 changed files with 762 additions and 357 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ There are 5 main functionalites for this voucher progam:
Use the following command for the first time run
```sh
make build
cp config.toml.example config.toml
cp log.xml.example log.xml
```
Otherwise, use this command
```sh
Expand Down
11 changes: 10 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ BOX代码已上传至全球最大的技术开源社区GitHub,待与诸君共
监控以太坊公链event log,确认审批流操作,以及充值提现记录等,并将结果通知给代理
## 使用步骤:

初始化。首次使用make build命令,再次make rebuild命令,切记,build命令将清除所有数据;
初始化。首次使用make build命令
```sh
make build
cp config.toml.example config.toml
cp log.xml.example log.xml
```
再次make rebuild命令,切记,build命令将清除所有数据;
```sh
make rebuild
```
将连接代理的地址、端口以及ssl公钥以及证书写入到config.json配置文件中对应的参数中
将eth公链、比特币公链分别写入到config.json配置文件中对应的参数中
启动本程序
Expand Down
3 changes: 3 additions & 0 deletions common/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var DefaultBackoff = Backoff{
jitter: 0.2,
}

//重连次数记录
var RetryCount = 0

type Backoff struct {
MaxDelay time.Duration
baseDelay time.Duration
Expand Down
28 changes: 14 additions & 14 deletions config.toml → config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# |- scripts
# \- client-cert.sh
# \- server-cert.sh
basedir = "/Users/admin/Work/src/github.com/boxproject/voucher/build/"
basedir = "/opt/box/voucher"

[agentservice]
# 服务名称
Expand All @@ -25,22 +25,22 @@ name = "voucher"
alias = "server1"
companionname = "companion"
#http
ipandport = "192.168.199.150:9092"
ipandport = "127.0.0.1:19092"
pattern = "/addkey"
# rpc
rpcapi = "127.0.0.1:50502"
# 如果不填该参数,默认查找 ${basedir}/certs/${name}.pem
clientcert = "/Users/admin/ssl/client.pem"
clientcert = "/opt/box/voucher/ssl/client.pem"
# 如果不填该参数,默认查找 ${basedir}/certs/${name}.key
clientkey = "/Users/admin/ssl/client.key"
clientkey = "/opt/box/voucher/ssl/client.key"

[secret]
# 服务器端密钥字节数
secretLength = 40
# 初始化时下载客户端证书一次性密码字节数
passLength = 8
# 授权APP的数量
appNum = 3
appNum = 2

[database]
# 如果不提供该参数,默认为 ${basedir}/db
Expand Down Expand Up @@ -72,19 +72,19 @@ ip = "0.0.0.0"

# 以太坊公链节点
[ethereum]
scheme = "ws://127.0.0.1:8546"
delayedBlocks = 30
scheme = "ws://localhost:8546"
delayedBlocks = 0
cursorBlocks = 15900
retries = 10
accountPoolSize = 10
blockNoFilePath = "/Users/admin/Work/src/github.com/boxproject/voucher/blockno.txt"
nonceFilePath = "/Users/admin/Work/src/github.com/boxproject/voucher/nonce.txt"
accountPoolSize = 2
blockNoFilePath = "/opt/box/voucher/blockno.txt"
nonceFilePath = "/opt/box/voucher/nonce.txt"

# bitcoin node
[bitcoin]
type = "regtest"
type = "main"
host = "localhost:8332"
rpcuser="admin"
rpcpass="51318c0c86d5b51b3beffbc02b724e"
blockNoFilePath = "/Users/admin/Work/src/github.com/boxproject/voucher/btcBlockno.txt"
rpcuser="user"
rpcpass="pass"
blockNoFilePath = "/opt/box/voucher/btcBlockno.txt"
confirmations=6
7 changes: 7 additions & 0 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (
HASH_LIST_PRIFIX = "v_hl_" //hash list
WITHDRAW_APPLY_PRIFIX = "v_wa_" //withdraw apply
PENDING_PRIDFIX = "p_" //pending
ROUTER_PRIDFIX = "r_" //grpc router
)

const (
Expand All @@ -75,6 +76,7 @@ const (

//pub db key
const (
PUB_DB_BAK_PRIFIX = "pub_db_bak_"
PUBKEY_ETH = "pub_key_eth"
PUBKEY_BTC = "pub_key_btc"
DEPOSIT_PRIFIX = "pub_dp_"
Expand Down Expand Up @@ -150,6 +152,8 @@ const (
GRPC_COIN_LIST_WEB = "16" //coin上报
GRPC_HASH_ENABLE_WEB = "17" //hash enable 公链log
GRPC_HASH_DISABLE_WEB = "18" //hash enable 公链log

GRPC_CHECK_KEY_WEB = "19" //密码验证
)

//公链操作类型
Expand Down Expand Up @@ -199,6 +203,7 @@ const (
VOUCHER_OPERATE_TOKEN_DEL = "9" //token 删除
VOUCHER_OPERATE_TOKEN_LIST = "10" //token list 查询
VOUCHER_OPERATE_COIN = "11" //coin 操作
VOUCHER_OPERATE_CHECK_KEY = "12" //密码验证
)

type BoxRecord struct {
Expand Down Expand Up @@ -247,6 +252,7 @@ type GrpcStream struct {
}

type TokenInfo struct {
Status string
TokenName string
Decimals int64
ContractAddr string
Expand Down Expand Up @@ -405,6 +411,7 @@ type Operate struct {
CoinCategory int64 //币种分类
CoinUsed bool //币种使用
Sign string //签名
PassSign string //密码签名
}

var OperateChan chan *Operate = make(chan *Operate, CHAN_MAX_SIZE)
Expand Down
1 change: 0 additions & 1 deletion localdb/rundb.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func RunDatabase(cfg *config.Config) (Database, error) {

func prepare(db Database, cfg *config.Config) (err error) {
// 如果没有初始化过,则需要产生证书
// Create certificate if no initialization yet
if err = common.GenCert(cfg, config.SVRCERTSCRIPT); err != nil {
errors.GenServerCertErr.Err = err
return errors.GenServerCertErr
Expand Down
6 changes: 3 additions & 3 deletions log.xml → log.xml.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<filter enabled="true">
<tag>file</tag>
<type>file</type>
<level>INFO</level>
<property name="filename">/Users/wangzl/Work/src/github.com/boxproject/voucher/build/log/voucher.log</property>
<property name="filename">/opt/box/voucher/log/voucher.log</property>
<level>DEBUG</level>
<!--
%T - Time (15:04:05 MST)
%t - Time (15:04)
Expand Down Expand Up @@ -41,7 +41,7 @@
<tag>donotopen</tag>
<type>socket</type>
<level>FINEST</level>
<property name="endpoint">192.168.1.255:12124</property> <!-- recommend UDP broadcast -->
<property name="endpoint">127.0.0.1:12124</property> <!-- recommend UDP broadcast -->
<property name="protocol">udp</property> <!-- tcp or udp -->
</filter>
</logging>
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
"github.com/mdp/qrterminal"
"gopkg.in/urfave/cli.v1"
"github.com/awnumar/memguard"
"path/filepath"
"strings"
)

func main() {
Expand All @@ -52,7 +54,12 @@ func run(ctx *cli.Context) (err error) {
cfg *config.Config
db localdb.Database
)
logger.LoadConfiguration("log.xml")
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
logger.Error("get file path error",err)
}
execDir := strings.Replace(dir, "\\", "/", -1)
logger.LoadConfiguration(execDir+"/log.xml")

//config
filePath := ctx.String("c")
Expand Down
Loading

0 comments on commit d08c22c

Please sign in to comment.