]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go
Forbid any later GNU GPL versions autousage
[nncp.git] / src / cypherpunks.ru / nncp / cmd / nncp-pkt / main.go
index f4de406a4b17eab7eb6b22cff66849d476cdc9d8..bdb18ad0d6ff94b6c41be187b06cb888ef275185 100644 (file)
@@ -1,11 +1,10 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2018 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
 
 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
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, version 3 of the License.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,7 +15,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-// Parse raw NNCP packet
+// Parse raw NNCP packet.
 package main
 
 import (
@@ -31,7 +30,6 @@ import (
 
        "cypherpunks.ru/nncp"
        "github.com/davecgh/go-xdr/xdr2"
-       "golang.org/x/crypto/blake2b"
 )
 
 func usage() {
@@ -44,6 +42,7 @@ func usage() {
 
 func main() {
        var (
+               overheads  = flag.Bool("overheads", false, "Print packet overheads")
                dump       = flag.Bool("dump", false, "Write decrypted/parsed payload to stdout")
                decompress = flag.Bool("decompress", false, "Try to zlib decompress dumped data")
                cfgPath    = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
@@ -61,8 +60,18 @@ func main() {
                return
        }
 
+       if *overheads {
+               fmt.Printf(
+                       "Plain: %d\nEncrypted: %d\nSize: %d\n",
+                       nncp.PktOverhead,
+                       nncp.PktEncOverhead,
+                       nncp.PktSizeOverhead,
+               )
+               return
+       }
+
        var err error
-       beginning := make([]byte, nncp.PktOverhead-8-2*blake2b.Size256)
+       beginning := make([]byte, nncp.PktOverhead)
        if _, err = io.ReadFull(os.Stdin, beginning); err != nil {
                log.Fatalln("Not enough data to read")
        }
@@ -114,14 +123,14 @@ func main() {
                        path = string(pkt.Path[:pkt.PathLen])
                }
                fmt.Printf(
-                       "Packet type: plain\nPayload type: %s\nNiceness: %d\nPath: %s\n",
-                       payloadType, pkt.Nice, path,
+                       "Packet type: plain\nPayload type: %s\nNiceness: %s (%d)\nPath: %s\n",
+                       payloadType, nncp.NicenessFmt(pkt.Nice), pkt.Nice, path,
                )
                return
        }
        var pktEnc nncp.PktEnc
        _, err = xdr.Unmarshal(bytes.NewReader(beginning), &pktEnc)
-       if err == nil && pktEnc.Magic == nncp.MagicNNCPEv3 {
+       if err == nil && pktEnc.Magic == nncp.MagicNNCPEv4 {
                if *dump {
                        ctx, err := nncp.CtxFromCmdline(*cfgPath, "", "", false, false)
                        if err != nil {
@@ -148,8 +157,8 @@ func main() {
                        return
                }
                fmt.Printf(
-                       "Packet type: encrypted\nNiceness: %d\nSender: %s\nRecipient: %s\n",
-                       pktEnc.Nice, pktEnc.Sender, pktEnc.Recipient,
+                       "Packet type: encrypted\nNiceness: %s (%d)\nSender: %s\nRecipient: %s\n",
+                       nncp.NicenessFmt(pktEnc.Nice), pktEnc.Nice, pktEnc.Sender, pktEnc.Recipient,
                )
                return
        }