From: Sergey Matveev Date: Sat, 7 Jan 2017 16:19:09 +0000 (+0300) Subject: Move ensureRxDir to ctx file X-Git-Tag: 0.1~30 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=983b2a3873bac80795e0b445343e0ea30d999364;p=nncp.git Move ensureRxDir to ctx file --- diff --git a/src/cypherpunks.ru/nncp/ctx.go b/src/cypherpunks.ru/nncp/ctx.go index 3defbea..0d00803 100644 --- a/src/cypherpunks.ru/nncp/ctx.go +++ b/src/cypherpunks.ru/nncp/ctx.go @@ -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 +} diff --git a/src/cypherpunks.ru/nncp/llp.go b/src/cypherpunks.ru/nncp/llp.go index c286f7f..211c9a9 100644 --- a/src/cypherpunks.ru/nncp/llp.go +++ b/src/cypherpunks.ru/nncp/llp.go @@ -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...) }