]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cmd/nncp-ack/main.go
Raise copyright years
[nncp.git] / src / cmd / nncp-ack / main.go
index 950295a7d81029f7b8b4dfc11815b454d0ea4d42..2fda750b5064302fbb8d50c1b0d3f4d87a3d498e 100644 (file)
@@ -1,6 +1,6 @@
 /*
 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
-Copyright (C) 2016-2022 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2016-2023 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
@@ -37,8 +37,8 @@ func usage() {
        fmt.Fprintf(os.Stderr, nncp.UsageHeader())
        fmt.Fprintf(os.Stderr, "nncp-ack -- send packet receipt acknowledgement\n\n")
        fmt.Fprintf(os.Stderr, "Usage: %s [options] -all\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "Usage: %s           -node NODE[,...]\n", os.Args[0])
-       fmt.Fprintf(os.Stderr, "Usage: %s           -node NODE -pkt PKT\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "Usage: %s [options] -node NODE[,...]\n", os.Args[0])
+       fmt.Fprintf(os.Stderr, "Usage: %s [options] -node NODE -pkt PKT\n", os.Args[0])
        fmt.Fprintln(os.Stderr, "Options:")
        flag.PrintDefaults()
 }
@@ -119,15 +119,22 @@ func main() {
                os.Exit(1)
        }
 
+       acksCreated := os.NewFile(uintptr(4), "ACKsCreated")
+       if acksCreated == nil {
+               log.Fatalln("can not open FD:4")
+       }
+
        if *pktRaw != "" {
                if len(nodes) != 1 {
                        usage()
                        os.Exit(1)
                }
                nncp.ViaOverride(*viaOverride, ctx, nodes[0])
-               if err = ctx.TxACK(nodes[0], nice, *pktRaw, minSize); err != nil {
+               pktName, err := ctx.TxACK(nodes[0], nice, *pktRaw, minSize)
+               if err != nil {
                        log.Fatalln(err)
                }
+               acksCreated.WriteString(nodes[0].Id.String() + "/" + pktName + "\n")
                return
        }
 
@@ -199,7 +206,12 @@ func main() {
                                continue
                        }
                        pipeR, pipeW := io.Pipe()
-                       go nncp.PktEncRead(ctx.Self, ctx.Neigh, bufio.NewReader(fd), pipeW, true, nil)
+                       go nncp.PktEncRead(
+                               ctx.Self,
+                               ctx.Neigh,
+                               bufio.NewReaderSize(fd, nncp.MTHBlockSize),
+                               pipeW, true, nil,
+                       )
                        var pkt nncp.Pkt
                        _, err = xdr.Unmarshal(pipeR, &pkt)
                        fd.Close()
@@ -217,9 +229,11 @@ func main() {
                                })
                                continue
                        }
-                       if err = ctx.TxACK(node, nice, pktName, minSize); err != nil {
+                       newPktName, err := ctx.TxACK(node, nice, pktName, minSize)
+                       if err != nil {
                                log.Fatalln(err)
                        }
+                       acksCreated.WriteString(node.Id.String() + "/" + newPktName + "\n")
                }
        }
        if isBad {