mirror of
https://github.com/kvazar-network/keva-stratum.git
synced 2025-01-26 23:04:42 +00:00
Started adding redis.
This commit is contained in:
parent
f579a2bd10
commit
3aa6f2f8c1
38
main.go
38
main.go
@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"./pool"
|
"./pool"
|
||||||
@ -15,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/goji/httpauth"
|
"github.com/goji/httpauth"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/hashicorp/go-version"
|
||||||
"github.com/yvasiyarov/gorelic"
|
"github.com/yvasiyarov/gorelic"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -83,7 +85,43 @@ func readConfig(cfg *pool.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkRedisVersion(info string) bool {
|
||||||
|
var versionStr string
|
||||||
|
parts := strings.Split(info, "\r\n")
|
||||||
|
for _, line := range parts {
|
||||||
|
if strings.Index(line, ":") != -1 {
|
||||||
|
valParts := strings.Split(line, ":")
|
||||||
|
if valParts[0] == "redis_version" {
|
||||||
|
versionStr = valParts[1]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if versionStr == "" {
|
||||||
|
log.Printf("Could not detect redis version - must be super old or broken")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
minVersion, _ := version.NewVersion("2.6")
|
||||||
|
curVersion, err := version.NewVersion(versionStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Could not check redis version: " + err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if curVersion.LessThan(minVersion) {
|
||||||
|
log.Printf("You're using redis version %s the minimum required version is 2.6. Follow the damn usage instructions...", versionStr)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
info, err := stratum.RedisClient.Info().Result()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Cannot start redis server.")
|
||||||
|
}
|
||||||
|
if !checkRedisVersion(info) {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
readConfig(&cfg)
|
readConfig(&cfg)
|
||||||
startNewrelic()
|
startNewrelic()
|
||||||
|
@ -13,11 +13,19 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-redis/redis"
|
||||||
|
|
||||||
"../pool"
|
"../pool"
|
||||||
"../rpc"
|
"../rpc"
|
||||||
"../util"
|
"../util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var RedisClient *redis.Client = redis.NewClient(&redis.Options{
|
||||||
|
Addr: "localhost:6379",
|
||||||
|
Password: "",
|
||||||
|
DB: 0,
|
||||||
|
})
|
||||||
|
|
||||||
type StratumServer struct {
|
type StratumServer struct {
|
||||||
luckWindow int64
|
luckWindow int64
|
||||||
luckLargeWindow int64
|
luckLargeWindow int64
|
||||||
|
Loading…
x
Reference in New Issue
Block a user