diff --git a/README.md b/README.md index 472d1b9..ef972fb 100644 --- a/README.md +++ b/README.md @@ -56,4 +56,26 @@ Building the client for each platform: GOOS=windows GOARCH=amd64 go build -o lczero-client.exe GOOS=darwin GOARCH=amd64 go build -o lczero-client_mac GOOS=linux GOARCH=amd64 go build -o lczero-client_linux -``` \ No newline at end of file +``` + + +# Go module support + +Dependend go modules were added by executing: + +``` +go get 'github.com/Tilps/chess@master' +``` + +gives something like: +``` +go: downloading github.com/Tilps/chess v0.0.0-20200409092358-c35715299813 +go: github.com/Tilps/chess master => v0.0.0-20200409092358-c35715299813 +``` + +This version number can then be used in the `go.mod` file + +Whenever you want to update the version do the above `go get` step and there will be a new version number generated that you can put in the existing `go.mod` file. + +Just use the command `go mod download` to update go's module cache. +building should work with `go build lc0_main.go` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8756179 --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module github.com/LeelaChessZero/lczero-client + +go 1.15 + +require ( + github.com/Tilps/chess v0.0.0-20200409092358-c35715299813 + github.com/nightlyone/lockfile v1.0.1-0.20201014160207-368fd4d5d6ae +) + +replace github.com/LeelaChessZero/lczero-client => ./ diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..8376b36 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/Tilps/chess v0.0.0-20200409092358-c35715299813 h1:9SCZ8ooOu4zJEgPuv90hPtkTT5XEIq1K0j2/Jrunsb4= +github.com/Tilps/chess v0.0.0-20200409092358-c35715299813/go.mod h1:p5ClvMMzXkXDcSis21aF6thPWChCbR1YRrTGbEhwA6w= +github.com/nightlyone/lockfile v1.0.1-0.20201014160207-368fd4d5d6ae h1:ZD/X4pxMoJCbiaaxKpSl5hxmr0l0TTiVrF1BPvKThU4= +github.com/nightlyone/lockfile v1.0.1-0.20201014160207-368fd4d5d6ae/go.mod h1:rywoIealpdNse2r832aiD9jRk8ErCatROs6LzC841CI= diff --git a/lc0_main.go b/lc0_main.go index 0cb9b5e..d957447 100644 --- a/lc0_main.go +++ b/lc0_main.go @@ -29,7 +29,7 @@ import ( "sync" "time" - "client" + "github.com/LeelaChessZero/lczero-client/src/client" "github.com/Tilps/chess" "github.com/nightlyone/lockfile" @@ -52,11 +52,12 @@ var ( defaultLocalHost = "Unknown" gpuType = "Unknown" - localHost = flag.String("localhost", "", "Localhost name to send to the server when reporting\n(defaults to Unknown, overridden by the configuration file)") - hostname = flag.String("hostname", "http://api.lczero.org", "Address of the server") - user = flag.String("user", "", "Username") - password = flag.String("password", "", "Password") - gpu = flag.Int("gpu", -1, "GPU to use (ignored if --backend-opts used)") + localHost = flag.String("localhost", "", "Localhost name to send to the server when reporting\n(defaults to Unknown, overridden by the configuration file)") + hostname = flag.String("hostname", "http://api.lczero.org", "Address of the server") + networkMirror = flag.String("network-mirror", "", "Alternative url prefix to download networks from.") + user = flag.String("user", "", "Username") + password = flag.String("password", "", "Password") + gpu = flag.Int("gpu", -1, "GPU to use (ignored if --backend-opts used)") // debug = flag.Bool("debug", false, "Enable debug mode to see verbose output and save logs") lc0Args = flag.String("lc0args", "", "") backopts = flag.String("backend-opts", "", @@ -135,7 +136,7 @@ func getExtraParams() map[string]string { return map[string]string{ "user": *user, "password": *password, - "version": "32", + "version": "33", "token": strconv.Itoa(randId), "train_only": strconv.FormatBool(*trainOnly), "hostname": *localHost, @@ -365,11 +366,11 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri testedDxNet = networkPath } if *backopts != "" { - // Check against small token blacklist, currently only "mlh", "random" and "recordreplay" + // Check against small token blacklist. tokens := regexp.MustCompile("[,=().0-9]").Split(*backopts, -1) for _, token := range tokens { switch token { - case "mlh", "random", "recordreplay": + case "mlh", "random", "recordreplay", "trivial": log.Fatalf("Not accepted in --backend-opts: %s", token) } } @@ -895,7 +896,7 @@ func getNetwork(httpClient *http.Client, sha string, keepTime string) (string, e log.Println("Waiting 10 seconds before retrying") time.Sleep(10 * time.Second) } - err = client.DownloadNetwork(httpClient, *hostname, path, sha) + err = client.DownloadNetwork(httpClient, *networkMirror, path, sha) if err == nil { return checkValidNetwork(dir, sha) } @@ -1174,6 +1175,10 @@ func main() { *hostname = "http://testserver.lczero.org" } + if len(*networkMirror) == 0 { + *networkMirror = *hostname + "/get_network?sha=" + } + log.SetFlags(log.LstdFlags | log.Lshortfile) if len(*settingsPath) == 0 { @@ -1238,7 +1243,7 @@ func main() { *localHost = defaultLocalHost } - httpClient := &http.Client{Timeout:300 * time.Second} + httpClient := &http.Client{Timeout: 300 * time.Second} startTime = time.Now() for i := 0; ; i++ { err := nextGame(httpClient, i) diff --git a/src/client/client_http.go b/src/client/client_http.go index 8d02b9e..d16fc3f 100644 --- a/src/client/client_http.go +++ b/src/client/client_http.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "errors" - "fmt" "io" "io/ioutil" "log" @@ -109,13 +108,17 @@ func UploadMatchResult(httpClient *http.Client, hostname string, match_game_id u return postParams(httpClient, hostname+"/match_result", params, nil) } -func DownloadNetwork(httpClient *http.Client, hostname string, networkPath string, sha string) error { - uri := hostname + fmt.Sprintf("/get_network?sha=%s", sha) +func DownloadNetwork(httpClient *http.Client, uriPrefix string, networkPath string, sha string) error { + uri := uriPrefix + sha r, err := httpClient.Get(uri) if err != nil { return err } + if r.StatusCode >= 400 { + return errors.New("Network server gave error status.") + } + dir, _ := filepath.Split(networkPath) out, err := ioutil.TempFile(dir, sha+"_tmp") if err != nil {