X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcfg.go;h=8a7cb34ddc2099fea8f92b35333bad5d8a762f2d;hb=2e22bda93fdf8f2f84e4d19b3f1d46318b497139;hp=55c9dd0a2479cbe93ae98d97edb2aeb846098ff7;hpb=54b0f8a0e20847d666dd445bd92c282fd9ab5dec;p=nncp.git diff --git a/src/cfg.go b/src/cfg.go index 55c9dd0..8a7cb34 100644 --- a/src/cfg.go +++ b/src/cfg.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2021 Sergey Matveev +Copyright (C) 2016-2023 Sergey Matveev 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 @@ -38,6 +38,7 @@ const ( CfgPathEnv = "NNCPCFG" CfgSpoolEnv = "NNCPSPOOL" CfgLogEnv = "NNCPLOG" + CfgNoSync = "NNCPNOSYNC" ) var ( @@ -55,6 +56,7 @@ type NodeJSON struct { Incoming *string `json:"incoming,omitempty"` Exec map[string][]string `json:"exec,omitempty"` Freq *NodeFreqJSON `json:"freq,omitempty"` + ACK *NodeACKJSON `json:"ack,omitempty"` Via []string `json:"via,omitempty"` Calls []CallJSON `json:"calls,omitempty"` @@ -73,6 +75,11 @@ type NodeFreqJSON struct { MaxSize *uint64 `json:"maxsize,omitempty"` } +type NodeACKJSON struct { + MinSize *uint64 `json:"minsize,omitempty"` + Nice *string `json:"nice,omitempty"` +} + type CallJSON struct { Cron string `json:"cron"` Nice *string `json:"nice,omitempty"` @@ -93,6 +100,8 @@ type CallJSON struct { AutoTossNoExec bool `json:"autotoss-noexec,omitempty"` AutoTossNoTrns bool `json:"autotoss-notrns,omitempty"` AutoTossNoArea bool `json:"autotoss-noarea,omitempty"` + AutoTossNoACK bool `json:"autotoss-noack,omitempty"` + AutoTossGenACK bool `json:"autotoss-gen-ack,omitempty"` } type NodeOurJSON struct { @@ -146,6 +155,8 @@ type CfgJSON struct { Neigh map[string]NodeJSON `json:"neigh"` Areas map[string]AreaJSON `json:"areas,omitempty"` + + YggdrasilAliases map[string]string `json:"yggdrasil-aliases,omitempty"` } func NewNode(name string, cfg NodeJSON) (*Node, error) { @@ -191,7 +202,7 @@ func NewNode(name string, cfg NodeJSON) (*Node, error) { } var freqPath *string - freqChunked := int64(MaxFileSize) + var freqChunked int64 var freqMinSize int64 freqMaxSize := int64(MaxFileSize) if cfg.Freq != nil { @@ -217,6 +228,20 @@ func NewNode(name string, cfg NodeJSON) (*Node, error) { } } + ackNice := uint8(255) + var ackMinSize int64 + if cfg.ACK != nil { + if cfg.ACK.Nice != nil { + ackNice, err = NicenessParse(*cfg.ACK.Nice) + if err != nil { + return nil, err + } + } + if cfg.ACK.MinSize != nil { + ackMinSize = int64(*cfg.ACK.MinSize) * 1024 + } + } + defRxRate := 0 if cfg.RxRate != nil && *cfg.RxRate > 0 { defRxRate = *cfg.RxRate @@ -314,6 +339,8 @@ func NewNode(name string, cfg NodeJSON) (*Node, error) { call.AutoTossNoExec = callCfg.AutoTossNoExec call.AutoTossNoTrns = callCfg.AutoTossNoTrns call.AutoTossNoArea = callCfg.AutoTossNoArea + call.AutoTossNoACK = callCfg.AutoTossNoACK + call.AutoTossGenACK = callCfg.AutoTossGenACK calls = append(calls, &call) } @@ -329,6 +356,8 @@ func NewNode(name string, cfg NodeJSON) (*Node, error) { FreqChunked: freqChunked, FreqMinSize: freqMinSize, FreqMaxSize: freqMaxSize, + ACKNice: ackNice, + ACKMinSize: ackMinSize, Calls: calls, Addrs: cfg.Addrs, RxRate: defRxRate, @@ -465,7 +494,7 @@ func NewArea(ctx *Ctx, name string, cfg *AreaJSON) (*Area, error) { func CfgParse(data []byte) (*CfgJSON, error) { var err error - if bytes.Compare(data[:8], MagicNNCPBv3.B[:]) == 0 { + if bytes.Equal(data[:8], MagicNNCPBv3.B[:]) { os.Stderr.WriteString("Passphrase:") password, err := term.ReadPassword(0) if err != nil { @@ -476,9 +505,9 @@ func CfgParse(data []byte) (*CfgJSON, error) { if err != nil { return nil, err } - } else if bytes.Compare(data[:8], MagicNNCPBv2.B[:]) == 0 { + } else if bytes.Equal(data[:8], MagicNNCPBv2.B[:]) { log.Fatalln(MagicNNCPBv2.TooOld()) - } else if bytes.Compare(data[:8], MagicNNCPBv1.B[:]) == 0 { + } else if bytes.Equal(data[:8], MagicNNCPBv1.B[:]) { log.Fatalln(MagicNNCPBv1.TooOld()) } var cfgGeneral map[string]interface{} @@ -542,6 +571,8 @@ func Cfg2Ctx(cfgJSON *CfgJSON) (*Ctx, error) { Alias: make(map[string]*NodeId), MCDRxIfis: cfgJSON.MCDRxIfis, MCDTxIfis: cfgJSON.MCDTxIfis, + + YggdrasilAliases: cfgJSON.YggdrasilAliases, } if cfgJSON.Notify != nil { if cfgJSON.Notify.File != nil {