]> Cypherpunks.ru repositories - nncp.git/commitdiff
Merge branch 'develop' 0.9
authorSergey Matveev <stargrave@stargrave.org>
Sun, 11 Jun 2017 09:54:22 +0000 (12:54 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 11 Jun 2017 09:54:22 +0000 (12:54 +0300)
15 files changed:
VERSION
doc/download.texi
doc/news.ru.texi
doc/news.texi
ports/nncp/Makefile
src/cypherpunks.ru/nncp/call.go
src/cypherpunks.ru/nncp/cfg.go
src/cypherpunks.ru/nncp/cmd/nncp-call/main.go
src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go
src/cypherpunks.ru/nncp/humanizer.go
src/cypherpunks.ru/nncp/lockdir.go [new file with mode: 0644]
src/cypherpunks.ru/nncp/node.go
src/cypherpunks.ru/nncp/sp.go
src/cypherpunks.ru/nncp/toss.go
src/golang.org/x/sys

diff --git a/VERSION b/VERSION
index aec258df73d39d2122706793921981f4a0f672f8..b63ba696b7a7e4d89fa1517b02bfdccb2f1a10e1 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.8
+0.9
index 213d429645714e481fbd34614220944b4bba6a0d..887f5167b5832577524b3159b7005ec9b81dde43 100644 (file)
@@ -24,6 +24,10 @@ Tarballs include all necessary required libraries:
 @multitable {XXXXX} {XXXX KiB} {link sign} {xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}
 @headitem Version @tab Size @tab Tarball @tab SHA256 checksum
 
+@item @ref{Release 0.8, 0.8} @tab 932 KiB
+@tab @url{download/nncp-0.8.tar.xz, link} @url{download/nncp-0.8.tar.xz.sig, sign}
+@tab @code{9BD607D5 C5551857 B7E9277D 0E857936 1DB7353A E0F1556E EA9B1D91 8305B184}
+
 @item @ref{Release 0.7, 0.7} @tab 783 KiB
 @tab @url{download/nncp-0.7.tar.xz, link} @url{download/nncp-0.7.tar.xz.sig, sign}
 @tab @code{D3407323 F89296DD 743FA764 51964B43 794E61BE 0E1D2DD4 ABD02042 B94FFC4F}
index cae730d0108cec0eeda0284ab49b5f3a27e34c91..668c4fef6c59f7fb30cd7cd5ef71d1a36c16746d 100644 (file)
@@ -1,6 +1,14 @@
 @node Новости
 @section Новости
 
+@node Релиз 0.9
+@subsection Релиз 0.9
+@itemize
+@item
+Исправлена обработка @option{-rx}/@option{-tx} опций @command{nncp-call}
+команды. Они игнорировались.
+@end itemize
+
 @node Релиз 0.8
 @subsection Релиз 0.8
 @itemize
index 0358a6c1cf865e0b4877d790d52a1b996cf91f89..3d55767e0f2550d8c8dc387283cc6a55c17ff67e 100644 (file)
@@ -3,6 +3,14 @@
 
 See also this page @ref{Новости, on russian}.
 
+@node Release 0.9
+@section Release 0.9
+@itemize
+@item
+Fix @option{-rx}/@option{-tx} arguments processing in
+@command{nncp-call} command. They were ignored.
+@end itemize
+
 @node Release 0.8
 @section Release 0.8
 @itemize
index e4086f77acb708d40f317cdd40a9dd4e983c7a5d..00e5818cb23fee2933856cd6fdcb076853e5c8d9 100644 (file)
@@ -1,7 +1,7 @@
 # $FreeBSD$
 
 PORTNAME=      nncp
-PORTVERSION=   0.8
+PORTVERSION=   0.9
 CATEGORIES=    net
 MASTER_SITES=  http://www.nncpgo.org/download/ \
                http://sourceforge.net/projects/nncp/files/
index 5b8e0584a4f334599f702d0273d8fdd5d5fb0ecf..496720a2bc9499a65793075f7b132a5a3830f2e2 100644 (file)
@@ -23,7 +23,7 @@ import (
        "strconv"
 )
 
-func (ctx *Ctx) CallNode(node *Node, addrs []string, nice uint8, xxOnly *TRxTx, onlineDeadline, maxOnlineTime uint) (isGood bool) {
+func (ctx *Ctx) CallNode(node *Node, addrs []string, nice uint8, xxOnly TRxTx, onlineDeadline, maxOnlineTime uint) (isGood bool) {
        for _, addr := range addrs {
                sds := SDS{"node": node.Id, "addr": addr}
                ctx.LogD("call", sds, "dialing")
index 3400ed83a93e7d850f85da7b47653497592e14a9..3a642f68567ff4487630dab5e3b96b676d5cba34 100644 (file)
@@ -64,7 +64,7 @@ type NodeYAML struct {
 type CallYAML struct {
        Cron           string
        Nice           *int    `nice,omitempty`
-       Xx             *string `xx,omitempty`
+       Xx             string  `xx,omitempty`
        Addr           *string `addr,omitempty`
        OnlineDeadline *uint   `onlinedeadline,omitempty`
        MaxOnlineTime  *uint   `maxonlinetime,omitempty`
@@ -187,15 +187,14 @@ func NewNode(name string, yml NodeYAML) (*Node, error) {
                        nice = uint8(*callYml.Nice)
                }
                var xx TRxTx
-               if callYml.Xx != nil {
-                       switch *callYml.Xx {
-                       case "rx":
-                               xx = TRx
-                       case "tx":
-                               xx = TTx
-                       default:
-                               return nil, errors.New("xx field must be either \"rx\" or \"tx\"")
-                       }
+               switch callYml.Xx {
+               case "rx":
+                       xx = TRx
+               case "tx":
+                       xx = TTx
+               case "":
+               default:
+                       return nil, errors.New("xx field must be either \"rx\" or \"tx\"")
                }
                var addr *string
                if callYml.Addr != nil {
@@ -219,7 +218,7 @@ func NewNode(name string, yml NodeYAML) (*Node, error) {
                calls = append(calls, &Call{
                        Cron:           expr,
                        Nice:           nice,
-                       Xx:             &xx,
+                       Xx:             xx,
                        Addr:           addr,
                        OnlineDeadline: onlineDeadline,
                        MaxOnlineTime:  maxOnlineTime,
index 9694639dc6356cbdacb018f7240afcbc6910d749..42f761faa10c9952964a4f96857d61b1b4869132 100644 (file)
@@ -126,7 +126,7 @@ func main() {
                }
        }
 
-       if !ctx.CallNode(node, addrs, nice, &xxOnly, *onlineDeadline, *maxOnlineTime) {
+       if !ctx.CallNode(node, addrs, nice, xxOnly, *onlineDeadline, *maxOnlineTime) {
                os.Exit(1)
        }
 }
index b3678cde1ad0e28425dc4a1a9866363932ab5130..e6ec2d385648ae1c84c8e959cc381addbc3d8e92 100644 (file)
@@ -91,7 +91,7 @@ func main() {
                }
                ctx.LogD("daemon", nncp.SDS{"addr": conn.RemoteAddr()}, "accepted")
                go func(conn net.Conn) {
-                       state, err := ctx.StartR(conn, nice, nil)
+                       state, err := ctx.StartR(conn, nice, "")
                        if err == nil {
                                ctx.LogI("call-start", nncp.SDS{"node": state.Node.Id}, "connected")
                                state.Wait()
index 49b715a1c91f6c7c118196b0bf7e948c0aac4a02..7abfcab0aec30113aa18d4f5a91fdef533037d4e 100644 (file)
@@ -237,6 +237,8 @@ func (ctx *Ctx) Humanize(s string) string {
                if err, exists := sds["err"]; exists {
                        msg += ": " + err
                }
+       case "lockdir":
+               msg = fmt.Sprintf("Acquire lock for %s: %s", sds["path"], sds["err"])
        default:
                return s
        }
diff --git a/src/cypherpunks.ru/nncp/lockdir.go b/src/cypherpunks.ru/nncp/lockdir.go
new file mode 100644 (file)
index 0000000..25316b8
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+NNCP -- Node to Node copy, utilities for store-and-forward data exchange
+Copyright (C) 2016-2017 Sergey Matveev <stargrave@stargrave.org>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package nncp
+
+import (
+       "os"
+       "path/filepath"
+
+       "golang.org/x/sys/unix"
+)
+
+func (ctx *Ctx) LockDir(nodeId *NodeId, xx TRxTx) (*os.File, error) {
+       ctx.ensureRxDir(nodeId)
+       lockPath := filepath.Join(ctx.Spool, nodeId.String(), string(xx)) + ".lock"
+       dirLock, err := os.OpenFile(
+               lockPath,
+               os.O_CREATE|os.O_WRONLY,
+               os.FileMode(0600),
+       )
+       if err != nil {
+               ctx.LogE("lockdir", SDS{"path": lockPath, "err": err}, "")
+               return nil, err
+       }
+       err = unix.Flock(int(dirLock.Fd()), unix.LOCK_EX|unix.LOCK_NB)
+       if err != nil {
+               ctx.LogE("lockdir", SDS{"path": lockPath, "err": err}, "")
+               dirLock.Close()
+               return nil, err
+       }
+       return dirLock, nil
+}
+
+func (ctx *Ctx) UnlockDir(fd *os.File) {
+       if fd != nil {
+               unix.Flock(int(fd.Fd()), unix.LOCK_UN)
+               fd.Close()
+       }
+}
index 22fa3fb2e03663f81f47c7ba06633d2209ea9934..1ea490309ff45b2146d3e6b22b0317d6b222508e 100644 (file)
@@ -70,7 +70,7 @@ type NodeOur struct {
 type Call struct {
        Cron           *cronexpr.Expression
        Nice           uint8
-       Xx             *TRxTx
+       Xx             TRxTx
        Addr           *string
        OnlineDeadline uint
        MaxOnlineTime  uint
index 8b64be1a68e24505513fa4d6476a895a525df180..be845109752a79b2393dfdb8be20b716c5584621 100644 (file)
@@ -180,7 +180,7 @@ type SPState struct {
        TxSpeed        int64
        rxLock         *os.File
        txLock         *os.File
-       xxOnly         *TRxTx
+       xxOnly         TRxTx
        isDead         bool
        sync.RWMutex
 }
@@ -264,20 +264,20 @@ func (ctx *Ctx) infosOur(nodeId *NodeId, nice uint8, seen *map[[32]byte]struct{}
        return payloadsSplit(payloads)
 }
 
-func (ctx *Ctx) StartI(conn net.Conn, nodeId *NodeId, nice uint8, xxOnly *TRxTx, onlineDeadline, maxOnlineTime uint) (*SPState, error) {
+func (ctx *Ctx) StartI(conn net.Conn, nodeId *NodeId, nice uint8, xxOnly TRxTx, onlineDeadline, maxOnlineTime uint) (*SPState, error) {
        err := ctx.ensureRxDir(nodeId)
        if err != nil {
                return nil, err
        }
        var rxLock *os.File
-       if xxOnly != nil && *xxOnly == TRx {
+       if xxOnly == "" || xxOnly == TRx {
                rxLock, err = ctx.LockDir(nodeId, TRx)
                if err != nil {
                        return nil, err
                }
        }
        var txLock *os.File
-       if xxOnly != nil && *xxOnly == TTx {
+       if xxOnly == "" || xxOnly == TTx {
                txLock, err = ctx.LockDir(nodeId, TTx)
                if err != nil {
                        return nil, err
@@ -312,7 +312,7 @@ func (ctx *Ctx) StartI(conn net.Conn, nodeId *NodeId, nice uint8, xxOnly *TRxTx,
        }
 
        var infosPayloads [][]byte
-       if xxOnly == nil || *xxOnly != TTx {
+       if xxOnly == "" || xxOnly == TTx {
                infosPayloads = ctx.infosOur(nodeId, nice, &state.infosOurSeen)
        }
        var firstPayload []byte
@@ -358,7 +358,7 @@ func (ctx *Ctx) StartI(conn net.Conn, nodeId *NodeId, nice uint8, xxOnly *TRxTx,
        return &state, err
 }
 
-func (ctx *Ctx) StartR(conn net.Conn, nice uint8, xxOnly *TRxTx) (*SPState, error) {
+func (ctx *Ctx) StartR(conn net.Conn, nice uint8, xxOnly TRxTx) (*SPState, error) {
        started := time.Now()
        conf := noise.Config{
                CipherSuite: NoiseCipherSuite,
@@ -417,7 +417,7 @@ func (ctx *Ctx) StartR(conn net.Conn, nice uint8, xxOnly *TRxTx) (*SPState, erro
                return nil, err
        }
        var rxLock *os.File
-       if xxOnly != nil && *xxOnly == TRx {
+       if xxOnly == "" || xxOnly == TRx {
                rxLock, err = ctx.LockDir(node.Id, TRx)
                if err != nil {
                        return nil, err
@@ -425,7 +425,7 @@ func (ctx *Ctx) StartR(conn net.Conn, nice uint8, xxOnly *TRxTx) (*SPState, erro
        }
        state.rxLock = rxLock
        var txLock *os.File
-       if xxOnly != nil && *xxOnly == TTx {
+       if xxOnly == "" || xxOnly == TTx {
                txLock, err = ctx.LockDir(node.Id, TTx)
                if err != nil {
                        return nil, err
@@ -434,7 +434,7 @@ func (ctx *Ctx) StartR(conn net.Conn, nice uint8, xxOnly *TRxTx) (*SPState, erro
        state.txLock = txLock
 
        var infosPayloads [][]byte
-       if xxOnly == nil || *xxOnly != TTx {
+       if xxOnly == "" || xxOnly == TTx {
                infosPayloads = ctx.infosOur(node.Id, nice, &state.infosOurSeen)
        }
        var firstPayload []byte
@@ -499,22 +499,24 @@ func (state *SPState) StartWorkers(conn net.Conn, infosPayloads [][]byte, payloa
                }
        }()
 
-       go func() {
-               for range time.Tick(time.Second) {
-                       for _, payload := range state.ctx.infosOur(
-                               state.Node.Id,
-                               state.nice,
-                               &state.infosOurSeen,
-                       ) {
-                               state.ctx.LogD(
-                                       "sp-work",
-                                       SdsAdd(sds, SDS{"size": strconv.Itoa(len(payload))}),
-                                       "queuing new info",
-                               )
-                               state.payloads <- payload
+       if state.xxOnly == "" || state.xxOnly == TTx {
+               go func() {
+                       for range time.Tick(time.Second) {
+                               for _, payload := range state.ctx.infosOur(
+                                       state.Node.Id,
+                                       state.nice,
+                                       &state.infosOurSeen,
+                               ) {
+                                       state.ctx.LogD(
+                                               "sp-work",
+                                               SdsAdd(sds, SDS{"size": strconv.Itoa(len(payload))}),
+                                               "queuing new info",
+                                       )
+                                       state.payloads <- payload
+                               }
                        }
-               }
-       }()
+               }()
+       }
 
        state.wg.Add(1)
        go func() {
@@ -737,7 +739,7 @@ func (state *SPState) ProcessSP(payload []byte) ([][]byte, error) {
                                continue
                        }
                        state.ctx.LogD("sp-process", sdsp, "received")
-                       if state.xxOnly != nil && *state.xxOnly == TTx {
+                       if state.xxOnly == TTx {
                                continue
                        }
                        state.Lock()
index 4ae9711f8d7d6f42fbefb50b1363ef3001ccaef6..2fb4cbb034b47b1c549f92bfda036e6433182a8c 100644 (file)
@@ -36,7 +36,6 @@ import (
        "github.com/davecgh/go-xdr/xdr2"
        "github.com/dustin/go-humanize"
        "golang.org/x/crypto/blake2b"
-       "golang.org/x/sys/unix"
 )
 
 func newNotification(fromTo *FromToYAML, subject string) io.Reader {
@@ -48,40 +47,7 @@ func newNotification(fromTo *FromToYAML, subject string) io.Reader {
        ))
 }
 
-func (ctx *Ctx) LockDir(nodeId *NodeId, xx TRxTx) (*os.File, error) {
-       ctx.ensureRxDir(nodeId)
-       lockPath := filepath.Join(ctx.Spool, nodeId.String(), string(xx)) + ".lock"
-       dirLock, err := os.OpenFile(
-               lockPath,
-               os.O_CREATE|os.O_WRONLY,
-               os.FileMode(0600),
-       )
-       if err != nil {
-               ctx.LogE("lockdir", SDS{"path": lockPath, "err": err}, "")
-               return nil, err
-       }
-       err = unix.Flock(int(dirLock.Fd()), unix.LOCK_EX|unix.LOCK_NB)
-       if err != nil {
-               ctx.LogE("lockdir", SDS{"path": lockPath, "err": err}, "")
-               dirLock.Close()
-               return nil, err
-       }
-       return dirLock, nil
-}
-
-func (ctx *Ctx) UnlockDir(fd *os.File) {
-       if fd != nil {
-               unix.Flock(int(fd.Fd()), unix.LOCK_UN)
-               fd.Close()
-       }
-}
-
 func (ctx *Ctx) Toss(nodeId *NodeId, nice uint8, dryRun bool) bool {
-       dirLock, err := ctx.LockDir(nodeId, TRx)
-       if err != nil {
-               return false
-       }
-       defer ctx.UnlockDir(dirLock)
        isBad := false
        for job := range ctx.Jobs(nodeId, TRx) {
                pktName := filepath.Base(job.Fd.Name())
index 98b5b1e7e80eb60271c8dc4eba6521ec2c3e811e..0b25a408a50076fbbcae6b7ac0ea5fbb0b085e79 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 98b5b1e7e80eb60271c8dc4eba6521ec2c3e811e
+Subproject commit 0b25a408a50076fbbcae6b7ac0ea5fbb0b085e79