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/v7"
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 showPrgrs = flag.Bool("progress", false, "Progress showing")
46 debug = flag.Bool("debug", false, "Print MTH steps calculations")
47 version = flag.Bool("version", false, "Print version information")
48 warranty = flag.Bool("warranty", false, "Print warranty information")
50 log.SetFlags(log.Lshortfile)
54 fmt.Println(nncp.Warranty)
58 fmt.Println(nncp.VersionGet())
68 fd, err = os.Open(*fn)
78 mth := nncp.MTHNew(size, int64(*seek))
79 var debugger sync.WaitGroup
81 fmt.Println("Leaf BLAKE3 key:", hex.EncodeToString(nncp.MTHLeafKey[:]))
82 fmt.Println("Node BLAKE3 key:", hex.EncodeToString(nncp.MTHNodeKey[:]))
83 mth.Events = make(chan nncp.MTHEvent)
86 for e := range mth.Events {
89 case nncp.MTHEventAppend:
91 case nncp.MTHEventPrepend:
93 case nncp.MTHEventFold:
97 "%s\t%03d\t%06d\t%s\n",
98 t, e.Level, e.Ctr, hex.EncodeToString(e.Hsh),
106 log.Fatalln("-file is required with -seek")
108 if _, err = fd.Seek(int64(*seek), io.SeekStart); err != nil {
112 if _, err = nncp.CopyProgressed(
113 mth, bufio.NewReaderSize(fd, nncp.MTHBlockSize),
114 "hash", nncp.LEs{{K: "Pkt", V: *fn}, {K: "FullSize", V: size - int64(*seek)}},
120 if _, err = fd.Seek(0, io.SeekStart); err != nil {
126 if _, err = mth.PrependFrom(bufio.NewReaderSize(fd, nncp.MTHBlockSize)); err != nil {
132 fmt.Println(hex.EncodeToString(sum))