The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/discovery/discovery.go

71 lines
1.5 KiB

package discovery
import (
"fmt"
"github.com/dedis/kyber"
"github.com/harmony-one/harmony/p2p"
)
6 years ago
// ConfigEntry is the config entry.
type ConfigEntry struct {
IP string
Port string
Role string
ShardID string
ValidatorID int // Validator ID in its shard.
leader p2p.Peer
self p2p.Peer
peers []p2p.Peer
priK kyber.Scalar
pubK kyber.Point
}
func (config ConfigEntry) String() string {
return fmt.Sprintf("idc: %v:%v", config.IP, config.Port)
}
6 years ago
// New return new ConfigEntry.
// TODO: This should be change because this package is discovery and New here implies New Discovery.
func New(priK kyber.Scalar, pubK kyber.Point) *ConfigEntry {
var config ConfigEntry
config.priK = priK
config.pubK = pubK
config.peers = make([]p2p.Peer, 0)
return &config
}
6 years ago
// StartClientMode starts client mode.
func (config *ConfigEntry) StartClientMode(idcIP, idcPort string) error {
config.IP = "myip"
config.Port = "myport"
fmt.Printf("idc ip/port: %v/%v\n", idcIP, idcPort)
// ...
// TODO: connect to idc, and wait unless acknowledge
return nil
}
6 years ago
// GetShardID ...
func (config *ConfigEntry) GetShardID() string {
return config.ShardID
}
6 years ago
// GetPeers ...
func (config *ConfigEntry) GetPeers() []p2p.Peer {
return config.peers
}
6 years ago
// GetLeader ...
func (config *ConfigEntry) GetLeader() p2p.Peer {
return config.leader
}
6 years ago
// GetSelfPeer ...
func (config *ConfigEntry) GetSelfPeer() p2p.Peer {
return config.self
}