X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Ftx.go;h=6e13f2ef3fbeb9e4f97fe61b99d1897f6a8f6c09;hb=2e59e1d8da61bc5dee797d351e50e8ed114aa4c7;hp=77db5928d852daffe12e70b0414da3d2d336c8ec;hpb=1ef7f1ab8cc340afdea5a62ea8bf2a1e5ec1268a;p=nncp.git diff --git a/src/tx.go b/src/tx.go index 77db592..6e13f2e 100644 --- a/src/tx.go +++ b/src/tx.go @@ -453,7 +453,7 @@ func (ctx *Ctx) TxFile( } logMsg := func(les LEs) string { return fmt.Sprintf( - "File %s (%s) sent to %s:%s", + "File %s (%s) is sent to %s:%s", srcPath, humanize.IBytes(uint64(finalSize)), ctx.NodeName(node.Id), @@ -497,7 +497,7 @@ func (ctx *Ctx) TxFile( } logMsg := func(les LEs) string { return fmt.Sprintf( - "File %s (%s) sent to %s:%s", + "File %s (%s) is sent to %s:%s", srcPath, humanize.IBytes(uint64(size)), ctx.NodeName(node.Id), @@ -558,7 +558,7 @@ func (ctx *Ctx) TxFile( } logMsg := func(les LEs) string { return fmt.Sprintf( - "File %s (%s) sent to %s:%s", + "File %s (%s) is sent to %s:%s", srcPath, humanize.IBytes(uint64(metaPktSize)), ctx.NodeName(node.Id), @@ -604,7 +604,7 @@ func (ctx *Ctx) TxFreq( } logMsg := func(les LEs) string { return fmt.Sprintf( - "File request from %s:%s to %s sent", + "File request from %s:%s to %s is sent", ctx.NodeName(node.Id), srcPath, dstPath, ) @@ -675,7 +675,7 @@ func (ctx *Ctx) TxExec( } logMsg := func(les LEs) string { return fmt.Sprintf( - "Exec sent to %s@%s (%s)", + "Exec is sent to %s@%s (%s)", ctx.NodeName(node.Id), dst, humanize.IBytes(uint64(size)), ) } @@ -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 +}