You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
2.1 KiB
107 lines
2.1 KiB
// +build go1.9 |
|
|
|
package main |
|
|
|
import ( |
|
"encoding/json" |
|
"log" |
|
"math/rand" |
|
"os" |
|
"path/filepath" |
|
"runtime" |
|
"time" |
|
|
|
"github.com/yvasiyarov/gorelic" |
|
|
|
"github.com/etclabscore/open-etc-pool/api" |
|
"github.com/etclabscore/open-etc-pool/payouts" |
|
"github.com/etclabscore/open-etc-pool/proxy" |
|
"github.com/etclabscore/open-etc-pool/storage" |
|
) |
|
|
|
var cfg proxy.Config |
|
var backend *storage.RedisClient |
|
|
|
func startProxy() { |
|
s := proxy.NewProxy(&cfg, backend) |
|
s.Start() |
|
} |
|
|
|
func startApi() { |
|
s := api.NewApiServer(&cfg.Api, backend) |
|
s.Start() |
|
} |
|
|
|
func startBlockUnlocker() { |
|
u := payouts.NewBlockUnlocker(&cfg.BlockUnlocker, backend, &cfg.Network) |
|
u.Start() |
|
} |
|
|
|
func startPayoutsProcessor() { |
|
u := payouts.NewPayoutsProcessor(&cfg.Payouts, backend) |
|
u.Start() |
|
} |
|
|
|
func startNewrelic() { |
|
if cfg.NewrelicEnabled { |
|
nr := gorelic.NewAgent() |
|
nr.Verbose = cfg.NewrelicVerbose |
|
nr.NewrelicLicense = cfg.NewrelicKey |
|
nr.NewrelicName = cfg.NewrelicName |
|
nr.Run() |
|
} |
|
} |
|
|
|
func readConfig(cfg *proxy.Config) { |
|
configFileName := "config.json" |
|
if len(os.Args) > 1 { |
|
configFileName = os.Args[1] |
|
} |
|
configFileName, _ = filepath.Abs(configFileName) |
|
log.Printf("Loading config: %v", configFileName) |
|
|
|
configFile, err := os.Open(configFileName) |
|
if err != nil { |
|
log.Fatal("File error: ", err.Error()) |
|
} |
|
defer configFile.Close() |
|
jsonParser := json.NewDecoder(configFile) |
|
if err := jsonParser.Decode(&cfg); err != nil { |
|
log.Fatal("Config error: ", err.Error()) |
|
} |
|
} |
|
|
|
func main() { |
|
readConfig(&cfg) |
|
rand.Seed(time.Now().UnixNano()) |
|
|
|
if cfg.Threads > 0 { |
|
runtime.GOMAXPROCS(cfg.Threads) |
|
log.Printf("Running with %v threads", cfg.Threads) |
|
} |
|
|
|
startNewrelic() |
|
|
|
backend = storage.NewRedisClient(&cfg.Redis, cfg.Coin, cfg.Pplns) |
|
pong, err := backend.Check() |
|
if err != nil { |
|
log.Printf("Can't establish connection to backend: %v", err) |
|
} else { |
|
log.Printf("Backend check reply: %v", pong) |
|
} |
|
|
|
if cfg.Proxy.Enabled { |
|
go startProxy() |
|
} |
|
if cfg.Api.Enabled { |
|
go startApi() |
|
} |
|
if cfg.BlockUnlocker.Enabled { |
|
go startBlockUnlocker() |
|
} |
|
if cfg.Payouts.Enabled { |
|
go startPayoutsProcessor() |
|
} |
|
quit := make(chan bool) |
|
<-quit |
|
}
|
|
|