1-255 values are allowed.
@item -node
Process only single specified node.
+@item -spool
+ Override path to spool directory. May be specified by
+ @env{NNCPSPOOL} environment variable.
+@item -log
+ Override path to logfile. May be specified by @env{NNCPLOG}
+ environment variable.
@item -quiet
Print only errors, omit simple informational messages. In any case
those messages are logged, so you can reread them using
В команде @command{nncp-call} разрешается иметь только одного
обработчика контрольной суммы в фоне. Это полезно когда тысячи маленьких
входящих пакетов могут создать много горутин.
+@item
+Возможность переопределить путь до spool директории и файла журнала
+через аргумент командной строки или переменную окружения.
@end itemize
@node Релиз 0.12
Single background checksum verifier worker is allowed in
@command{nncp-call}. This is helpful when thousands of small inbound
packets could create many goroutines.
+@item
+Ability to override path to spool directory and logfile through either
+command line argument, or environment variable.
@end itemize
@node Release 0.12
)
const (
- CfgPathEnv = "NNCPCFG"
+ CfgPathEnv = "NNCPCFG"
+ CfgSpoolEnv = "NNCPSPOOL"
+ CfgLogEnv = "NNCPLOG"
)
var (
}
return &ctx, nil
}
-
-func CfgPathFromEnv(cmdlineFlag *string) (p string) {
- p = os.Getenv(CfgPathEnv)
- if p == "" {
- p = *cmdlineFlag
- }
- return
-}
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- niceRaw = flag.Int("nice", 255, "Minimal required niceness")
- doRx = flag.Bool("rx", false, "Receive packets")
- doTx = flag.Bool("tx", false, "Transfer packets")
- doDelete = flag.Bool("delete", false, "Delete transferred packets")
- doCheck = flag.Bool("check", false, "Check integrity while receiving")
- dryRun = flag.Bool("dryrun", false, "Do not writings")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ niceRaw = flag.Int("nice", 255, "Minimal required niceness")
+ doRx = flag.Bool("rx", false, "Receive packets")
+ doTx = flag.Bool("tx", false, "Transfer packets")
+ doDelete = flag.Bool("delete", false, "Delete transferred packets")
+ doCheck = flag.Bool("check", false, "Check integrity while receiving")
+ dryRun = flag.Bool("dryrun", false, "Do not writings")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
log.Fatalln("At least one of -rx and -tx must be specified")
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
+ log.Fatalln("Error during initialization:", err)
}
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
- }
- ctx.Quiet = *quiet
- ctx.Debug = *debug
nodeIds := make(map[nncp.NodeId]struct{}, flag.NArg())
for i := 0; i < flag.NArg(); i++ {
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
"strings"
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- niceRaw = flag.Int("nice", 255, "Minimal required niceness")
- rxOnly = flag.Bool("rx", false, "Only receive packets")
- txOnly = flag.Bool("tx", false, "Only transfer packets")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ niceRaw = flag.Int("nice", 255, "Minimal required niceness")
+ rxOnly = flag.Bool("rx", false, "Only receive packets")
+ txOnly = flag.Bool("tx", false, "Only transfer packets")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
onlineDeadline = flag.Uint("onlinedeadline", 0, "Override onlinedeadline option")
maxOnlineTime = flag.Uint("maxonlinetime", 0, "Override maxonlinetime option")
log.Fatalln("-rx and -tx can not be set simultaneously")
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
if ctx.Self == nil {
log.Fatalln("Config lacks private keys")
}
- ctx.Quiet = *quiet
- ctx.Debug = *debug
splitted := strings.SplitN(flag.Arg(0), ":", 2)
node, err := ctx.FindNode(splitted[0])
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
"strconv"
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
return
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
if ctx.Self == nil {
log.Fatalln("Config lacks private keys")
}
- ctx.Quiet = *quiet
- ctx.Debug = *debug
var nodes []*nncp.Node
if flag.NArg() > 0 {
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
return
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, "", "", false, false)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
cfg := nncp.CfgYAML{
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- nodeRaw = flag.String("node", "", "Process only that node")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ nodeRaw = flag.String("node", "", "Process only that node")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
return
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
+ log.Fatalln("Error during initialization:", err)
}
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
- }
- ctx.Quiet = *quiet
- ctx.Debug = *debug
var nodeOnly *nncp.Node
if *nodeRaw != "" {
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"net"
"os"
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- niceRaw = flag.Int("nice", 255, "Minimal required niceness")
- bind = flag.String("bind", "[::]:5400", "Address to bind to")
- maxConn = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ niceRaw = flag.Int("nice", 255, "Minimal required niceness")
+ bind = flag.String("bind", "[::]:5400", "Address to bind to")
+ maxConn = flag.Int("maxconn", 128, "Maximal number of simultaneous connections")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
}
nice := uint8(*niceRaw)
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
if ctx.Self == nil {
log.Fatalln("Config lacks private keys")
}
- ctx.Quiet = *quiet
- ctx.Debug = *debug
ln, err := net.Listen("tcp", *bind)
if err != nil {
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
"strings"
niceRaw = flag.Int("nice", nncp.DefaultNiceFile, "Outbound packet niceness")
minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
chunkSize = flag.Uint64("chunked", 0, "Split file on specified size chunks, in KiB")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
quiet = flag.Bool("quiet", false, "Print only errors")
debug = flag.Bool("debug", false, "Print debug messages")
version = flag.Bool("version", false, "Print version information")
}
nice := uint8(*niceRaw)
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
if ctx.Self == nil {
log.Fatalln("Config lacks private keys")
}
- ctx.Quiet = *quiet
- ctx.Debug = *debug
splitted := strings.SplitN(flag.Arg(1), ":", 2)
if len(splitted) != 2 {
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
"path/filepath"
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- niceRaw = flag.Int("nice", nncp.DefaultNiceFreq, "Outbound packet niceness")
- minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ niceRaw = flag.Int("nice", nncp.DefaultNiceFreq, "Outbound packet niceness")
+ minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
}
nice := uint8(*niceRaw)
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
if ctx.Self == nil {
log.Fatalln("Config lacks private keys")
}
- ctx.Quiet = *quiet
- ctx.Debug = *debug
splitted := strings.SplitN(flag.Arg(0), ":", 2)
if len(splitted) != 2 {
"bufio"
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
func main() {
var (
cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ logPath = flag.String("log", "", "Override path to logfile")
debug = flag.Bool("debug", false, "Print debug messages")
version = flag.Bool("version", false, "Print version information")
warranty = flag.Bool("warranty", false, "Print warranty information")
return
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, "", *logPath, false, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
fd, err := os.Open(ctx.LogPath)
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- niceRaw = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness")
- minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ niceRaw = flag.Int("nice", nncp.DefaultNiceMail, "Outbound packet niceness")
+ minSize = flag.Uint64("minsize", 0, "Minimal required resulting packet size, in KiB")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
}
nice := uint8(*niceRaw)
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
if ctx.Self == nil {
log.Fatalln("Config lacks private keys")
}
- ctx.Quiet = *quiet
- ctx.Debug = *debug
node, err := ctx.FindNode(flag.Arg(0))
if err != nil {
"flag"
"fmt"
"io"
- "io/ioutil"
"log"
"os"
_, err = xdr.Unmarshal(bytes.NewReader(beginning), &pktEnc)
if err == nil && pktEnc.Magic == nncp.MagicNNCPEv2 {
if *dump {
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, "", "", false, false)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
if ctx.Self == nil {
log.Fatalln("Config lacks private keys")
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- allNodes = flag.Bool("all", false, "Process all found chunked files for all nodes")
- nodeRaw = flag.String("node", "", "Process all found chunked files for that node")
- keep = flag.Bool("keep", false, "Do not remove chunks while assembling")
- dryRun = flag.Bool("dryrun", false, "Do not assemble whole file")
- dumpMeta = flag.Bool("dump", false, "Print decoded human-readable FILE.nncp.meta")
- stdout = flag.Bool("stdout", false, "Output reassembled FILE to stdout")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ allNodes = flag.Bool("all", false, "Process all found chunked files for all nodes")
+ nodeRaw = flag.String("node", "", "Process all found chunked files for that node")
+ keep = flag.Bool("keep", false, "Do not remove chunks while assembling")
+ dryRun = flag.Bool("dryrun", false, "Do not assemble whole file")
+ dumpMeta = flag.Bool("dump", false, "Print decoded human-readable FILE.nncp.meta")
+ stdout = flag.Bool("stdout", false, "Output reassembled FILE to stdout")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
return
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
+ log.Fatalln("Error during initialization:", err)
}
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
- }
- ctx.Quiet = *quiet
- ctx.Debug = *debug
var nodeOnly *nncp.Node
if *nodeRaw != "" {
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
"path/filepath"
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
os.Exit(1)
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
+ log.Fatalln("Error during initialization:", err)
}
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
- }
- ctx.Quiet = *quiet
- ctx.Debug = *debug
node, err := ctx.FindNode(flag.Arg(0))
if err != nil {
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
"sort"
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- nodeRaw = flag.String("node", "", "Process only that node")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ nodeRaw = flag.String("node", "", "Process only that node")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
return
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, "", false, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
+ log.Fatalln("Error during initialization:", err)
}
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
- }
- ctx.Debug = *debug
var nodeOnly *nncp.Node
if *nodeRaw != "" {
import (
"flag"
"fmt"
- "io/ioutil"
"log"
"os"
"time"
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- nodeRaw = flag.String("node", "", "Process only that node")
- niceRaw = flag.Int("nice", 255, "Minimal required niceness")
- dryRun = flag.Bool("dryrun", false, "Do not actually write any tossed data")
- doSeen = flag.Bool("seen", false, "Create .seen files")
- cycle = flag.Uint("cycle", 0, "Repeat tossing after N seconds in infinite loop")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ nodeRaw = flag.String("node", "", "Process only that node")
+ niceRaw = flag.Int("nice", 255, "Minimal required niceness")
+ dryRun = flag.Bool("dryrun", false, "Do not actually write any tossed data")
+ doSeen = flag.Bool("seen", false, "Create .seen files")
+ cycle = flag.Uint("cycle", 0, "Repeat tossing after N seconds in infinite loop")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
}
nice := uint8(*niceRaw)
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
- }
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
+ log.Fatalln("Error during initialization:", err)
}
if ctx.Self == nil {
log.Fatalln("Config lacks private keys")
}
- ctx.Quiet = *quiet
- ctx.Debug = *debug
var nodeOnly *nncp.Node
if *nodeRaw != "" {
func main() {
var (
- cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
- nodeRaw = flag.String("node", "", "Process only that node")
- niceRaw = flag.Int("nice", 255, "Minimal required niceness")
- rxOnly = flag.Bool("rx", false, "Only receive packets")
- txOnly = flag.Bool("tx", false, "Only transfer packets")
- mkdir = flag.Bool("mkdir", false, "Create necessary outbound directories")
- keep = flag.Bool("keep", false, "Do not delete transferred packets")
- quiet = flag.Bool("quiet", false, "Print only errors")
- debug = flag.Bool("debug", false, "Print debug messages")
- version = flag.Bool("version", false, "Print version information")
- warranty = flag.Bool("warranty", false, "Print warranty information")
+ cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
+ nodeRaw = flag.String("node", "", "Process only that node")
+ niceRaw = flag.Int("nice", 255, "Minimal required niceness")
+ rxOnly = flag.Bool("rx", false, "Only receive packets")
+ txOnly = flag.Bool("tx", false, "Only transfer packets")
+ mkdir = flag.Bool("mkdir", false, "Create necessary outbound directories")
+ keep = flag.Bool("keep", false, "Do not delete transferred packets")
+ spoolPath = flag.String("spool", "", "Override path to spool")
+ logPath = flag.String("log", "", "Override path to logfile")
+ quiet = flag.Bool("quiet", false, "Print only errors")
+ debug = flag.Bool("debug", false, "Print debug messages")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
flag.Usage = usage
flag.Parse()
log.Fatalln("-rx and -tx can not be set simultaneously")
}
- cfgRaw, err := ioutil.ReadFile(nncp.CfgPathFromEnv(cfgPath))
+ ctx, err := nncp.CtxFromCmdline(*cfgPath, *spoolPath, *logPath, *quiet, *debug)
if err != nil {
- log.Fatalln("Can not read config:", err)
+ log.Fatalln("Error during initialization:", err)
}
- ctx, err := nncp.CfgParse(cfgRaw)
- if err != nil {
- log.Fatalln("Can not parse config:", err)
- }
- ctx.Quiet = *quiet
- ctx.Debug = *debug
var nodeOnly *nncp.Node
if *nodeRaw != "" {
import (
"errors"
+ "io/ioutil"
"os"
"path/filepath"
)
fd.Close()
return nil
}
+
+func CtxFromCmdline(cfgPath, spoolPath, logPath string, quiet, debug bool) (*Ctx, error) {
+ env := os.Getenv(CfgPathEnv)
+ if env != "" {
+ cfgPath = env
+ }
+ cfgRaw, err := ioutil.ReadFile(cfgPath)
+ if err != nil {
+ return nil, err
+ }
+ ctx, err := CfgParse(cfgRaw)
+ if err != nil {
+ return nil, err
+ }
+ if spoolPath == "" {
+ env = os.Getenv(CfgSpoolEnv)
+ if env != "" {
+ ctx.Spool = env
+ }
+ } else {
+ ctx.Spool = spoolPath
+ }
+ if logPath == "" {
+ env = os.Getenv(CfgLogEnv)
+ if env != "" {
+ ctx.LogPath = env
+ }
+ } else {
+ ctx.LogPath = logPath
+ }
+ ctx.Quiet = quiet
+ ctx.Debug = debug
+ return ctx, nil
+}