// Load node config func LoadNodeConfig() (err error) { // parse ini file confPath := path.Join(NODE_BASE_PATH, CONF_DIR, NODE_CONF_FILE) c, err := conf.ReadConfigFile(confPath) if err != nil { return } // set global var NODE_ADDRESS, err = c.GetString("default", "NODE_ADDRESS") if err != nil { return } OSS_ADDRESS, err = c.GetString("default", "OSS_ADDRESS") if err != nil { return } LOG_FILE, err = c.GetString("default", "LOG_FILE") if err != nil { return } if LOG_FILE[0:1] != "/" { // convert to abs path LOG_FILE = path.Join(NODE_BASE_PATH, LOG_FILE) } level, err := c.GetString("default", "LOG_LEVEL") if err != nil { return } switch level { case "FATAL": LOG_LEVEL = FATAL case "CRITICAL": LOG_LEVEL = CRITICAL case "ERROR": LOG_LEVEL = ERROR case "WARN": LOG_LEVEL = WARN case "INFO": LOG_LEVEL = INFO case "DEBUG": LOG_LEVEL = DEBUG default: err = fmt.Errorf("Invalid log level %s", level) return } // cert DOMAIN_ID, err = c.GetString("default", "DOMAIN_ID") if err != nil { return } encoded, err := c.GetString("default", "DOMAIN_PUB_KEY") if err != nil { return } DOMAIN_PUB_KEY, err = loadDomainPubKey([]byte(encoded)) if err != nil { return } encoded, err = c.GetString("default", "NODE_SIG") if err != nil { return } NODE_SIG, err = loadNodeSig(encoded) if err != nil { return } NODE_CERT = &NodeCert{ DomainId: DOMAIN_ID, NodeId: NODE_ADDRESS, } // verify NODE_SIG s, err := json.Marshal(NODE_CERT) if err != nil { return } if err = rsa.VerifyPKCS1v15(DOMAIN_PUB_KEY, crypto.SHA1, Sha1Bytes(s), NODE_SIG); err != nil { return } return nil }
// Load domain config func LoadDomainConfig() (err error) { // calc default sig DOMAIN_CONFIG_SIG = getDomainConfigSig() // parse ini file confPath := path.Join(NODE_BASE_PATH, CONF_DIR, DOMAIN_CONF_FILE) c, err := conf.ReadConfigFile(confPath) if err != nil { // file not exist, use default values return nil } // set global var if v, err := c.GetString("default", "MULTICAST_ADDR"); err == nil { MULTICAST_ADDR = v } if v, err := c.GetInt("default", "BLOCK_SIZE"); err == nil { BLOCK_SIZE = v } if v, err := c.GetInt("default", "DOMAIN_RING_SPOTS"); err == nil { DOMAIN_RING_SPOTS = v } if v, err := c.GetFloat64("default", "DEVICE_WEIGHT_UNIT"); err == nil { DEVICE_WEIGHT_UNIT = v } if v, err := c.GetInt("default", "REPLICA"); err == nil { REPLICA = v } if v, err := c.GetInt("default", "MIN_REPLICA"); err == nil { MIN_REPLICA = v } if v, err := c.GetSecond("default", "WRITE_BLOCK_TIMEOUT"); err == nil { WRITE_BLOCK_TIMEOUT = v } if v, err := c.GetSecond("default", "REPLICA_BLOCK_TIMEOUT"); err == nil { REPLICA_BLOCK_TIMEOUT = v } if v, err := c.GetSecond("default", "GATHER_BLOCK_TIMEOUT"); err == nil { GATHER_BLOCK_TIMEOUT = v } if v, err := c.GetSecond("default", "READ_BLOCK_TIMEOUT"); err == nil { READ_BLOCK_TIMEOUT = v } if v, err := c.GetSecond("default", "DEL_BLOCK_TIMEOUT"); err == nil { DEL_BLOCK_TIMEOUT = v } if v, err := c.GetSecond("default", "DETECT_BLOCK_TIMEOUT"); err == nil { DETECT_BLOCK_TIMEOUT = v } if v, err := c.GetSecond("default", "QUERY_BLOCK_TIMEOUT"); err == nil { QUERY_BLOCK_TIMEOUT = v } if v, err := c.GetSecond("default", "GOSSIP_TIMEOUT"); err == nil { GOSSIP_TIMEOUT = v } if v, err := c.GetSecond("default", "BLOCK_META_SYNC_INTERVAL"); err == nil { BLOCK_META_SYNC_INTERVAL = v } if v, err := c.GetSecond("default", "SWEEP_INTERVAL"); err == nil { SWEEP_INTERVAL = v } if v, err := c.GetSecond("default", "REBALANCE_INTERVAL"); err == nil { REBALANCE_INTERVAL = v } if v, err := c.GetSecond("default", "GC_INTERVAL"); err == nil { GC_INTERVAL = v } if v, err := c.GetInt("default", "MAX_CONCURRENT_REPAIR"); err == nil { MAX_CONCURRENT_REPAIR = v } if v, err := c.GetSecond("default", "MAX_REBALANCE_IDLE"); err == nil { MAX_REBALANCE_IDLE = v } if v, err := c.GetInt("default", "MAX_CONCURRENT_REBALANCE"); err == nil { MAX_CONCURRENT_REBALANCE = v } if v, err := c.GetInt("default", "MAX_CONCURRENT_GC"); err == nil { MAX_CONCURRENT_GC = v } if v, err := c.GetSecond("default", "QUERY_REBALANCE_CACHE_TIMEOUT"); err == nil { QUERY_REBALANCE_CACHE_TIMEOUT = v } if v, err := c.GetSecond("default", "REBALANCE_OUT_TIME"); err == nil { REBALANCE_OUT_TIME = v } if v, err := c.GetSecond("default", "ACCESS_INTERMITTENT"); err == nil { ACCESS_INTERMITTENT = v } if v, err := c.GetSecond("default", "MAX_NODE_TIME_DIFF"); err == nil { MAX_NODE_TIME_DIFF = v } if v, err := c.GetSecond("default", "POLL_NEIGHBOR_INTERVAL"); err == nil { POLL_NEIGHBOR_INTERVAL = v } if v, err := c.GetSecond("default", "NODE_CLEANUP_TIME"); err == nil { NODE_CLEANUP_TIME = v } if v, err := c.GetSecond("default", "NODE_OUT_TIME"); err == nil { NODE_OUT_TIME = v } if v, err := c.GetInt("default", "GOSSIP_NOTIFY_QUEUE_LENGTH"); err == nil { GOSSIP_NOTIFY_QUEUE_LENGTH = v } if v, err := c.GetUint64("default", "CPU_BUSY_THROTLLE"); err == nil { CPU_BUSY_THROTLLE = v } if v, err := c.GetUint64("default", "DISK_BUSY_THROTLLE"); err == nil { DISK_BUSY_THROTLLE = v } if v, err := c.GetInt("default", "READ_QUEUE_LENGTH"); err == nil { READ_QUEUE_LENGTH = v } if v, err := c.GetInt("default", "WRITE_QUEUE_LENGTH"); err == nil { WRITE_QUEUE_LENGTH = v } // update DOMAIN_CONFIG_SIG DOMAIN_CONFIG_SIG = getDomainConfigSig() return }