]> Cypherpunks.ru repositories - nncp.git/commitdiff
nncp-show shows .part
authorSergey Matveev <stargrave@stargrave.org>
Wed, 30 Jun 2021 09:38:24 +0000 (12:38 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 30 Jun 2021 11:10:12 +0000 (14:10 +0300)
doc/news.ru.texi
doc/news.texi
src/cmd/nncp-stat/main.go
src/jobs.go

index 191b513defe1c97d1f86729f83566c5e7457b1a7..c045d753c72f16c377bc436971f997231c984fa8 100644 (file)
@@ -37,6 +37,9 @@ MultiCast Discovery использует
 @item
 @command{nncp-cfgenc} ошибочно трижды спрашивал парольную фразу при шифровании.
 
+@item
+@command{nncp-stat} выводит сводку о частично скачанных пакетах.
+
 @item
 Обновлены зависимые библиотеки.
 
index f7a2e820ec4b21d805e6c336af62faa9ad5eda61..cc4eba943acd1d41550398bca9c27c03ab8571bf 100644 (file)
@@ -38,6 +38,9 @@ MultiCast Discovery uses
 @item
 @command{nncp-cfgenc} mistakenly asked passphrase three times during encryption.
 
+@item
+@command{nncp-stat} reports about partly downloaded packets.
+
 @item
 Updated dependencies.
 
index 2f7cdc4436877c0e54aefdb3c7e67a80e3019a56..ea5f407dfddd8738d26f41ffa1311cfbf0b4264e 100644 (file)
@@ -36,11 +36,11 @@ func usage() {
        flag.PrintDefaults()
 }
 
-func jobPrint(xx nncp.TRxTx, job nncp.Job) {
+func jobPrint(xx nncp.TRxTx, job nncp.Job, suffix string) {
        fmt.Printf(
-               "\t%s %s %s (nice: %s)\n",
+               "\t%s %s%s %s (nice: %s)\n",
                string(xx),
-               nncp.Base32Codec.EncodeToString(job.HshValue[:]),
+               nncp.Base32Codec.EncodeToString(job.HshValue[:]), suffix,
                humanize.IBytes(uint64(job.Size)),
                nncp.NicenessFmt(job.PktEnc.Nice),
        )
@@ -101,30 +101,50 @@ func main() {
                rxBytes := make(map[uint8]int64)
                noCKNums := make(map[uint8]int)
                noCKBytes := make(map[uint8]int64)
+               partNums := 0
+               partBytes := int64(0)
                for job := range ctx.Jobs(node.Id, nncp.TRx) {
                        if *showPkt {
-                               jobPrint(nncp.TRx, job)
+                               jobPrint(nncp.TRx, job, "")
                        }
                        rxNums[job.PktEnc.Nice] = rxNums[job.PktEnc.Nice] + 1
                        rxBytes[job.PktEnc.Nice] = rxBytes[job.PktEnc.Nice] + job.Size
                }
                for job := range ctx.JobsNoCK(node.Id) {
                        if *showPkt {
-                               jobPrint(nncp.TRx, job)
+                               jobPrint(nncp.TRx, job, ".nock")
                        }
                        noCKNums[job.PktEnc.Nice] = noCKNums[job.PktEnc.Nice] + 1
                        noCKBytes[job.PktEnc.Nice] = noCKBytes[job.PktEnc.Nice] + job.Size
                }
+               for job := range ctx.JobsPart(node.Id) {
+                       if *showPkt {
+                               fmt.Printf(
+                                       "\t%s %s.part %s\n",
+                                       string(nncp.TRx),
+                                       nncp.Base32Codec.EncodeToString(job.HshValue[:]),
+                                       humanize.IBytes(uint64(job.Size)),
+                               )
+                       }
+                       partNums++
+                       partBytes += job.Size
+               }
                txNums := make(map[uint8]int)
                txBytes := make(map[uint8]int64)
                for job := range ctx.Jobs(node.Id, nncp.TTx) {
                        if *showPkt {
-                               jobPrint(nncp.TTx, job)
+                               jobPrint(nncp.TTx, job, "")
                        }
                        txNums[job.PktEnc.Nice] = txNums[job.PktEnc.Nice] + 1
                        txBytes[job.PktEnc.Nice] = txBytes[job.PktEnc.Nice] + job.Size
                }
                var nice uint8
+               if partNums > 0 {
+                       fmt.Printf(
+                               "\tpart: % 10s, % 3d pkts\n",
+                               humanize.IBytes(uint64(partBytes)), partNums,
+                       )
+               }
                for nice = 1; nice > 0; nice++ {
                        rxNum, rxExists := rxNums[nice]
                        txNum, txExists := txNums[nice]
index e1344ebf65b8b21c33e136d45eeed4b1292f245b..0819738f4033b4ffdc8022b9d9adf600e308289c 100644 (file)
@@ -88,7 +88,7 @@ func (ctx *Ctx) HdrWrite(pktEncRaw []byte, tgt string) error {
        return err
 }
 
-func (ctx *Ctx) jobsFind(nodeId *NodeId, xx TRxTx, nock bool) chan Job {
+func (ctx *Ctx) jobsFind(nodeId *NodeId, xx TRxTx, nock, part bool) chan Job {
        rxPath := filepath.Join(ctx.Spool, nodeId.String(), string(xx))
        jobs := make(chan Job, 16)
        go func() {
@@ -113,6 +113,14 @@ func (ctx *Ctx) jobsFind(nodeId *NodeId, xx TRxTx, nock bool) chan Job {
                                hshValue, err = Base32Codec.DecodeString(
                                        strings.TrimSuffix(name, NoCKSuffix),
                                )
+                       } else if part {
+                               if !strings.HasSuffix(name, PartSuffix) ||
+                                       len(name) != Base32Encoded32Len+len(PartSuffix) {
+                                       continue
+                               }
+                               hshValue, err = Base32Codec.DecodeString(
+                                       strings.TrimSuffix(name, PartSuffix),
+                               )
                        } else {
                                if len(name) != Base32Encoded32Len {
                                        continue
@@ -125,7 +133,7 @@ func (ctx *Ctx) jobsFind(nodeId *NodeId, xx TRxTx, nock bool) chan Job {
                        pth := filepath.Join(rxPath, name)
                        hdrExists := true
                        var fd *os.File
-                       if nock {
+                       if nock || part {
                                fd, err = os.Open(pth)
                        } else {
                                fd, err = os.Open(pth + HdrSuffix)
@@ -137,9 +145,46 @@ func (ctx *Ctx) jobsFind(nodeId *NodeId, xx TRxTx, nock bool) chan Job {
                        if err != nil {
                                continue
                        }
+                       if part {
+                               job := Job{
+                                       Path:     pth,
+                                       Size:     fi.Size(),
+                                       HshValue: new([MTHSize]byte),
+                               }
+                               copy(job.HshValue[:], hshValue)
+                               jobs <- job
+                               continue
+                       }
                        pktEnc, pktEncRaw, err := ctx.HdrRead(fd)
                        fd.Close()
-                       if err != nil || pktEnc.Magic != MagicNNCPEv5.B {
+                       if err != nil {
+                               continue
+                       }
+                       switch pktEnc.Magic {
+                       case MagicNNCPEv1.B:
+                               err = MagicNNCPEv1.TooOld()
+                       case MagicNNCPEv2.B:
+                               err = MagicNNCPEv2.TooOld()
+                       case MagicNNCPEv3.B:
+                               err = MagicNNCPEv3.TooOld()
+                       case MagicNNCPEv4.B:
+                               err = MagicNNCPEv4.TooOld()
+                       case MagicNNCPEv5.B:
+                       default:
+                               err = BadMagic
+                       }
+                       if err != nil {
+                               ctx.LogE("job", LEs{
+                                       {"XX", string(xx)},
+                                       {"Name", name},
+                                       {"Size", fi.Size()},
+                               }, err, func(les LEs) string {
+                                       return fmt.Sprintf(
+                                               "Job %s/%s size: %s",
+                                               string(xx), name,
+                                               humanize.IBytes(uint64(fi.Size())),
+                                       )
+                               })
                                continue
                        }
                        ctx.LogD("job", LEs{
@@ -173,9 +218,13 @@ func (ctx *Ctx) jobsFind(nodeId *NodeId, xx TRxTx, nock bool) chan Job {
 }
 
 func (ctx *Ctx) Jobs(nodeId *NodeId, xx TRxTx) chan Job {
-       return ctx.jobsFind(nodeId, xx, false)
+       return ctx.jobsFind(nodeId, xx, false, false)
 }
 
 func (ctx *Ctx) JobsNoCK(nodeId *NodeId) chan Job {
-       return ctx.jobsFind(nodeId, TRx, true)
+       return ctx.jobsFind(nodeId, TRx, true, false)
+}
+
+func (ctx *Ctx) JobsPart(nodeId *NodeId) chan Job {
+       return ctx.jobsFind(nodeId, TRx, false, true)
 }