X-Git-Url: http://www.git.cypherpunks.ru/?p=nncp.git;a=blobdiff_plain;f=src%2Ftx.go;h=6e13f2ef3fbeb9e4f97fe61b99d1897f6a8f6c09;hp=f9da81b03093f6c82d500da82d5f492dfa056f33;hb=2e59e1d8da61bc5dee797d351e50e8ed114aa4c7;hpb=2cad23b498bbb9fc1e929b4900b40e520017c614 diff --git a/src/tx.go b/src/tx.go index f9da81b..6e13f2e 100644 --- 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 +}