cleanup. move configr to client/config

pull/69/head
Minh Doan 6 years ago
parent 598c32f85b
commit 178154bb95
  1. 4
      client/btctxgen/main.go
  2. 4
      client/txgen/main.go
  3. 15
      client/wallet/main.go
  4. 99
      configr/main.go

@ -28,7 +28,7 @@ import (
"github.com/simple-rules/harmony-benchmark/blockchain"
"github.com/simple-rules/harmony-benchmark/client"
"github.com/simple-rules/harmony-benchmark/client/btctxiter"
"github.com/simple-rules/harmony-benchmark/configr"
"github.com/simple-rules/harmony-benchmark/client/config"
"github.com/simple-rules/harmony-benchmark/consensus"
"github.com/simple-rules/harmony-benchmark/log"
"github.com/simple-rules/harmony-benchmark/node"
@ -176,7 +176,7 @@ func main() {
flag.Parse()
// Read the configs
configr := configr.NewConfigr()
configr := config.NewConfig()
configr.ReadConfigFile(*configFile)
leaders, shardIDs := configr.GetLeadersAndShardIds()

@ -10,7 +10,7 @@ import (
"github.com/simple-rules/harmony-benchmark/blockchain"
"github.com/simple-rules/harmony-benchmark/client"
"github.com/simple-rules/harmony-benchmark/configr"
"github.com/simple-rules/harmony-benchmark/client/config"
"github.com/simple-rules/harmony-benchmark/consensus"
"github.com/simple-rules/harmony-benchmark/crypto/pki"
"github.com/simple-rules/harmony-benchmark/log"
@ -255,7 +255,7 @@ func main() {
flag.Parse()
// Read the configs
configr := configr.NewConfigr()
configr := config.NewConfig()
configr.ReadConfigFile(*configFile)
leaders, shardIds := configr.GetLeadersAndShardIds()

@ -6,20 +6,21 @@ import (
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"strconv"
"time"
"github.com/dedis/kyber"
"github.com/simple-rules/harmony-benchmark/blockchain"
"github.com/simple-rules/harmony-benchmark/client"
"github.com/simple-rules/harmony-benchmark/configr"
"github.com/simple-rules/harmony-benchmark/client/config"
"github.com/simple-rules/harmony-benchmark/crypto"
"github.com/simple-rules/harmony-benchmark/crypto/pki"
"github.com/simple-rules/harmony-benchmark/node"
"github.com/simple-rules/harmony-benchmark/p2p"
proto_node "github.com/simple-rules/harmony-benchmark/proto/node"
"io"
"io/ioutil"
"os"
"strconv"
"time"
)
func main() {
@ -177,7 +178,7 @@ func main() {
}
func FetchUtxos() (blockchain.UtxoMap, error) {
configr := configr.NewConfigr()
configr := config.NewConfig()
configr.ReadConfigFile("local_config_shards.txt")
leaders, _ := configr.GetLeadersAndShardIds()
clientPeer := configr.GetClientPeer()

@ -1,99 +0,0 @@
package configr
import (
"bufio"
"log"
"os"
"strconv"
"strings"
"github.com/simple-rules/harmony-benchmark/p2p"
)
type ConfigEntry struct {
IP string
Port string
Role string
ShardID string
}
type Configr struct {
config []ConfigEntry
}
func NewConfigr() *Configr {
configr := Configr{}
return &configr
}
// Gets all the validator peers
func (configr *Configr) GetValidators() []p2p.Peer {
var peerList []p2p.Peer
for _, entry := range configr.config {
if entry.Role != "validator" {
continue
}
peer := p2p.Peer{Port: entry.Port, Ip: entry.IP}
peerList = append(peerList, peer)
}
return peerList
}
// Gets all the leader peers and corresponding shard Ids
func (configr *Configr) GetLeadersAndShardIds() ([]p2p.Peer, []uint32) {
var peerList []p2p.Peer
var shardIDs []uint32
for _, entry := range configr.config {
if entry.Role == "leader" {
peerList = append(peerList, p2p.Peer{Ip: entry.IP, Port: entry.Port})
val, err := strconv.Atoi(entry.ShardID)
if err == nil {
shardIDs = append(shardIDs, uint32(val))
} else {
log.Print("[Generator] Error parsing the shard Id ", entry.ShardID)
}
}
}
return peerList, shardIDs
}
func (configr *Configr) GetClientPeer() *p2p.Peer {
for _, entry := range configr.config {
if entry.Role != "client" {
continue
}
peer := p2p.Peer{Port: entry.Port, Ip: entry.IP}
return &peer
}
return nil
}
// Gets the port of the client node in the config
func (configr *Configr) GetClientPort() string {
for _, entry := range configr.config {
if entry.Role == "client" {
return entry.Port
}
}
return ""
}
// Parse the config file and return a 2d array containing the file data
func (configr *Configr) ReadConfigFile(filename string) error {
file, err := os.Open(filename)
defer file.Close()
if err != nil {
log.Fatal("Failed to read config file ", filename)
return err
}
fscanner := bufio.NewScanner(file)
result := []ConfigEntry{}
for fscanner.Scan() {
p := strings.Split(fscanner.Text(), " ")
entry := ConfigEntry{p[0], p[1], p[2], p[3]}
result = append(result, entry)
}
configr.config = result
return nil
}
Loading…
Cancel
Save