From 6eadebfbb212121d2c12fbc6e5d0c91f948bf6ba Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Mon, 10 Sep 2018 00:23:14 -0700 Subject: [PATCH] get leaders. --- client/utils.go | 24 +++++++++++++++++++++++- client/wallet/main.go | 28 ++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/client/utils.go b/client/utils.go index c1a9f8590..72ce0c0e3 100644 --- a/client/utils.go +++ b/client/utils.go @@ -1,6 +1,13 @@ package client -import "github.com/simple-rules/harmony-benchmark/crypto/pki" +import ( + "bytes" + "io" + "log" + "net/http" + + "github.com/simple-rules/harmony-benchmark/crypto/pki" +) var AddressToIntPriKeyMap map[[20]byte]int // For convenience, we use int as the secret seed for generating private key @@ -14,3 +21,18 @@ func LookUpIntPriKey(address [20]byte) (int, bool) { value, ok := AddressToIntPriKeyMap[address] return value, ok } + +func DownloadUrlAsString(url string) (string, error) { + response, err := http.Get(url) + buf := bytes.NewBufferString("") + if err != nil { + log.Fatal(err) + } else { + defer response.Body.Close() + _, err := io.Copy(buf, response.Body) + if err != nil { + log.Fatal(err) + } + } + return buf.String(), err +} diff --git a/client/wallet/main.go b/client/wallet/main.go index b90762ea2..0e1677525 100644 --- a/client/wallet/main.go +++ b/client/wallet/main.go @@ -6,6 +6,14 @@ import ( "errors" "flag" "fmt" + "strings" + + "io" + "io/ioutil" + math_rand "math/rand" + "os" + "strconv" + "time" "github.com/dedis/kyber" "github.com/simple-rules/harmony-benchmark/blockchain" @@ -17,12 +25,6 @@ import ( "github.com/simple-rules/harmony-benchmark/p2p" proto_node "github.com/simple-rules/harmony-benchmark/proto/node" "github.com/simple-rules/harmony-benchmark/utils" - "io" - "io/ioutil" - math_rand "math/rand" - "os" - "strconv" - "time" ) func main() { @@ -218,6 +220,20 @@ func main() { } } +func getLeaders() []p2p.Peer { + str, _ := client.DownloadUrlAsString("https://s3-us-west-2.amazonaws.com/unique-bucket-bin/leaders.txt") + lines := strings.Split(str, "\n") + var leaders []p2p.Peer + for _, line := range lines { + if line == "" { + continue + } + parts := strings.Split(line, " ") + leaders = append(leaders, p2p.Peer{Ip: parts[0], Port: parts[1]}) + } + return leaders +} + func CreateWalletServerNode() *node.Node { configr := client_config.NewConfig() configr.ReadConfigFile("local_config_shards.txt")