@ -12,6 +12,7 @@ import (
"github.com/harmony-one/harmony/p2p"
)
// ConfigEntry is the config entry.
type ConfigEntry struct {
IP string
Port string
@ -20,17 +21,18 @@ type ConfigEntry struct {
ValidatorID int // Validator ID in its shard.
}
// DistributionConfig is the distribution config.
type DistributionConfig struct {
config [ ] ConfigEntry
}
// done
// NewDistributionConfig creates new DistributionConfig
func NewDistributionConfig ( ) * DistributionConfig {
config := DistributionConfig { }
return & config
}
// Gets all the leader peers and corresponding shard Ids
// GetLeadersAndShardIDs get s all the leader peers and corresponding shard Ids
func ( config * DistributionConfig ) GetLeadersAndShardIDs ( ) ( [ ] p2p . Peer , [ ] uint32 ) {
var peerList [ ] p2p . Peer
var shardIDs [ ] uint32
@ -48,6 +50,7 @@ func (config *DistributionConfig) GetLeadersAndShardIDs() ([]p2p.Peer, []uint32)
return peerList , shardIDs
}
// GetClientPeer returns client peer.
func ( config * DistributionConfig ) GetClientPeer ( ) * p2p . Peer {
for _ , entry := range config . config {
if entry . Role != "client" {
@ -59,8 +62,7 @@ func (config *DistributionConfig) GetClientPeer() *p2p.Peer {
return nil
}
// done
// Gets the port of the client node in the config
// GetClientPort gets the port of the client node in the config
func ( config * DistributionConfig ) GetClientPort ( ) string {
for _ , entry := range config . config {
if entry . Role == "client" {
@ -70,8 +72,7 @@ func (config *DistributionConfig) GetClientPort() string {
return ""
}
// done
// Parse the config file and return a 2d array containing the file data
// ReadConfigFile parses the config file and return a 2d array containing the file data
func ( config * DistributionConfig ) ReadConfigFile ( filename string ) error {
file , err := os . Open ( filename )
if err != nil {
@ -123,7 +124,7 @@ func (config *DistributionConfig) GetPeers(ip, port, shardID string) []p2p.Peer
return peerList
}
// GetPeers Gets the validator list
// GetSelf Peer Gets the validator list
func ( config * DistributionConfig ) GetSelfPeer ( ip , port , shardID string ) p2p . Peer {
for _ , entry := range config . config {
if entry . IP == ip && entry . Port == port && entry . ShardID == shardID {
@ -147,10 +148,12 @@ func (config *DistributionConfig) GetLeader(shardID string) p2p.Peer {
return leaderPeer
}
// GetConfigEntries returns a list of ConfigEntry.
func ( config * DistributionConfig ) GetConfigEntries ( ) [ ] ConfigEntry {
return config . config
}
// GetMyConfigEntry ...
func ( config * DistributionConfig ) GetMyConfigEntry ( ip string , port string ) * ConfigEntry {
if config . config == nil {
return nil
@ -165,6 +168,6 @@ func (config *DistributionConfig) GetMyConfigEntry(ip string, port string) *Conf
func setKey ( peer * p2p . Peer ) {
// Get public key deterministically based on ip and port
priKey := crypto . Ed25519Curve . Scalar ( ) . SetInt64 ( int64 ( GetUniqueId FromPeer ( * peer ) ) ) // TODO: figure out why using a random hash value doesn't work for private key (schnorr)
priKey := crypto . Ed25519Curve . Scalar ( ) . SetInt64 ( int64 ( GetUniqueID FromPeer ( * peer ) ) ) // TODO: figure out why using a random hash value doesn't work for private key (schnorr)
peer . PubKey = pki . GetPublicKeyFromScalar ( priKey )
}