github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/cmd/puppeth/wizard_network.go (about) 1 2 //此源码被清华学神尹成大魔王专业翻译分析并修改 3 //尹成QQ77025077 4 //尹成微信18510341407 5 //尹成所在QQ群721929980 6 //尹成邮箱 yinc13@mails.tsinghua.edu.cn 7 //尹成毕业于清华大学,微软区块链领域全球最有价值专家 8 //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620 9 //版权所有2017 Go Ethereum作者 10 //此文件是Go以太坊的一部分。 11 // 12 //Go以太坊是免费软件:您可以重新发布和/或修改它 13 //根据GNU通用公共许可证的条款 14 //自由软件基金会,或者许可证的第3版,或者 15 //(由您选择)任何更高版本。 16 // 17 //Go以太坊的分布希望它会有用, 18 //但没有任何保证;甚至没有 19 //适销性或特定用途的适用性。见 20 //GNU通用公共许可证了解更多详细信息。 21 // 22 //你应该已经收到一份GNU通用公共许可证的副本 23 //一起去以太坊吧。如果没有,请参见<http://www.gnu.org/licenses/>。 24 25 package main 26 27 import ( 28 "fmt" 29 "strings" 30 31 "github.com/ethereum/go-ethereum/log" 32 ) 33 34 // 35 //连接到新服务器的选项。 36 func (w *wizard) manageServers() { 37 // 38 fmt.Println() 39 40 servers := w.conf.servers() 41 for i, server := range servers { 42 fmt.Printf(" %d. Disconnect %s\n", i+1, server) 43 } 44 fmt.Printf(" %d. Connect another server\n", len(w.conf.Servers)+1) 45 46 choice := w.readInt() 47 if choice < 0 || choice > len(w.conf.Servers)+1 { 48 log.Error("Invalid server choice, aborting") 49 return 50 } 51 // 52 if choice <= len(w.conf.Servers) { 53 server := servers[choice-1] 54 client := w.servers[server] 55 56 delete(w.servers, server) 57 if client != nil { 58 client.Close() 59 } 60 delete(w.conf.Servers, server) 61 w.conf.flush() 62 63 log.Info("Disconnected existing server", "server", server) 64 w.networkStats() 65 return 66 } 67 // 68 if w.makeServer() != "" { 69 w.networkStats() 70 } 71 } 72 73 // 74 // 75 // 76 // 77 // 78 func (w *wizard) makeServer() string { 79 fmt.Println() 80 fmt.Println("What is the remote server's address ([username[:identity]@]hostname[:port])?") 81 82 // 83 input := w.readString() 84 85 client, err := dial(input, nil) 86 if err != nil { 87 log.Error("Server not ready for puppeth", "err", err) 88 return "" 89 } 90 // 91 w.servers[input] = client 92 w.conf.Servers[input] = client.pubkey 93 w.conf.flush() 94 95 return input 96 } 97 98 // 99 // 100 func (w *wizard) selectServer() string { 101 // 102 fmt.Println() 103 fmt.Println("Which server do you want to interact with?") 104 105 servers := w.conf.servers() 106 for i, server := range servers { 107 fmt.Printf(" %d. %s\n", i+1, server) 108 } 109 fmt.Printf(" %d. Connect another server\n", len(w.conf.Servers)+1) 110 111 choice := w.readInt() 112 if choice < 0 || choice > len(w.conf.Servers)+1 { 113 log.Error("Invalid server choice, aborting") 114 return "" 115 } 116 // 117 if choice <= len(w.conf.Servers) { 118 return servers[choice-1] 119 } 120 return w.makeServer() 121 } 122 123 // 124 // 125 func (w *wizard) manageComponents() { 126 // 127 fmt.Println() 128 129 var serviceHosts, serviceNames []string 130 for server, services := range w.services { 131 for _, service := range services { 132 serviceHosts = append(serviceHosts, server) 133 serviceNames = append(serviceNames, service) 134 135 fmt.Printf(" %d. Tear down %s on %s\n", len(serviceHosts), strings.Title(service), server) 136 } 137 } 138 fmt.Printf(" %d. Deploy new network component\n", len(serviceHosts)+1) 139 140 choice := w.readInt() 141 if choice < 0 || choice > len(serviceHosts)+1 { 142 log.Error("Invalid component choice, aborting") 143 return 144 } 145 // 146 if choice <= len(serviceHosts) { 147 // 148 service := serviceNames[choice-1] 149 server := serviceHosts[choice-1] 150 client := w.servers[server] 151 152 if out, err := tearDown(client, w.network, service, true); err != nil { 153 log.Error("Failed to tear down component", "err", err) 154 if len(out) > 0 { 155 fmt.Printf("%s\n", out) 156 } 157 return 158 } 159 // 160 services := w.services[server] 161 for i, name := range services { 162 if name == service { 163 w.services[server] = append(services[:i], services[i+1:]...) 164 if len(w.services[server]) == 0 { 165 delete(w.services, server) 166 } 167 } 168 } 169 log.Info("Torn down existing component", "server", server, "service", service) 170 return 171 } 172 // 173 w.deployComponent() 174 } 175 176 // 177 // 178 func (w *wizard) deployComponent() { 179 // 180 fmt.Println() 181 fmt.Println("What would you like to deploy? (recommended order)") 182 fmt.Println(" 1. Ethstats - Network monitoring tool") 183 fmt.Println(" 2. Bootnode - Entry point of the network") 184 fmt.Println(" 3. Sealer - Full node minting new blocks") 185 fmt.Println(" 4. Explorer - Chain analysis webservice (ethash only)") 186 fmt.Println(" 5. Wallet - Browser wallet for quick sends") 187 fmt.Println(" 6. Faucet - Crypto faucet to give away funds") 188 fmt.Println(" 7. Dashboard - Website listing above web-services") 189 190 switch w.read() { 191 case "1": 192 w.deployEthstats() 193 case "2": 194 w.deployNode(true) 195 case "3": 196 w.deployNode(false) 197 case "4": 198 w.deployExplorer() 199 case "5": 200 w.deployWallet() 201 case "6": 202 w.deployFaucet() 203 case "7": 204 w.deployDashboard() 205 default: 206 log.Error("That's not something I can do") 207 } 208 }