// parseNodes parses a list of discovery node URLs loaded from a .json file. func (cfg *Config) parseNodes(file string) []*discover.Node { // Short circuit if no node config is present path := filepath.Join(cfg.DataDir, file) if _, err := os.Stat(path); err != nil { return nil } // Load the nodes from the config file blob, err := ioutil.ReadFile(path) if err != nil { glog.V(logger.Error).Infof("Failed to access nodes: %v", err) return nil } nodelist := []string{} if err := json.Unmarshal(blob, &nodelist); err != nil { glog.V(logger.Error).Infof("Failed to load nodes: %v", err) return nil } // Interpret the list as a discovery node array var nodes []*discover.Node for _, url := range nodelist { if url == "" { continue } node, err := discover.ParseNode(url) if err != nil { glog.V(logger.Error).Infof("Node URL %s: %v\n", url, err) continue } nodes = append(nodes, node) } return nodes }
// AddPeer connects to the given node and maintains the connection until the // server is shut down. If the connection fails for any reason, the server will // attempt to reconnect the peer. func (self *Ethereum) AddPeer(nodeURL string) error { n, err := discover.ParseNode(nodeURL) if err != nil { return fmt.Errorf("invalid node URL: %v", err) } self.net.AddPeer(n) return nil }
func (cfg *Config) parseBootNodes() []*discover.Node { if cfg.BootNodes == "" { return defaultBootNodes } var ns []*discover.Node for _, url := range strings.Split(cfg.BootNodes, " ") { if url == "" { continue } n, err := discover.ParseNode(url) if err != nil { glog.V(logger.Error).Infof("Bootstrap URL %s: %v\n", url, err) continue } ns = append(ns, n) } return ns }