derohe-proxy/derohe-proxy.go
2022-05-15 02:15:30 +02:00

64 lines
1.6 KiB
Go

package main
import (
"derohe-proxy/proxy"
"fmt"
"net"
"time"
"github.com/docopt/docopt-go"
)
func main() {
var err error
Arguments, err = docopt.Parse(command_line, nil, true, "pre-alpha", false)
if err != nil {
fmt.Printf("Error while parsing options err: %s\n", err)
return
}
if Arguments["--listen-address"] != nil {
addr, err := net.ResolveTCPAddr("tcp", Arguments["--listen-address"].(string))
if err != nil {
fmt.Printf("--listen-address: address is invalid\n")
return
} else {
if addr.Port == 0 {
fmt.Printf("--listen-address: no port specified\n")
return
} else {
listen_addr = addr.String()
}
}
}
if Arguments["--daemon-address"] == nil {
fmt.Printf("--daemon-address: option is required\n")
return
} else {
fmt.Printf("--daemon-address: is set to %v\n", Arguments["--daemon-address"].(string))
daemon_address = Arguments["--daemon-address"].(string)
}
go proxy.Start_server(listen_addr)
// Wait for first miner connection to grab wallet address
for proxy.CountMiners() < 1 {
time.Sleep(time.Second * 1)
}
go proxy.Start_client(daemon_address, proxy.Address)
var current_time time.Time
last_time := time.Now()
//fmt.Printf("%4d miners connected\t\tBlocks:%4d\tMiniblocks:%4d\tRejected:%4d\n", proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected)
for {
current_time = time.Now()
if current_time.Sub(last_time) >= time.Minute {
fmt.Printf("%4d miners connected\t\tBlocks:%4d\tMiniblocks:%4d\tRejected:%4d\n", proxy.CountMiners(), proxy.Blocks, proxy.Minis, proxy.Rejected)
last_time = time.Now()
}
}
}