github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/cmd/puppeth/wizard_ethstats.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:33</date> 10 //</624450069847871488> 11 12 13 package main 14 15 import ( 16 "fmt" 17 "sort" 18 19 "github.com/ethereum/go-ethereum/log" 20 ) 21 22 //deployethstats查询用户在部署ethstats时的各种输入 23 // 24 func (w *wizard) deployEthstats() { 25 // 26 server := w.selectServer() 27 if server == "" { 28 return 29 } 30 client := w.servers[server] 31 32 //从服务器检索任何活动的ethstats配置 33 infos, err := checkEthstats(client, w.network) 34 if err != nil { 35 infos = ðstatsInfos{ 36 port: 80, 37 host: client.server, 38 secret: "", 39 } 40 } 41 existed := err == nil 42 43 //找出要监听的端口 44 fmt.Println() 45 fmt.Printf("Which port should ethstats listen on? (default = %d)\n", infos.port) 46 infos.port = w.readDefaultInt(infos.port) 47 48 //图1部署ethstats的虚拟主机 49 if infos.host, err = w.ensureVirtualHost(client, infos.port, infos.host); err != nil { 50 log.Error("Failed to decide on ethstats host", "err", err) 51 return 52 } 53 // 54 fmt.Println() 55 if infos.secret == "" { 56 fmt.Printf("What should be the secret password for the API? (must not be empty)\n") 57 infos.secret = w.readString() 58 } else { 59 fmt.Printf("What should be the secret password for the API? (default = %s)\n", infos.secret) 60 infos.secret = w.readDefaultString(infos.secret) 61 } 62 //收集禁止报告的黑名单 63 if existed { 64 fmt.Println() 65 fmt.Printf("Keep existing IP %v blacklist (y/n)? (default = yes)\n", infos.banned) 66 if !w.readDefaultYesNo(true) { 67 // 68 fmt.Println() 69 fmt.Printf("Clear out blacklist and start over (y/n)? (default = no)\n") 70 if w.readDefaultYesNo(false) { 71 infos.banned = nil 72 } 73 //允许用户显式添加/删除某些IP地址 74 fmt.Println() 75 fmt.Println("Which additional IP addresses should be blacklisted?") 76 for { 77 if ip := w.readIPAddress(); ip != "" { 78 infos.banned = append(infos.banned, ip) 79 continue 80 } 81 break 82 } 83 fmt.Println() 84 fmt.Println("Which IP addresses should not be blacklisted?") 85 for { 86 if ip := w.readIPAddress(); ip != "" { 87 for i, addr := range infos.banned { 88 if ip == addr { 89 infos.banned = append(infos.banned[:i], infos.banned[i+1:]...) 90 break 91 } 92 } 93 continue 94 } 95 break 96 } 97 sort.Strings(infos.banned) 98 } 99 } 100 //尝试在主机上部署ethstats服务器 101 nocache := false 102 if existed { 103 fmt.Println() 104 fmt.Printf("Should the ethstats be built from scratch (y/n)? (default = no)\n") 105 nocache = w.readDefaultYesNo(false) 106 } 107 trusted := make([]string, 0, len(w.servers)) 108 for _, client := range w.servers { 109 if client != nil { 110 trusted = append(trusted, client.address) 111 } 112 } 113 if out, err := deployEthstats(client, w.network, infos.port, infos.secret, infos.host, trusted, infos.banned, nocache); err != nil { 114 log.Error("Failed to deploy ethstats container", "err", err) 115 if len(out) > 0 { 116 fmt.Printf("%s\n", out) 117 } 118 return 119 } 120 //一切正常,运行网络扫描以获取任何更改 121 w.networkStats() 122 } 123