From 3312a29dde094c4dc0749234fcc8313638890f72 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 19 Nov 2017 18:28:02 +0100 Subject: [PATCH 1/2] lib/connections: Fix race condition in parallel dial, minor cleanups (fixes #4526) --- lib/connections/service.go | 4 ++-- lib/connections/structs.go | 6 +++++- lib/connections/tcp_listen.go | 13 ++++++------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/connections/service.go b/lib/connections/service.go index c197abf4..72cd1e79 100644 --- a/lib/connections/service.go +++ b/lib/connections/service.go @@ -746,13 +746,13 @@ func dialParallel(deviceID protocol.DeviceID, dialTargets []dialTarget) (interna wg := sync.NewWaitGroup() for _, tgt := range tgts { wg.Add(1) - go func() { + go func(tgt dialTarget) { conn, err := tgt.Dial() if err == nil { res <- conn } wg.Done() - }() + }(tgt) } // Spawn a routine which will unblock main routine in case we fail diff --git a/lib/connections/structs.go b/lib/connections/structs.go index 63336134..0dfad5b0 100644 --- a/lib/connections/structs.go +++ b/lib/connections/structs.go @@ -188,6 +188,10 @@ type dialTarget struct { func (t dialTarget) Dial() (internalConn, error) { l.Debugln("dialing", t.deviceID, t.uri, "prio", t.priority) conn, err := t.dialer.Dial(t.deviceID, t.uri) - l.Debugln("dialing", t.deviceID, t.uri, "outcome", conn, err) + if err != nil { + l.Debugln("dialing", t.deviceID, t.uri, "error:", err) + } else { + l.Debugln("dialing", t.deviceID, t.uri, "success:", conn) + } return conn, err } diff --git a/lib/connections/tcp_listen.go b/lib/connections/tcp_listen.go index 437dced3..1b9d4882 100644 --- a/lib/connections/tcp_listen.go +++ b/lib/connections/tcp_listen.go @@ -102,19 +102,18 @@ func (t *tcpListener) Serve() { l.Debugln("Listen (BEP/tcp): connect from", conn.RemoteAddr()) - err = dialer.SetTCPOptions(conn) - if err != nil { + if err := dialer.SetTCPOptions(conn); err != nil { l.Debugln("Listen (BEP/tcp): setting tcp options:", err) } - err = dialer.SetTrafficClass(conn, t.cfg.Options().TrafficClass) - if err != nil { - l.Debugln("Listen (BEP/tcp): setting traffic class:", err) + if tc := t.cfg.Options().TrafficClass; tc != 0 { + if err := dialer.SetTrafficClass(conn, tc); err != nil { + l.Debugln("Listen (BEP/tcp): setting traffic class:", err) + } } tc := tls.Server(conn, t.tlsCfg) - err = tlsTimedHandshake(tc) - if err != nil { + if err := tlsTimedHandshake(tc); err != nil { l.Infoln("Listen (BEP/tcp): TLS handshake:", err) tc.Close() continue From 00ce889a8b7e0a4b43a2c88d2d3ee6b0acb7e152 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 20 Nov 2017 08:10:18 +0100 Subject: [PATCH 2/2] build: Windows code signing (ref #3420) --- build.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/build.go b/build.go index 3744feb1..fd44beda 100644 --- a/build.go +++ b/build.go @@ -503,6 +503,10 @@ func buildZip(target target) { build(target, tags) + if goos == "windows" { + windowsCodesign(target.BinaryName()) + } + for i := range target.archiveFiles { target.archiveFiles[i].src = strings.Replace(target.archiveFiles[i].src, "{{binary}}", target.BinaryName(), 1) target.archiveFiles[i].dst = strings.Replace(target.archiveFiles[i].dst, "{{binary}}", target.BinaryName(), 1) @@ -1092,6 +1096,31 @@ func macosCodesign(file string) { } } +func windowsCodesign(file string) { + st := "signtool.exe" + args := []string{"sign", "/fd", "sha256"} + if path := os.Getenv("CODESIGN_SIGNTOOL"); path != "" { + st = path + } + if f := os.Getenv("CODESIGN_CERTIFICATE_FILE"); f != "" { + args = append(args, "/f", f) + } + if p := os.Getenv("CODESIGN_CERTIFICATE_PASSWORD"); p != "" { + args = append(args, "/p", p) + } + if tr := os.Getenv("CODESIGN_TIMESTAMP_SERVER"); tr != "" { + args = append(args, "/tr", tr, "/td", "sha256") + } + args = append(args, file) + + bs, err := runError(st, args...) + if err != nil { + log.Println("Codesign: signing failed:", string(bs)) + return + } + log.Println("Codesign: successfully signed", file) +} + func metalint() { lazyRebuildAssets() runPrint("go", "test", "-run", "Metalint", "./meta")