|
| 1 | +// // Copyright 2018 The crowdcompute:crowdengine Authors |
| 2 | +// // This file is part of the crowdcompute:crowdengine library. |
| 3 | +// // |
| 4 | +// // The crowdcompute:crowdengine library is free software: you can redistribute it and/or modify |
| 5 | +// // it under the terms of the GNU Lesser General Public License as published by |
| 6 | +// // the Free Software Foundation, either version 3 of the License, or |
| 7 | +// // (at your option) any later version. |
| 8 | +// // |
| 9 | +// // The crowdcompute:crowdengine library is distributed in the hope that it will be useful, |
| 10 | +// // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// // GNU Lesser General Public License for more details. |
| 13 | +// // |
| 14 | +// // You should have received a copy of the GNU Lesser General Public License |
| 15 | +// // along with the crowdcompute:crowdengine library. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package commands |
| 18 | + |
| 19 | +// import ( |
| 20 | +// "bufio" |
| 21 | +// "fmt" |
| 22 | +// "os" |
| 23 | + |
| 24 | +// "github.com/crowdcompute/crowdengine/common" |
| 25 | +// "github.com/urfave/cli" |
| 26 | +// ) |
| 27 | + |
| 28 | +// var ( |
| 29 | +// // P2pPortFlag p2p port |
| 30 | +// P2pPortFlag = cli.IntFlag{ |
| 31 | +// Name: "port, p", |
| 32 | +// Usage: "The p2p port the node will listen to.", |
| 33 | +// Value: 12000, |
| 34 | +// } |
| 35 | + |
| 36 | +// // IPFlag listen |
| 37 | +// IPFlag = cli.StringFlag{ |
| 38 | +// Name: "ip", |
| 39 | +// Usage: "Setting the IP address", |
| 40 | +// Value: "127.0.0.0", |
| 41 | +// } |
| 42 | +// // RPCFlag settings |
| 43 | +// RPCFlag = cli.BoolFlag{ |
| 44 | +// Name: "rpc", |
| 45 | +// Usage: "Setting this flag will make this node listet to JSON-RPC calls", |
| 46 | +// } |
| 47 | +// ) |
| 48 | + |
| 49 | +// var ( |
| 50 | +// // RunCommand runs a node |
| 51 | +// RunCommand = cli.Command{ |
| 52 | +// Action: runNode, |
| 53 | +// Name: "run", |
| 54 | +// Usage: "Run a Crowd Compute node", |
| 55 | +// ArgsUsage: "<bootnodes>", |
| 56 | +// Flags: []cli.Flag{ |
| 57 | +// P2pPortFlag, |
| 58 | +// IPFlag, |
| 59 | +// RPCFlag, |
| 60 | +// }, |
| 61 | +// Category: "CC CLI", |
| 62 | +// Description: ` |
| 63 | +// The command runs a new node. |
| 64 | +// It expects the <bootnodes> file as an argument.`, |
| 65 | +// } |
| 66 | +// ) |
| 67 | + |
| 68 | +// // It creates a default node based on the command line arguments and runs it in |
| 69 | +// // blocking mode, waiting for it to be shut down. |
| 70 | +// // func runNode(ctx *cli.Context) error { |
| 71 | +// // bootnodesFile := ctx.Args().First() |
| 72 | +// // port := ctx.Int("port") |
| 73 | +// // ip := ctx.String("ip") |
| 74 | +// // rpcFlag := ctx.Bool("rpc") // BoolTFlag returns false if no flag was set |
| 75 | + |
| 76 | +// // bootnodes := getBootnodesFromFile(bootnodesFile) |
| 77 | + |
| 78 | +// // // Creating a new Node. |
| 79 | +// // // Takes port and ip command line arguments as parameters |
| 80 | +// // n, err := node.NewNode(port, ip, bootnodes) |
| 81 | +// // common.CheckErr(err, "[initNode] Failed to create node.") |
| 82 | + |
| 83 | +// // // Create a cancellable context for our GRPC call |
| 84 | +// // ctxt, cancel := context.WithCancel(context.Background()) |
| 85 | +// // defer cancel() |
| 86 | +// // n.Start(ctxt, rpcFlag) |
| 87 | + |
| 88 | +// // return nil |
| 89 | +// // } |
| 90 | + |
| 91 | +// // getBootnodesFromFile returns a slice of bootnodes given the file bootnodesFile |
| 92 | +// func getBootnodesFromFile(bootnodesFile string) []string { |
| 93 | +// bootnodes := make([]string, 0) |
| 94 | +// if bootnodesFile != "" { |
| 95 | +// file, err := os.Open(bootnodesFile) |
| 96 | +// common.CheckErr(err, "[getBootnodes] Failed to open the bootnodes file.") |
| 97 | + |
| 98 | +// defer file.Close() |
| 99 | +// scanner := bufio.NewScanner(file) |
| 100 | +// for scanner.Scan() { |
| 101 | +// bootnodes = append(bootnodes, scanner.Text()) |
| 102 | +// fmt.Println(scanner.Text()) |
| 103 | +// } |
| 104 | +// } |
| 105 | +// return bootnodes |
| 106 | +// } |
0 commit comments