// Init API node for connection to targets func API_INIT(targets ...string) bool { var err tree_lib.TreeError err.From = tree_lib.FROM_API_INIT if len(targets) == 0 { tree_log.Error(err.From, "For running API client you need to specify target node(s) to connect") return false } for _, n := range targets { node_info.ChildsNodeInfo[n], err = tree_db.GetNodeInfo(n) if !err.IsNull() { tree_log.Error(err.From, fmt.Sprintf("Unable Getting target (%s) node info from Node database, ", n), err.Error()) return false } } rand.Seed(time.Now().UnixNano()) node_info.CurrentNodeInfo = node_info.NodeInfo{ Name: fmt.Sprintf("%s|%s", API_NAME_PREFIX, tree_lib.RandomString(10)), Childs: targets, // Getting next prime number based on Unix Timestamp nanoseconds and // TODO: Think about making this in a different way Value: tree_lib.NextPrimeNumber((1 * rand.Int63n(100)) + int64(100)), } node_info.CurrentNodeValue = big.NewInt(node_info.CurrentNodeInfo.Value) // Setting node values based on child list node_info.CalculateChildParentNodeValues() // After we have child information lets connect to them node_info.ChildsConnectionUpdate() return true }
func init() { tree_event.ON(tree_event.ON_RESTART_NODE, func(ev *tree_event.Event) { Restart() }) go func() { for { // After we have child information lets connect to them node_info.ChildsConnectionUpdate() time.Sleep(time.Millisecond * 500) } }() }