github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/node/registration/p2p.go (about) 1 package registration 2 3 import ( 4 "io/ioutil" 5 "path/filepath" 6 7 "github.com/prysmaticlabs/prysm/shared/cmd" 8 "github.com/prysmaticlabs/prysm/shared/params" 9 "github.com/urfave/cli/v2" 10 "gopkg.in/yaml.v2" 11 ) 12 13 // P2PPreregistration prepares data for p2p.Service's registration. 14 func P2PPreregistration(cliCtx *cli.Context) (bootstrapNodeAddrs []string, dataDir string, err error) { 15 // Bootnode ENR may be a filepath to a YAML file 16 bootnodesTemp := params.BeaconNetworkConfig().BootstrapNodes // actual CLI values 17 bootstrapNodeAddrs = make([]string, 0) // dest of final list of nodes 18 for _, addr := range bootnodesTemp { 19 if filepath.Ext(addr) == ".yaml" { 20 fileNodes, err := readbootNodes(addr) 21 if err != nil { 22 return nil, "", err 23 } 24 bootstrapNodeAddrs = append(bootstrapNodeAddrs, fileNodes...) 25 } else { 26 bootstrapNodeAddrs = append(bootstrapNodeAddrs, addr) 27 } 28 } 29 30 dataDir = cliCtx.String(cmd.DataDirFlag.Name) 31 if dataDir == "" { 32 dataDir = cmd.DefaultDataDir() 33 if dataDir == "" { 34 log.Fatal( 35 "Could not determine your system's HOME path, please specify a --datadir you wish " + 36 "to use for your chain data", 37 ) 38 } 39 } 40 41 return 42 } 43 44 func readbootNodes(fileName string) ([]string, error) { 45 fileContent, err := ioutil.ReadFile(fileName) 46 if err != nil { 47 return nil, err 48 } 49 listNodes := make([]string, 0) 50 err = yaml.Unmarshal(fileContent, &listNodes) 51 if err != nil { 52 return nil, err 53 } 54 return listNodes, nil 55 }