]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/tx.go
ACK
[nncp.git] / src / tx.go
index f9da81b03093f6c82d500da82d5f492dfa056f33..6e13f2ef3fbeb9e4f97fe61b99d1897f6a8f6c09 100644 (file)
--- a/src/tx.go
+++ b/src/tx.go
@@ -729,3 +729,39 @@ func (ctx *Ctx) TxTrns(node *Node, nice uint8, size int64, src io.Reader) error
        os.Symlink(nodePath, filepath.Join(ctx.Spool, node.Name))
        return err
 }
+
+func (ctx *Ctx) TxACK(
+       node *Node,
+       nice uint8,
+       hsh string,
+       minSize int64,
+) error {
+       hshRaw, err := Base32Codec.DecodeString(hsh)
+       if err != nil {
+               return err
+       }
+       if len(hshRaw) != MTHSize {
+               return errors.New("Invalid packet id size")
+       }
+       pkt, err := NewPkt(PktTypeACK, nice, []byte(hshRaw))
+       if err != nil {
+               return err
+       }
+       src := bytes.NewReader([]byte{})
+       _, _, err = ctx.Tx(node, pkt, nice, 0, minSize, MaxFileSize, src, hsh, nil)
+       les := LEs{
+               {"Type", "ack"},
+               {"Node", node.Id},
+               {"Nice", int(nice)},
+               {"Pkt", hsh},
+       }
+       logMsg := func(les LEs) string {
+               return fmt.Sprintf("ACK to %s of %s is sent", ctx.NodeName(node.Id), hsh)
+       }
+       if err == nil {
+               ctx.LogI("tx", les, logMsg)
+       } else {
+               ctx.LogE("tx", les, err, logMsg)
+       }
+       return err
+}