Merge pull request #1126 from harmony-ek/make_dns_zone_configurable

Make DNS zone configurable via -dns_zone
pull/1128/head
Eugene Kim 6 years ago committed by GitHub
commit f4f9d9c838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      cmd/harmony/main.go
  2. 6
      internal/configs/net/config.go
  3. 10
      node/node.go
  4. 8
      node/node_syncing.go

@ -85,8 +85,8 @@ var (
metricsReportURL = flag.String("metrics_report_url", "", "If set, reports metrics to this URL.")
versionFlag = flag.Bool("version", false, "Output version info")
onlyLogTps = flag.Bool("only_log_tps", false, "Only log TPS if true")
dnsFlag = flag.Bool("dns", true, "use harmony dns nodes if true; use libp2p peer discovery if false")
dnsZone = flag.String("dns_zone", "", "if given and not empty, use peers from the zone (default: use libp2p peer discovery instead)")
dnsFlag = flag.Bool("dns", true, "[deprecated] equivalent to -dns_zone t.hmny.io")
//Leader needs to have a minimal number of peers to start consensus
minPeers = flag.Int("min_peers", 100, "Minimal number of Peers in shard")
// Key file to store the private key
@ -318,7 +318,11 @@ func setUpConsensusAndNode(nodeConfig *nodeconfig.ConfigType) *node.Node {
// Current node.
chainDBFactory := &shardchain.LDBFactory{RootDir: nodeConfig.DBDir}
currentNode := node.New(nodeConfig.Host, currentConsensus, chainDBFactory, *isArchival)
currentNode.SetDNSFlag(*dnsFlag)
if *dnsZone != "" {
currentNode.SetDNSZone(*dnsZone)
} else if *dnsFlag {
currentNode.SetDNSZone("t.hmny.io")
}
currentNode.NodeConfig.SetRole(nodeconfig.NewNode)
// TODO: add staking support
// currentNode.StakingAccount = myAccount

@ -1,6 +0,0 @@
package netconfig
var (
// DNS harmony dns server for harmony nodes IP
DNS = [4]string{"s0.t.hmny.io", "s1.t.hmny.io", "s2.t.hmny.io", "s3.t.hmny.io"}
)

@ -124,7 +124,7 @@ type Node struct {
stateSync *syncing.StateSync
beaconSync *syncing.StateSync
peerRegistrationRecord map[string]*syncConfig // record registration time (unixtime) of peers begin in syncing
dnsFlag bool
dnsZone string
// The p2p host used to send/receive p2p messages
host p2p.Host
@ -508,8 +508,8 @@ func (node *Node) AccountManager() *accounts.Manager {
return node.accountManager
}
// SetDNSFlag indicates whether use harmony dns server to get peer info for node syncing
func (node *Node) SetDNSFlag(flag bool) {
utils.GetLogInstance().Info("SetDNSFlag", "flag", flag)
node.dnsFlag = flag
// SetDNSZone sets the DNS zone to use to get peer info for node syncing
func (node *Node) SetDNSZone(zone string) {
utils.GetLogger().Info("using DNS zone to get peers", "zone", zone)
node.dnsZone = zone
}

@ -15,7 +15,6 @@ import (
downloader_pb "github.com/harmony-one/harmony/api/service/syncing/downloader/proto"
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/types"
netconfig "github.com/harmony-one/harmony/internal/configs/net"
"github.com/harmony-one/harmony/internal/ctxerror"
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/node/worker"
@ -70,8 +69,11 @@ func (node *Node) GetSyncingPeers() []p2p.Peer {
// GetPeersFromDNS get peers from our DNS server; TODO: temp fix for resolve node syncing
// the GetSyncingPeers return a bunch of "new" peers, all of them are out of sync
func (node *Node) GetPeersFromDNS() []p2p.Peer {
if node.dnsZone == "" {
return nil
}
shardID := node.Consensus.ShardID
dns := netconfig.DNS[shardID]
dns := fmt.Sprintf("s%d.%s", shardID, node.dnsZone)
addrs, err := net.LookupHost(dns)
if err != nil {
utils.GetLogInstance().Debug("GetPeersFromDNS cannot find peers", "error", err)
@ -163,7 +165,7 @@ func (node *Node) SupportSyncing() {
node.StartSyncingServer()
go node.SendNewBlockToUnsync()
if node.dnsFlag {
if node.dnsZone != "" {
go node.DoSyncing(node.Blockchain(), node.Worker, node.GetPeersFromDNS, true)
} else {
go node.DoSyncing(node.Blockchain(), node.Worker, node.GetSyncingPeers, true)

Loading…
Cancel
Save