OSDN Git Service

rename node.host to node.ip
authorHAOYUatHZ <haoyu@protonmail.com>
Thu, 29 Aug 2019 02:57:09 +0000 (10:57 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Thu, 29 Aug 2019 02:57:09 +0000 (10:57 +0800)
docs/precog/config_example.json
docs/precog/sql_dump/precog_schema.sql
toolbar/precog/config/config.go
toolbar/precog/database/orm/node.go
toolbar/precog/monitor/connection.go
toolbar/precog/monitor/discover.go
toolbar/precog/monitor/monitor.go
toolbar/precog/monitor/stats.go

index ca47453..c8b276b 100644 (file)
         {
             "alias" : "seed1",
             "xpub" : "f2767279cd01ed8793808e0542a18958e1a2f3a6b6fe5328ec79596a022bc6f085951a98a631917563f86bb91db9159dd2969ff9d690fc12b250baff2b6f6a1d",
-            "host": "47.103.79.68",
+            "ip": "47.103.79.68",
             "port": 56656
         },
         {
             "alias" : "seed2",
             "xpub" : "c785deb76af14e918ea05eeab863288c48b16d1816621adf74ada868e8e3246780bf5206dc5a0e3efef0c119978e11ed75eca9d3b50846e37c55cf8d56717c4f",
-            "host": "47.103.13.86",
+            "ip": "47.103.13.86",
             "port": 56656
         },
         {
             "alias" : "seed3",
             "xpub" : "22bc19ec65d4ee524c5130575ddff041e712dbb415740eae314fd3359aa3978319384cd3ded8c4125ca2774716d7285268ebf1d85091eef8e7ad03077857e7ab",
-            "host": "47.102.193.119",
+            "ip": "47.102.193.119",
             "port": 56656
         },
         {
             "alias" : "seed4",
             "xpub" : "214c0e6827346e9fee1056c4c8b96cefd67b75ed1dead59e4e4e3eee8c1fe095dbe7a7fb61bb23b4ab66cde2a1c04466b8d3e8efa21cf7eee064c70fb1525b14",
-            "host": "47.103.17.22",
+            "ip": "47.103.17.22",
             "port": 56656
         }
     ]
index b460e51..e28e6bf 100644 (file)
@@ -20,7 +20,7 @@ CREATE TABLE `nodes` (
   `alias` varchar(128) NOT NULL DEFAULT '',
   `xpub` char(128) NOT NULL DEFAULT '',
   `public_key` char(64) NOT NULL DEFAULT '',
-  `host` varchar(128) NOT NULL DEFAULT '',
+  `ip` varchar(128) NOT NULL DEFAULT '',
   `port` smallint unsigned NOT NULL DEFAULT '0',
   `best_height` int(11) DEFAULT '0',
   `latest_daily_uptime_minutes` int(11) DEFAULT '0',
index 55a905a..16facd6 100644 (file)
@@ -51,7 +51,7 @@ type Node struct {
        Alias     string        `json:"alias"`
        XPub      *chainkd.XPub `json:"xpub"`
        PublicKey string        `json:"public_key"`
-       Host      string        `json:"host"`
+       IP        string        `json:"ip"`
        Port      uint16        `json:"port"`
 }
 
index 84fbc0c..2e3e50b 100644 (file)
@@ -9,7 +9,7 @@ type Node struct {
        Alias                    string
        Xpub                     string
        PublicKey                string
-       Host                     string
+       IP                       string
        Port                     uint16
        BestHeight               uint64
        LatestDailyUptimeMinutes uint64
index 0e27199..ecc0c4e 100644 (file)
@@ -30,17 +30,7 @@ func (m *monitor) dialNodes() error {
 
        addresses := make([]*p2p.NetAddress, 0)
        for i := 0; i < len(nodes); i++ {
-               ips, err := net.LookupIP(nodes[i].Host)
-               if err != nil {
-                       log.Error(err)
-                       continue
-               }
-               if len(ips) == 0 {
-                       log.Errorf("fail to look up ip for %s", nodes[i].Host)
-                       continue
-               }
-
-               address := p2p.NewNetAddressIPPort(ips[0], nodes[i].Port)
+               address := p2p.NewNetAddressIPPort(net.ParseIP(nodes[i].IP), nodes[i].Port)
                addresses = append(addresses, address)
        }
 
index c65dcb1..8bbe73a 100644 (file)
@@ -37,7 +37,7 @@ func (m *monitor) discoveryRoutine() {
 func (m *monitor) saveDiscoveredNode(node *dht.Node) {
        if err := m.upSertNode(&config.Node{
                PublicKey: node.ID.String(),
-               Host:      node.IP.String(),
+               IP:        node.IP.String(),
                Port:      node.TCP,
        }); err == nil {
                m.discvMap[node.ID.String()] = node
index f9ae5f0..ab1e278 100644 (file)
@@ -94,7 +94,7 @@ func makePath() (string, error) {
 func (m *monitor) Run() {
        var seeds []string
        for _, node := range m.cfg.Nodes {
-               seeds = append(seeds, fmt.Sprintf("%s:%d", node.Host, node.Port))
+               seeds = append(seeds, fmt.Sprintf("%s:%d", node.IP, node.Port))
                if err := m.upSertNode(&node); err != nil {
                        log.Error(err)
                }
index ba918c8..0b1eaca 100644 (file)
@@ -33,13 +33,13 @@ func (m *monitor) upSertNode(node *config.Node) error {
        if node.XPub != nil {
                ormNode.Xpub = node.XPub.String()
        }
-       ormNode.Host = node.Host
+       ormNode.IP = node.IP
        ormNode.Port = node.Port
        return m.db.Where(&orm.Node{PublicKey: ormNode.PublicKey}).
                Assign(&orm.Node{
                        Xpub:  ormNode.Xpub,
                        Alias: ormNode.Alias,
-                       Host:  ormNode.Host,
+                       IP:    ormNode.IP,
                        Port:  ormNode.Port,
                }).FirstOrCreate(ormNode).Error
 }