]> 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 f6327419a93d845f669bdafbf54fa2e595097b11..bdb18ad0d6ff94b6c41be187b06cb888ef275185 100644 (file)
@@ -4,8 +4,7 @@ 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
@@ -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")
        }
@@ -121,7 +130,7 @@ func main() {
        }
        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 {