X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcfg.go;h=615e382410a6f52bd067e40717356a3b9c6e0950;hb=1d2ce674b042d07fd9b37a46578c8b62bb0345b7;hp=deebd1981d8d5c3cb80417e5ab1ebcbf40d68032;hpb=0139e8deda4112d2c3dcd52e0ad72162e54caa03;p=nncp.git diff --git a/src/cfg.go b/src/cfg.go index deebd19..615e382 100644 --- a/src/cfg.go +++ b/src/cfg.go @@ -24,6 +24,7 @@ import ( "log" "os" "path" + "strconv" "github.com/gorhill/cronexpr" "github.com/hjson/hjson-go" @@ -45,17 +46,15 @@ var ( ) type NodeJSON struct { - Id string `json:"id"` - ExchPub string `json:"exchpub"` - SignPub string `json:"signpub"` - NoisePub *string `json:"noisepub,omitempty"` - Exec map[string][]string `json:"exec,omitempty"` - Incoming *string `json:"incoming,omitempty"` - Freq *string `json:"freq,omitempty"` - FreqChunked *uint64 `json:"freqchunked,omitempty"` - FreqMinSize *uint64 `json:"freqminsize,omitempty"` - Via []string `json:"via,omitempty"` - Calls []CallJSON `json:"calls,omitempty"` + Id string `json:"id"` + ExchPub string `json:"exchpub"` + SignPub string `json:"signpub"` + NoisePub *string `json:"noisepub,omitempty"` + Exec map[string][]string `json:"exec,omitempty"` + Incoming *string `json:"incoming,omitempty"` + Freq *NodeFreqJSON `json:"freq,omitempty"` + Via []string `json:"via,omitempty"` + Calls []CallJSON `json:"calls,omitempty"` Addrs map[string]string `json:"addrs,omitempty"` @@ -65,6 +64,13 @@ type NodeJSON struct { MaxOnlineTime *uint `json:"maxonlinetime,omitempty"` } +type NodeFreqJSON struct { + Path *string `json:"path,omitempty"` + Chunked *uint64 `json:"chunked,omitempty"` + MinSize *uint64 `json:"minsize,omitempty"` + MaxSize *uint64 `json:"maxsize,omitempty"` +} + type CallJSON struct { Cron string Nice *string `json:"nice,omitempty"` @@ -92,13 +98,18 @@ type FromToJSON struct { } type NotifyJSON struct { - File *FromToJSON `json:"file,omitempty"` - Freq *FromToJSON `json:"freq,omitempty"` + File *FromToJSON `json:"file,omitempty"` + Freq *FromToJSON `json:"freq,omitempty"` + Exec map[string]*FromToJSON `json:"exec,omitempty"` } type CfgJSON struct { - Spool string `json:"spool"` - Log string `json:"log"` + Spool string `json:"spool"` + Log string `json:"log"` + Umask string `json:"umask",omitempty` + + OmitPrgrs bool `json:"noprogress",omitempty` + Notify *NotifyJSON `json:"notify,omitempty"` Self *NodeOurJSON `json:"self"` @@ -147,24 +158,31 @@ func NewNode(name string, yml NodeJSON) (*Node, error) { incoming = &inc } - var freq *string + var freqPath *string + freqChunked := int64(MaxFileSize) + var freqMinSize int64 + freqMaxSize := int64(MaxFileSize) if yml.Freq != nil { - fr := path.Clean(*yml.Freq) - if !path.IsAbs(fr) { - return nil, errors.New("Freq path must be absolute") + f := yml.Freq + if f.Path != nil { + fPath := path.Clean(*f.Path) + if !path.IsAbs(fPath) { + return nil, errors.New("freq.path path must be absolute") + } + freqPath = &fPath } - freq = &fr - } - var freqChunked int64 - if yml.FreqChunked != nil { - if *yml.FreqChunked == 0 { - return nil, errors.New("freqchunked value must be greater than zero") + if f.Chunked != nil { + if *f.Chunked == 0 { + return nil, errors.New("freq.chunked value must be greater than zero") + } + freqChunked = int64(*f.Chunked) * 1024 + } + if f.MinSize != nil { + freqMinSize = int64(*f.MinSize) * 1024 + } + if f.MaxSize != nil { + freqMaxSize = int64(*f.MaxSize) * 1024 } - freqChunked = int64(*yml.FreqChunked) * 1024 - } - var freqMinSize int64 - if yml.FreqMinSize != nil { - freqMinSize = int64(*yml.FreqMinSize) * 1024 } defRxRate := 0 @@ -265,9 +283,10 @@ func NewNode(name string, yml NodeJSON) (*Node, error) { SignPub: ed25519.PublicKey(signPub), Exec: yml.Exec, Incoming: incoming, - Freq: freq, + FreqPath: freqPath, FreqChunked: freqChunked, FreqMinSize: freqMinSize, + FreqMaxSize: freqMaxSize, Calls: calls, Addrs: yml.Addrs, RxRate: defRxRate, @@ -397,12 +416,27 @@ func CfgParse(data []byte) (*Ctx, error) { if !path.IsAbs(logPath) { return nil, errors.New("Log path must be absolute") } + var umaskForce *int + if cfgJSON.Umask != "" { + r, err := strconv.ParseUint(cfgJSON.Umask, 8, 16) + if err != nil { + return nil, err + } + rInt := int(r) + umaskForce = &rInt + } + showPrgrs := true + if cfgJSON.OmitPrgrs { + showPrgrs = false + } ctx := Ctx{ - Spool: spoolPath, - LogPath: logPath, - Self: self, - Neigh: make(map[NodeId]*Node, len(cfgJSON.Neigh)), - Alias: make(map[string]*NodeId), + Spool: spoolPath, + LogPath: logPath, + UmaskForce: umaskForce, + ShowPrgrs: showPrgrs, + Self: self, + Neigh: make(map[NodeId]*Node, len(cfgJSON.Neigh)), + Alias: make(map[string]*NodeId), } if cfgJSON.Notify != nil { if cfgJSON.Notify.File != nil { @@ -411,6 +445,9 @@ func CfgParse(data []byte) (*Ctx, error) { if cfgJSON.Notify.Freq != nil { ctx.NotifyFreq = cfgJSON.Notify.Freq } + if cfgJSON.Notify.Exec != nil { + ctx.NotifyExec = cfgJSON.Notify.Exec + } } vias := make(map[NodeId][]string) for name, neighJSON := range cfgJSON.Neigh {