github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/cmd/puppeth/wizard_ethstats.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 "sort" 30 31 "github.com/ethereum/go-ethereum/log" 32 ) 33 34 //deployethstats查询用户在部署ethstats时的各种输入 35 // 36 func (w *wizard) deployEthstats() { 37 // 38 server := w.selectServer() 39 if server == "" { 40 return 41 } 42 client := w.servers[server] 43 44 // 45 infos, err := checkEthstats(client, w.network) 46 if err != nil { 47 infos = ðstatsInfos{ 48 port: 80, 49 host: client.server, 50 secret: "", 51 } 52 } 53 existed := err == nil 54 55 // 56 fmt.Println() 57 fmt.Printf("Which port should ethstats listen on? (default = %d)\n", infos.port) 58 infos.port = w.readDefaultInt(infos.port) 59 60 // 61 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 62 log.Error("Failed to decide on ethstats host", "err", err) 63 return 64 } 65 // 66 fmt.Println() 67 if infos.secret == "" { 68 fmt.Printf("What should be the secret password for the API? (must not be empty)\n") 69 infos.secret = w.readString() 70 } else { 71 fmt.Printf("What should be the secret password for the API? (default = %s)\n", infos.secret) 72 infos.secret = w.readDefaultString(infos.secret) 73 } 74 // 75 if existed { 76 fmt.Println() 77 fmt.Printf("Keep existing IP %v blacklist (y/n)? (default = yes)\n", infos.banned) 78 if w.readDefaultString("y") != "y" { 79 // 80 fmt.Println() 81 fmt.Printf("Clear out blacklist and start over (y/n)? (default = no)\n") 82 if w.readDefaultString("n") != "n" { 83 infos.banned = nil 84 } 85 //允许用户显式添加/删除某些IP地址 86 fmt.Println() 87 fmt.Println("Which additional IP addresses should be blacklisted?") 88 for { 89 if ip := w.readIPAddress(); ip != "" { 90 infos.banned = append(infos.banned, ip) 91 continue 92 } 93 break 94 } 95 fmt.Println() 96 fmt.Println("Which IP addresses should not be blacklisted?") 97 for { 98 if ip := w.readIPAddress(); ip != "" { 99 for i, addr := range infos.banned { 100 if ip == addr { 101 infos.banned = append(infos.banned[:i], infos.banned[i+1:]...) 102 break 103 } 104 } 105 continue 106 } 107 break 108 } 109 sort.Strings(infos.banned) 110 } 111 } 112 // 113 nocache := false 114 if existed { 115 fmt.Println() 116 fmt.Printf("Should the ethstats be built from scratch (y/n)? (default = no)\n") 117 nocache = w.readDefaultString("n") != "n" 118 } 119 trusted := make([]string, 0, len(w.servers)) 120 for _, client := range w.servers { 121 if client != nil { 122 trusted = append(trusted, client.address) 123 } 124 } 125 if out, err := deployEthstats(client, w.network, infos.port, infos.secret, infos.host, trusted, infos.banned, nocache); err != nil { 126 log.Error("Failed to deploy ethstats container", "err", err) 127 if len(out) > 0 { 128 fmt.Printf("%s\n", out) 129 } 130 return 131 } 132 // 133 w.networkStats() 134 }