X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-xfer%2Fmain.go;h=a1ef5fa5d51c438179b33450f7876352d62d5242;hb=2cad23b498bbb9fc1e929b4900b40e520017c614;hp=b65686c8d14b6caa7d271d00053a13574075674d;hpb=b47dbfe6687569650fa544a4ecf3e4ea388390cb;p=nncp.git diff --git a/src/cmd/nncp-xfer/main.go b/src/cmd/nncp-xfer/main.go index b65686c..a1ef5fa 100644 --- a/src/cmd/nncp-xfer/main.go +++ b/src/cmd/nncp-xfer/main.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 Sergey Matveev +Copyright (C) 2016-2022 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -218,7 +218,7 @@ func main() { continue } pktEnc, pktEncRaw, err := ctx.HdrRead(fd) - if err != nil { + if err == nil { switch pktEnc.Magic { case nncp.MagicNNCPEv1.B: err = nncp.MagicNNCPEv1.TooOld() @@ -229,6 +229,8 @@ func main() { case nncp.MagicNNCPEv4.B: err = nncp.MagicNNCPEv4.TooOld() case nncp.MagicNNCPEv5.B: + err = nncp.MagicNNCPEv5.TooOld() + case nncp.MagicNNCPEv6.B: default: err = errors.New("is not an encrypted packet") } @@ -264,7 +266,7 @@ func main() { fd.Close() continue } - if _, err = fd.Seek(0, 0); err != nil { + if _, err = fd.Seek(0, io.SeekStart); err != nil { log.Fatalln(err) } tmp, err := ctx.NewTmpFileWHash() @@ -282,7 +284,7 @@ func main() { w.CloseWithError(err) } }() - if _, err = nncp.CopyProgressed( + _, err = nncp.CopyProgressed( tmp.W, r, "Rx", append( les, @@ -290,13 +292,24 @@ func main() { nncp.LE{K: "FullSize", V: fiInt.Size()}, ), ctx.ShowPrgrs, - ); err != nil { + ) + fd.Close() + if err != nil { ctx.LogE("xfer-rx", les, err, logMsg) + tmp.Cancel() isBad = true + continue } - fd.Close() - if isBad { + if err = tmp.W.Flush(); err != nil { + ctx.LogE("xfer-rx", les, err, logMsg) tmp.Cancel() + isBad = true + continue + } + if tmp.Checksum() != fiInt.Name() { + ctx.LogE("xfer-rx", les, errors.New("checksum mismatch"), logMsg) + tmp.Cancel() + isBad = true continue } if err = tmp.Commit(filepath.Join( @@ -475,13 +488,15 @@ Tx: isBad = true continue } - if err = tmp.Sync(); err != nil { - tmp.Close() - ctx.LogE("xfer-tx-sync", les, err, func(les nncp.LEs) string { - return logMsg(les) + ": syncing" - }) - isBad = true - continue + if !nncp.NoSync { + if err = tmp.Sync(); err != nil { + tmp.Close() + ctx.LogE("xfer-tx-sync", les, err, func(les nncp.LEs) string { + return logMsg(les) + ": syncing" + }) + isBad = true + continue + } } if err = tmp.Close(); err != nil { ctx.LogE("xfer-tx-close", les, err, func(les nncp.LEs) string {