Skip to content

Commit

Permalink
Merge pull request #159 from LeelaChessZero/master
Browse files Browse the repository at this point in the history
Merge from master for release 33.
  • Loading branch information
borg323 authored Dec 12, 2021
2 parents 1fc740d + 6ec3d80 commit 47a9dda
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 15 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```


# 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`
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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 => ./
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
27 changes: 16 additions & 11 deletions lc0_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"sync"
"time"

"client"
"github.com/LeelaChessZero/lczero-client/src/client"

"github.com/Tilps/chess"
"github.com/nightlyone/lockfile"
Expand All @@ -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", "",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/client/client_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 47a9dda

Please sign in to comment.