2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // Calculate MTH hash of the file
31 "go.cypherpunks.ru/nncp/v8"
35 fmt.Fprintf(os.Stderr, nncp.UsageHeader())
36 fmt.Fprintf(os.Stderr, "nncp-hash -- calculate MTH hash of the file\n\n")
37 fmt.Fprintf(os.Stderr, "Usage: %s [-file ...] [-seek X] [-debug] [-progress] [options]\nOptions:\n", os.Args[0])
43 fn = flag.String("file", "", "Read the file instead of stdin")
44 seek = flag.Uint64("seek", 0, "Seek the file, hash, rewind, hash remaining")
45 forceFat = flag.Bool("force-fat", false, "Force MTHFat implementation usage")
46 showPrgrs = flag.Bool("progress", false, "Progress showing")
47 debug = flag.Bool("debug", false, "Print MTH steps calculations")
48 version = flag.Bool("version", false, "Print version information")
49 warranty = flag.Bool("warranty", false, "Print warranty information")
51 log.SetFlags(log.Lshortfile)
55 fmt.Println(nncp.Warranty)
59 fmt.Println(nncp.VersionGet())
69 fd, err = os.Open(*fn)
81 fmt.Println("Leaf BLAKE3 key:", hex.EncodeToString(nncp.MTHLeafKey[:]))
82 fmt.Println("Node BLAKE3 key:", hex.EncodeToString(nncp.MTHNodeKey[:]))
85 var debugger sync.WaitGroup
86 startDebug := func(events chan nncp.MTHEvent) {
89 for e := range events {
90 fmt.Println(e.String())
95 copier := func(w io.Writer) error {
96 _, err := nncp.CopyProgressed(
97 w, bufio.NewReaderSize(fd, nncp.MTHBlockSize), "hash",
98 nncp.LEs{{K: "Pkt", V: *fn}, {K: "FullSize", V: size - int64(*seek)}},
106 mth := nncp.MTHFatNew()
108 startDebug(mth.Events())
111 if err = copier(mth); err != nil {
116 mth := nncp.MTHSeqNew(size, int64(*seek))
118 startDebug(mth.Events())
122 log.Fatalln("-file is required with -seek")
124 if _, err = fd.Seek(int64(*seek), io.SeekStart); err != nil {
128 if err = copier(mth); err != nil {
132 if _, err = fd.Seek(0, io.SeekStart); err != nil {
135 if _, err = mth.PreaddFrom(
136 bufio.NewReaderSize(fd, nncp.MTHBlockSize),
145 fmt.Println(hex.EncodeToString(sum))