MaxOnlineTime *uint `json:"maxonlinetime,omitempty"`
WhenTxExists *bool `json:"when-tx-exists,omitempty"`
NoCK *bool `json:"nock"`
+ MCDIgnore *bool `json:"mcd-ignore"`
AutoToss *bool `json:"autotoss,omitempty"`
AutoTossDoSeen *bool `json:"autotoss-doseen,omitempty"`
AutoTossNoFreq *bool `json:"autotoss-nofreq,omitempty"`
AutoTossNoExec *bool `json:"autotoss-noexec,omitempty"`
AutoTossNoTrns *bool `json:"autotoss-notrns,omitempty"`
+ AutoTossNoArea *bool `json:"autotoss-noarea,omitempty"`
}
type NodeOurJSON struct {
Exec map[string]*FromToJSON `json:"exec,omitempty"`
}
+type AreaJSON struct {
+ Id string `json:"id"`
+ Pub string `json:"pub"`
+ Prv *string `json:"prv,omitempty"`
+
+ Subs []string `json:"subs"`
+
+ Exec map[string][]string `json:"exec,omitempty"`
+ Incoming *string `json:"incoming,omitempty"`
+
+ AllowUnknown *bool `json:"allow-unknown,omitempty"`
+}
+
type CfgJSON struct {
Spool string `json:"spool"`
Log string `json:"log"`
Self *NodeOurJSON `json:"self"`
Neigh map[string]NodeJSON `json:"neigh"`
+
+ MCDRxIfis []string `json:"mcd-listen"`
+ MCDTxIfis map[string]int `json:"mcd-send"`
+
+ Areas map[string]AreaJSON `json:"areas"`
}
func NewNode(name string, cfg NodeJSON) (*Node, error) {
if callCfg.NoCK != nil {
call.NoCK = *callCfg.NoCK
}
+ if callCfg.MCDIgnore != nil {
+ call.MCDIgnore = *callCfg.MCDIgnore
+ }
if callCfg.AutoToss != nil {
call.AutoToss = *callCfg.AutoToss
}
if callCfg.AutoTossNoTrns != nil {
call.AutoTossNoTrns = *callCfg.AutoTossNoTrns
}
+ if callCfg.AutoTossNoArea != nil {
+ call.AutoTossNoArea = *callCfg.AutoTossNoArea
+ }
calls = append(calls, &call)
}
return &node, nil
}
+func NewArea(ctx *Ctx, name string, cfg *AreaJSON) (*Area, error) {
+ areaId, err := AreaIdFromString(cfg.Id)
+ if err != nil {
+ return nil, err
+ }
+ subs := make([]*NodeId, 0, len(cfg.Subs))
+ for _, s := range cfg.Subs {
+ node, err := ctx.FindNode(s)
+ if err != nil {
+ return nil, err
+ }
+ subs = append(subs, node.Id)
+ }
+ area := Area{
+ Name: name,
+ Id: areaId,
+ Pub: new([32]byte),
+ Subs: subs,
+ Exec: cfg.Exec,
+ Incoming: cfg.Incoming,
+ }
+ pub, err := Base32Codec.DecodeString(cfg.Pub)
+ if err != nil {
+ return nil, err
+ }
+ if len(pub) != 32 {
+ return nil, errors.New("Invalid pub size")
+ }
+ copy(area.Pub[:], pub)
+ if cfg.Prv != nil {
+ prv, err := Base32Codec.DecodeString(*cfg.Prv)
+ if err != nil {
+ return nil, err
+ }
+ if len(prv) != 32 {
+ return nil, errors.New("Invalid prv size")
+ }
+ area.Prv = new([32]byte)
+ copy(area.Prv[:], prv)
+ }
+ if cfg.AllowUnknown != nil {
+ area.AllowUnknown = *cfg.AllowUnknown
+ }
+ return &area, nil
+}
+
func CfgParse(data []byte) (*Ctx, error) {
var err error
- if bytes.Compare(data[:8], MagicNNCPBv3[:]) == 0 {
+ if bytes.Compare(data[:8], MagicNNCPBv3.B[:]) == 0 {
os.Stderr.WriteString("Passphrase:") // #nosec G104
password, err := term.ReadPassword(0)
if err != nil {
if err != nil {
return nil, err
}
+ } else if bytes.Compare(data[:8], MagicNNCPBv2.B[:]) == 0 {
+ log.Fatalln(MagicNNCPBv2.TooOld())
+ } else if bytes.Compare(data[:8], MagicNNCPBv1.B[:]) == 0 {
+ log.Fatalln(MagicNNCPBv1.TooOld())
}
var cfgGeneral map[string]interface{}
if err = hjson.Unmarshal(data, &cfgGeneral); err != nil {
Self: self,
Neigh: make(map[NodeId]*Node, len(cfgJSON.Neigh)),
Alias: make(map[string]*NodeId),
+ MCDRxIfis: cfgJSON.MCDRxIfis,
+ MCDTxIfis: cfgJSON.MCDTxIfis,
}
if cfgJSON.Notify != nil {
if cfgJSON.Notify.File != nil {
)
}
}
+ ctx.AreaId2Area = make(map[AreaId]*Area, len(cfgJSON.Areas))
+ ctx.AreaName2Id = make(map[string]*AreaId, len(cfgJSON.Areas))
+ for name, areaJSON := range cfgJSON.Areas {
+ area, err := NewArea(&ctx, name, &areaJSON)
+ if err != nil {
+ return nil, err
+ }
+ ctx.AreaId2Area[*area.Id] = area
+ ctx.AreaName2Id[name] = area.Id
+ }
return &ctx, nil
}