X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcypherpunks.ru%2Fnncp%2Fcmd%2Fnncp-pkt%2Fmain.go;h=bdb18ad0d6ff94b6c41be187b06cb888ef275185;hb=dd92823db3d72fb21a4c712a7fb052dce16443dd;hp=f4de406a4b17eab7eb6b22cff66849d476cdc9d8;hpb=a4262555b0506c1cf85b9d5d4dae58bf3922e629;p=nncp.git diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go index f4de406..bdb18ad 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-pkt/main.go @@ -1,11 +1,10 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2018 Sergey Matveev +Copyright (C) 2016-2019 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 -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 . */ -// 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 }