Skip to content

Commit

Permalink
fix: highlight func does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
sjlleo committed Jun 12, 2022
1 parent 35bc155 commit c59e843
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions printer/realtime_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package printer

import (
"fmt"
"reflect"
"strings"

"github.com/xgadget-lab/nexttrace/ipgeo"
"github.com/xgadget-lab/nexttrace/trace"
)

Expand All @@ -23,7 +21,13 @@ func findLatestAvailableHop(res *trace.Result, ttl int, probesIndex int) int {
for ttl > 0 {
// 查找上一个跃点是不是有效结果
ttl--
if res.Hops[ttl][probesIndex].Address != nil {
// 判断此TTL跃点是否有效并判断地理位置结构体是否已经初始化
if res.Hops[ttl][probesIndex].Success && res.Hops[ttl][probesIndex].Geo != nil {
// TTL虽有效,但地理位置API没有能够正确返回数据,依旧不能视为有效数据
if res.Hops[ttl][probesIndex].Geo.Country == "" {
// 跳过继续寻找上一个有效跃点
continue
}
return ttl
}
}
Expand Down Expand Up @@ -65,8 +69,8 @@ func makeHopsType(res *trace.Result, ttl int) map[int]HopInfo {
// 创建一个字典,存放所有当前TTL的跃点类型集合
hopProbesMap := make(map[int]HopInfo)
for i := range res.Hops[ttl] {
// 判断是否Hops以及Geo结构体已经初始化
if res.Hops[ttl][i].Address != nil && reflect.DeepEqual(res.Hops[ttl][i].Geo, ipgeo.IPGeoData{}) {
// 判断是否res.Hops[ttl][i]是一个有效的跃点并且地理位置信息已经初始化
if res.Hops[ttl][i].Success && res.Hops[ttl][i].Geo != nil {
if availableTTL := findLatestAvailableHop(res, ttl, i); availableTTL != -1 {
switch {
case strings.Contains(res.Hops[ttl][i].Geo.District, "IXP") || strings.Contains(strings.ToLower(res.Hops[ttl][i].Hostname), "ix"):
Expand All @@ -75,10 +79,11 @@ func makeHopsType(res *trace.Result, ttl int) map[int]HopInfo {
hopProbesMap[i] = Peer
case strings.Contains(res.Hops[ttl][i].Geo.District, "PoP"):
hopProbesMap[i] = PoP
// 2个有效跃点必须都为有效数据
case res.Hops[availableTTL][i].Geo.Country != "LAN Address" && res.Hops[ttl][i].Geo.Country != "LAN Address" &&
res.Hops[availableTTL][i].Geo.Country != "" && res.Hops[ttl][i].Geo.Country != "" &&
// 2个有效跃点必须都为有效数据,如果当前跳没有地理位置信息或者为局域网,不能视为有效节点
case res.Hops[availableTTL][i].Geo.Country != "LAN Address" && res.Hops[ttl][i].Geo.Country != "LAN Address" && res.Hops[ttl][i].Geo.Country != "" &&
// 一个跃点在中国大陆,另外一个跃点在其他地区,则可以推断出数据包跨境
chinaMainland(res.Hops[availableTTL][i]) != chinaMainland(res.Hops[ttl][i]):
// TODO: 将先后2跳跃点信息汇报给API,以完善相关数据
hopProbesMap[i] = Aboard
}
} else {
Expand Down

0 comments on commit c59e843

Please sign in to comment.