]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/cfg.go
Replace Twofish/HKDF with ChaCha20/BLAKE2X for speed and simplicity
[nncp.git] / src / cypherpunks.ru / nncp / cfg.go
index 3400ed83a93e7d850f85da7b47653497592e14a9..d948a274086438719aa6e09ae36c08f27405c93a 100644 (file)
@@ -32,7 +32,9 @@ import (
 )
 
 const (
-       CfgPathEnv = "NNCPCFG"
+       CfgPathEnv  = "NNCPCFG"
+       CfgSpoolEnv = "NNCPSPOOL"
+       CfgLogEnv   = "NNCPLOG"
 )
 
 var (
@@ -64,7 +66,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 +189,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 +220,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,
@@ -338,7 +339,7 @@ func (nodeOur *NodeOur) ToYAML() string {
 
 func CfgParse(data []byte) (*Ctx, error) {
        var err error
-       if bytes.Compare(data[:8], MagicNNCPBv1[:]) == 0 {
+       if bytes.Compare(data[:8], MagicNNCPBv2[:]) == 0 {
                os.Stderr.WriteString("Passphrase:")
                password, err := terminal.ReadPassword(0)
                if err != nil {
@@ -415,11 +416,3 @@ func CfgParse(data []byte) (*Ctx, error) {
        }
        return &ctx, nil
 }
-
-func CfgPathFromEnv(cmdlineFlag *string) (p string) {
-       p = os.Getenv(CfgPathEnv)
-       if p == "" {
-               p = *cmdlineFlag
-       }
-       return
-}