X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcheck.go;h=4c1f542452420bda9a3446208c2dfc4b4a0a499c;hb=1d2ce674b042d07fd9b37a46578c8b62bb0345b7;hp=fdd6436f9049806ebe46d054a609f6b0839ccf33;hpb=dd887c15fa21071a2f4931f7248e10c4ab1029d2;p=nncp.git diff --git a/src/check.go b/src/check.go index fdd6436..4c1f542 100644 --- a/src/check.go +++ b/src/check.go @@ -20,46 +20,47 @@ package nncp import ( "bufio" "bytes" + "errors" "io" "log" "golang.org/x/crypto/blake2b" ) -func Check(src io.Reader, checksum []byte) (bool, error) { +func Check(src io.Reader, checksum []byte, sds SDS, showPrgrs bool) (bool, error) { hsh, err := blake2b.New256(nil) if err != nil { log.Fatalln(err) } - if _, err = io.Copy(hsh, bufio.NewReader(src)); err != nil { + if _, err = CopyProgressed(hsh, bufio.NewReader(src), sds, showPrgrs); err != nil { return false, err } return bytes.Compare(hsh.Sum(nil), checksum) == 0, nil } -func (ctx *Ctx) checkXx(nodeId *NodeId, xx TRxTx) bool { +func (ctx *Ctx) checkXxIsBad(nodeId *NodeId, xx TRxTx) bool { isBad := false for job := range ctx.Jobs(nodeId, xx) { sds := SDS{ - "xx": string(xx), - "node": nodeId, - "pkt": ToBase32(job.HshValue[:]), + "xx": string(xx), + "node": nodeId, + "pkt": ToBase32(job.HshValue[:]), + "fullsize": job.Size, } - ctx.LogP("check", sds, "") - gut, err := Check(job.Fd, job.HshValue[:]) + gut, err := Check(job.Fd, job.HshValue[:], sds, ctx.ShowPrgrs) job.Fd.Close() if err != nil { - ctx.LogE("check", SdsAdd(sds, SDS{"err": err}), "") - return false + ctx.LogE("check", sds, err, "") + return true } if !gut { isBad = true - ctx.LogE("check", sds, "bad") + ctx.LogE("check", sds, errors.New("bad"), "") } } return isBad } func (ctx *Ctx) Check(nodeId *NodeId) bool { - return ctx.checkXx(nodeId, TRx) || ctx.checkXx(nodeId, TTx) + return !(ctx.checkXxIsBad(nodeId, TRx) || ctx.checkXxIsBad(nodeId, TTx)) }