From: Sergey Matveev Date: Sun, 11 Jun 2017 08:47:03 +0000 (+0300) Subject: Fix invalid -rx/-tx arguments processing X-Git-Tag: 0.9^2~3 X-Git-Url: http://www.git.cypherpunks.ru/?p=nncp.git;a=commitdiff_plain;h=b4c6e5230f3bec679ceb9ca4207da08f7e9c53aa Fix invalid -rx/-tx arguments processing --- diff --git a/VERSION b/VERSION index aec258d..b63ba69 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8 +0.9 diff --git a/doc/news.ru.texi b/doc/news.ru.texi index cae730d..668c4fe 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -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 diff --git a/doc/news.texi b/doc/news.texi index 0358a6c..3d55767 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -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 diff --git a/ports/nncp/Makefile b/ports/nncp/Makefile index e4086f7..00e5818 100644 --- a/ports/nncp/Makefile +++ b/ports/nncp/Makefile @@ -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/ diff --git a/src/cypherpunks.ru/nncp/call.go b/src/cypherpunks.ru/nncp/call.go index 5b8e058..496720a 100644 --- a/src/cypherpunks.ru/nncp/call.go +++ b/src/cypherpunks.ru/nncp/call.go @@ -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") diff --git a/src/cypherpunks.ru/nncp/cfg.go b/src/cypherpunks.ru/nncp/cfg.go index 3400ed8..3a642f6 100644 --- a/src/cypherpunks.ru/nncp/cfg.go +++ b/src/cypherpunks.ru/nncp/cfg.go @@ -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, diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go index 9694639..42f761f 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-call/main.go @@ -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) } } diff --git a/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go b/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go index b3678cd..e6ec2d3 100644 --- a/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go +++ b/src/cypherpunks.ru/nncp/cmd/nncp-daemon/main.go @@ -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() diff --git a/src/cypherpunks.ru/nncp/node.go b/src/cypherpunks.ru/nncp/node.go index 22fa3fb..1ea4903 100644 --- a/src/cypherpunks.ru/nncp/node.go +++ b/src/cypherpunks.ru/nncp/node.go @@ -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 diff --git a/src/cypherpunks.ru/nncp/sp.go b/src/cypherpunks.ru/nncp/sp.go index 8b64be1..be84510 100644 --- a/src/cypherpunks.ru/nncp/sp.go +++ b/src/cypherpunks.ru/nncp/sp.go @@ -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()