From: Sergey Matveev Date: Wed, 22 Jan 2020 15:41:10 +0000 (+0300) Subject: Simplify code, no performance penalty X-Git-Tag: v5.3.3^2~3 X-Git-Url: http://www.git.cypherpunks.ru/?a=commitdiff_plain;h=0679d5b7cce7e041fb518babb222e4510eff776e;p=nncp.git Simplify code, no performance penalty --- diff --git a/src/cmd/nncp-bundle/main.go b/src/cmd/nncp-bundle/main.go index 859fe6f..c3613bd 100644 --- a/src/cmd/nncp-bundle/main.go +++ b/src/cmd/nncp-bundle/main.go @@ -182,22 +182,14 @@ func main() { } } else { bufStdin := bufio.NewReaderSize(os.Stdin, CopyBufSize*2) - var peeked []byte - var prefixIdx int - var tarR *tar.Reader - var entry *tar.Header - var exists bool pktEncBuf := make([]byte, nncp.PktEncOverhead) var pktEnc *nncp.PktEnc - var pktName string - var selfPath string - var dstPath string for { - peeked, err = bufStdin.Peek(CopyBufSize) + peeked, err := bufStdin.Peek(CopyBufSize) if err != nil && err != io.EOF { log.Fatalln("Error during reading:", err) } - prefixIdx = bytes.Index(peeked, []byte(nncp.NNCPBundlePrefix)) + prefixIdx := bytes.Index(peeked, []byte(nncp.NNCPBundlePrefix)) if prefixIdx == -1 { if err == io.EOF { break @@ -208,7 +200,7 @@ func main() { bufStdin.Discard(prefixIdx) tarR = tar.NewReader(bufStdin) sds["xx"] = string(nncp.TRx) - entry, err = tarR.Next() + entry, err := tarR.Next() if err != nil { if err != io.EOF { ctx.LogD( @@ -243,7 +235,7 @@ func main() { ctx.LogE("nncp-bundle", sds, errors.New("not enough spool space"), "") continue } - pktName = filepath.Base(entry.Name) + pktName := filepath.Base(entry.Name) if _, err = nncp.Base32Codec.DecodeString(pktName); err != nil { ctx.LogD("nncp-bundle", nncp.SdsAdd(sds, nncp.SDS{"err": "bad packet name"}), "") continue @@ -266,7 +258,7 @@ func main() { } if *pktEnc.Sender == *ctx.SelfId && *doDelete { if len(nodeIds) > 0 { - if _, exists = nodeIds[*pktEnc.Recipient]; !exists { + if _, exists := nodeIds[*pktEnc.Recipient]; !exists { ctx.LogD("nncp-bundle", sds, "Recipient is not requested") continue } @@ -275,7 +267,7 @@ func main() { sds["xx"] = string(nncp.TTx) sds["node"] = nodeId32 sds["pkt"] = pktName - dstPath = filepath.Join( + dstPath := filepath.Join( ctx.Spool, nodeId32, string(nncp.TTx), @@ -314,7 +306,7 @@ func main() { continue } if len(nodeIds) > 0 { - if _, exists = nodeIds[*pktEnc.Sender]; !exists { + if _, exists := nodeIds[*pktEnc.Sender]; !exists { ctx.LogD("nncp-bundle", sds, "Sender is not requested") continue } @@ -322,8 +314,8 @@ func main() { sds["node"] = nncp.Base32Codec.EncodeToString(pktEnc.Recipient[:]) sds["pkt"] = pktName sds["fullsize"] = entry.Size - selfPath = filepath.Join(ctx.Spool, ctx.SelfId.String(), string(nncp.TRx)) - dstPath = filepath.Join(selfPath, pktName) + selfPath := filepath.Join(ctx.Spool, ctx.SelfId.String(), string(nncp.TRx)) + dstPath := filepath.Join(selfPath, pktName) if _, err = os.Stat(dstPath); err == nil || !os.IsNotExist(err) { ctx.LogD("nncp-bundle", sds, "Packet already exists") continue