OSDN Git Service

fix rtt
authorHAOYUatHZ <haoyu@protonmail.com>
Sun, 1 Sep 2019 06:42:55 +0000 (14:42 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Sun, 1 Sep 2019 06:42:55 +0000 (14:42 +0800)
docs/precog/sql_dump/precog_schema.sql
toolbar/precog/database/orm/node.go
toolbar/precog/monitor/stats.go

index e77971d..4b955ca 100644 (file)
@@ -23,7 +23,7 @@ CREATE TABLE `nodes` (
   `ip` varchar(128) NOT NULL DEFAULT '',
   `port` smallint unsigned NOT NULL DEFAULT '0',
   `best_height` int(11) DEFAULT '0',
-  `avg_lantency_ms` int(11) DEFAULT NULL,
+  `avg_rtt_ms` int(11) DEFAULT NULL,
   `latest_daily_uptime_minutes` int(11) DEFAULT '0',
   `status` tinyint(1) NOT NULL DEFAULT '0',
   `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
index c5964f6..d0fb3e8 100644 (file)
@@ -18,7 +18,7 @@ type Node struct {
        IP                       string
        Port                     uint16
        BestHeight               uint64
-       AvgLantencyMS            sql.NullInt64
+       AvgRttMS                 sql.NullInt64
        LatestDailyUptimeMinutes uint64
        Status                   uint8
        CreatedAt                time.Time `json:"alias"`
@@ -31,9 +31,9 @@ func (n *Node) MarshalJSON() ([]byte, error) {
                return nil, errors.New("fail to look up status")
        }
 
-       avgLantencyMS := uint64(0)
-       if n.AvgLantencyMS.Valid {
-               avgLantencyMS = uint64(n.AvgLantencyMS.Int64)
+       avgRttMS := uint64(0)
+       if n.AvgRttMS.Valid {
+               avgRttMS = uint64(n.AvgRttMS.Int64)
        }
 
        return json.Marshal(&struct {
@@ -41,7 +41,7 @@ func (n *Node) MarshalJSON() ([]byte, error) {
                PublicKey                string    `json:"publickey"`
                Address                  string    `json:"address"`
                BestHeight               uint64    `json:"best_height"`
-               AvgLantencyMS            uint64    `json:"avg_lantency_ms"`
+               AvgRttMS                 uint64    `json:"avg_rtt_ms"`
                LatestDailyUptimeMinutes uint64    `json:"latest_daily_uptime_minutes"`
                Status                   string    `json:"status"`
                UpdatedAt                time.Time `json:"updated_at"`
@@ -50,7 +50,7 @@ func (n *Node) MarshalJSON() ([]byte, error) {
                PublicKey:                n.PublicKey,
                Address:                  fmt.Sprintf("%s:%d", n.IP, n.Port),
                BestHeight:               n.BestHeight,
-               AvgLantencyMS:            avgLantencyMS,
+               AvgRttMS:                 avgRttMS,
                LatestDailyUptimeMinutes: n.LatestDailyUptimeMinutes,
                Status:    status,
                UpdatedAt: time.Now(),
index 614843f..af5942b 100644 (file)
@@ -34,6 +34,20 @@ func (m *monitor) upsertNode(node *config.Node) error {
        return m.db.Save(ormNode).Error
 }
 
+func parseRemoteAddr(remoteAddr string) (string, uint16, error) {
+       host, portStr, err := net.SplitHostPort(remoteAddr)
+       if err != nil {
+               return "", 0, err
+       }
+
+       port, err := strconv.Atoi(portStr)
+       if err != nil {
+               return "", 0, err
+       }
+
+       return host, uint16(port), nil
+}
+
 func (m *monitor) processDialResults(peerList []*p2p.Peer) error {
        var ormNodes []*orm.Node
        if err := m.db.Model(&orm.Node{}).Find(&ormNodes).Error; err != nil {
@@ -100,20 +114,6 @@ func (m *monitor) processPeerInfos(peerInfos []*peers.PeerInfo) {
        }
 }
 
-func parseRemoteAddr(remoteAddr string) (string, uint16, error) {
-       host, portStr, err := net.SplitHostPort(remoteAddr)
-       if err != nil {
-               return "", 0, err
-       }
-
-       port, err := strconv.Atoi(portStr)
-       if err != nil {
-               return "", 0, err
-       }
-
-       return host, uint16(port), nil
-}
-
 func (m *monitor) processPeerInfo(dbTx *gorm.DB, peerInfo *peers.PeerInfo) error {
        ip, port, err := parseRemoteAddr(peerInfo.RemoteAddr)
        if err != nil {
@@ -148,8 +148,8 @@ func (m *monitor) processPeerInfo(dbTx *gorm.DB, peerInfo *peers.PeerInfo) error
        latestLiveness := ormNodeLivenesses[0]
        lantencyMS := ping.Nanoseconds() / 1000000
        if lantencyMS != 0 {
-               ormNode.AvgLantencyMS = sql.NullInt64{
-                       Int64: (ormNode.AvgLantencyMS.Int64*int64(latestLiveness.PongTimes) + lantencyMS) / int64(latestLiveness.PongTimes+1),
+               ormNode.AvgRttMS = sql.NullInt64{
+                       Int64: (ormNode.AvgRttMS.Int64*int64(latestLiveness.PongTimes) + lantencyMS) / int64(latestLiveness.PongTimes+1),
                        Valid: true,
                }
        }