From dd6c03216b7ca60539ec131b628c6209590896fa Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Thu, 3 Jan 2019 06:28:00 +0000 Subject: [PATCH] remove unused client/config package Signed-off-by: Leo Chen --- client/config/config.go | 101 ---------------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 client/config/config.go diff --git a/client/config/config.go b/client/config/config.go deleted file mode 100644 index e47ad6a63..000000000 --- a/client/config/config.go +++ /dev/null @@ -1,101 +0,0 @@ -package config - -import ( - "bufio" - "log" - "os" - "strconv" - "strings" - - "github.com/harmony-one/harmony/p2p" -) - -// Entry is a single config of a node. -type Entry struct { - IP string - Port string - Role string - ShardID string -} - -// Config is a struct containing multiple Entry of all nodes. -type Config struct { - config []Entry -} - -// NewConfig returns a pointer to a Config. -func NewConfig() *Config { - config := Config{} - return &config -} - -// GetValidators returns all the validator peers -func (config *Config) GetValidators() []p2p.Peer { - var peerList []p2p.Peer - for _, entry := range config.config { - if entry.Role != "validator" { - continue - } - peer := p2p.Peer{Port: entry.Port, IP: entry.IP} - peerList = append(peerList, peer) - } - return peerList -} - -// GetShardIDToLeaderMap returns all the leader peers and corresponding shard Ids -func (config *Config) GetShardIDToLeaderMap() map[uint32]p2p.Peer { - shardIDLeaderMap := map[uint32]p2p.Peer{} - for _, entry := range config.config { - if entry.Role == "leader" { - val, err := strconv.Atoi(entry.ShardID) - if err == nil { - shardIDLeaderMap[uint32(val)] = p2p.Peer{IP: entry.IP, Port: entry.Port} - } else { - log.Print("[Generator] Error parsing the shard Id ", entry.ShardID) - } - } - } - return shardIDLeaderMap -} - -// GetClientPeer returns the client peer. -func (config *Config) GetClientPeer() *p2p.Peer { - for _, entry := range config.config { - if entry.Role != "client" { - continue - } - peer := p2p.Peer{Port: entry.Port, IP: entry.IP} - return &peer - } - return nil -} - -// GetClientPort returns the port of the client node in the config -func (config *Config) GetClientPort() string { - for _, entry := range config.config { - if entry.Role == "client" { - return entry.Port - } - } - return "" -} - -// ReadConfigFile parses the config file and return a 2d array containing the file data -func (config *Config) ReadConfigFile(filename string) error { - file, err := os.Open(filename) - if err != nil { - log.Fatal("Failed to read config file ", filename) - return err - } - defer file.Close() - fscanner := bufio.NewScanner(file) - - result := []Entry{} - for fscanner.Scan() { - p := strings.Split(fscanner.Text(), " ") - entry := Entry{p[0], p[1], p[2], p[3]} - result = append(result, entry) - } - config.config = result - return nil -}