]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-pkt/main.go
Simplify Base32-related code
[nncp.git] / src / cmd / nncp-pkt / main.go
index 82da1d35b7673e9fd9b340aae77291e4a9abfa71..126497484ddeda0521139430cb6036a5a484be93 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2019 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2020 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
@@ -21,14 +21,14 @@ package main
 import (
        "bufio"
        "bytes"
-       "compress/zlib"
        "flag"
        "fmt"
        "io"
        "log"
        "os"
 
-       "github.com/davecgh/go-xdr/xdr2"
+       xdr "github.com/davecgh/go-xdr/xdr2"
+       "github.com/klauspost/compress/zstd"
        "go.cypherpunks.ru/nncp/v5"
 )
 
@@ -44,7 +44,7 @@ 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")
+               decompress = flag.Bool("decompress", false, "Try to zstd decompress dumped data")
                cfgPath    = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
                version    = flag.Bool("version", false, "Print version information")
                warranty   = flag.Bool("warranty", false, "Print warranty information")
@@ -77,13 +77,13 @@ func main() {
        }
        var pkt nncp.Pkt
        _, err = xdr.Unmarshal(bytes.NewReader(beginning), &pkt)
-       if err == nil && pkt.Magic == nncp.MagicNNCPPv2 {
+       if err == nil && pkt.Magic == nncp.MagicNNCPPv3 {
                if *dump {
                        bufW := bufio.NewWriter(os.Stdout)
                        var r io.Reader
                        r = bufio.NewReader(os.Stdin)
                        if *decompress {
-                               decompressor, err := zlib.NewReader(r)
+                               decompressor, err := zstd.NewReader(r)
                                if err != nil {
                                        log.Fatalln(err)
                                }
@@ -118,7 +118,7 @@ func main() {
                                -1,
                        ))
                case nncp.PktTypeTrns:
-                       path = nncp.ToBase32(pkt.Path[:pkt.PathLen])
+                       path = nncp.Base32Codec.EncodeToString(pkt.Path[:pkt.PathLen])
                default:
                        path = string(pkt.Path[:pkt.PathLen])
                }
@@ -132,7 +132,7 @@ func main() {
        _, err = xdr.Unmarshal(bytes.NewReader(beginning), &pktEnc)
        if err == nil && pktEnc.Magic == nncp.MagicNNCPEv4 {
                if *dump {
-                       ctx, err := nncp.CtxFromCmdline(*cfgPath, "", "", false, false)
+                       ctx, err := nncp.CtxFromCmdline(*cfgPath, "", "", false, false, false, false)
                        if err != nil {
                                log.Fatalln("Error during initialization:", err)
                        }