]> Cypherpunks.ru repositories - nncp.git/commitdiff
Move ensureRxDir to ctx file
authorSergey Matveev <stargrave@stargrave.org>
Sat, 7 Jan 2017 16:19:09 +0000 (19:19 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 7 Jan 2017 16:19:09 +0000 (19:19 +0300)
src/cypherpunks.ru/nncp/ctx.go
src/cypherpunks.ru/nncp/llp.go

index 3defbeab5a6d948368e25656f9aa528b0036072c..0d00803a8aa3b432252e1524bb03819e9c25b75b 100644 (file)
@@ -20,6 +20,8 @@ package nncp
 
 import (
        "errors"
+       "os"
+       "path/filepath"
 )
 
 type Ctx struct {
@@ -51,3 +53,18 @@ func (ctx *Ctx) FindNode(id string) (*Node, error) {
        }
        return node, nil
 }
+
+func (ctx *Ctx) ensureRxDir(nodeId *NodeId) error {
+       dirPath := filepath.Join(ctx.Spool, nodeId.String(), string(TRx))
+       if err := os.MkdirAll(dirPath, os.FileMode(0700)); err != nil {
+               ctx.LogE("llp-ensure", SDS{"dir": dirPath, "err": err}, "")
+               return err
+       }
+       fd, err := os.Open(dirPath)
+       if err != nil {
+               ctx.LogE("llp-ensure", SDS{"dir": dirPath, "err": err}, "")
+               return err
+       }
+       fd.Close()
+       return nil
+}
index c286f7f2bce41b08841459bd79e642d304475e37..211c9a97e969def47e616102f596c1bf7b0afa82 100644 (file)
@@ -248,21 +248,6 @@ func (ctx *Ctx) infosOur(nodeId *NodeId, nice uint8) [][]byte {
        return payloadsSplit(payloads)
 }
 
-func (ctx *Ctx) ensureRxDir(nodeId *NodeId) error {
-       dirPath := filepath.Join(ctx.Spool, nodeId.String(), string(TRx))
-       if err := os.MkdirAll(dirPath, os.FileMode(0700)); err != nil {
-               ctx.LogE("llp-ensure", SDS{"dir": dirPath, "err": err}, "")
-               return err
-       }
-       fd, err := os.Open(dirPath)
-       if err != nil {
-               ctx.LogE("llp-ensure", SDS{"dir": dirPath, "err": err}, "")
-               return err
-       }
-       fd.Close()
-       return nil
-}
-
 func (ctx *Ctx) StartI(conn net.Conn, nodeId *NodeId, nice uint8, xxOnly *TRxTx) (*LLPState, error) {
        err := ctx.ensureRxDir(nodeId)
        if err != nil {
@@ -314,6 +299,7 @@ func (ctx *Ctx) StartI(conn net.Conn, nodeId *NodeId, nice uint8, xxOnly *TRxTx)
        if len(infosPayloads) > 0 {
                firstPayload = infosPayloads[0]
        }
+       // Pad first payload, to hide actual existing files
        for i := 0; i < (MaxLLPSize-len(firstPayload))/LLPHeadOverhead; i++ {
                firstPayload = append(firstPayload, LLPHaltMarshalized...)
        }
@@ -433,6 +419,7 @@ func (ctx *Ctx) StartR(conn net.Conn, nice uint8, xxOnly *TRxTx) (*LLPState, err
        if len(infosPayloads) > 0 {
                firstPayload = infosPayloads[0]
        }
+       // Pad first payload, to hide actual existing files
        for i := 0; i < (MaxLLPSize-len(firstPayload))/LLPHeadOverhead; i++ {
                firstPayload = append(firstPayload, LLPHaltMarshalized...)
        }