diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd72dd4..0c9157d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -166,7 +166,7 @@ jobs: git config --global user.name "${{ secrets.git_name }}" - name: Clone repo run: | - git clone https://github.com/xgadget-lab/homebrew-nexttrace.git + git clone https://github.com/nxtrace/homebrew-nexttrace.git - name: Exec scipt run: | cd homebrew-nexttrace @@ -183,7 +183,7 @@ jobs: run: | cd homebrew-nexttrace git commit -am 'Publish a new version with Formula' || true - git remote set-url origin https://${{ secrets.gt_token }}@github.com/xgadget-lab/homebrew-nexttrace.git + git remote set-url origin https://${{ secrets.gt_token }}@github.com/nxtrace/homebrew-nexttrace.git git push # env: # SSH_AUTH_SOCK: /tmp/ssh_agent.sock diff --git a/.github/workflows/publishNewFormula.yml b/.github/workflows/publishNewFormula.yml index 8c64550..65c6004 100644 --- a/.github/workflows/publishNewFormula.yml +++ b/.github/workflows/publishNewFormula.yml @@ -21,7 +21,7 @@ jobs: git config --global user.name "${{ secrets.git_name }}" - name: Clone repo run: | - git clone https://github.com/xgadget-lab/homebrew-nexttrace.git + git clone https://github.com/nxtrace/homebrew-nexttrace.git - name: Exec scipt run: | cd homebrew-nexttrace @@ -38,7 +38,7 @@ jobs: run: | cd homebrew-nexttrace git commit -am 'Publish a new version with Formula' || true - git remote set-url origin https://${{ secrets.gt_token }}@github.com/xgadget-lab/homebrew-nexttrace.git + git remote set-url origin https://${{ secrets.gt_token }}@github.com/nxtrace/homebrew-nexttrace.git git push # env: # SSH_AUTH_SOCK: /tmp/ssh_agent.sock diff --git a/README.md b/README.md index 527cbda..3ea0c99 100644 --- a/README.md +++ b/README.md @@ -43,19 +43,14 @@ We are extremely grateful to [DMIT](https://dmit.io) and [Misaka](https://misaka.io) and [Skywolf](https://skywolf.cloud) for providing the network infrastructure that powers this project. -## Announcement - -LeoMoeAPI v1 will end service support on September 1, 2024. Versions **v1.1.7** and below that rely on its service will become unusable. Please download from the [Ntrace-V1 repository](https://github.com/nxtrace/Ntrace-V1/releases) NextTrace. - -Because NextTrace V1 and V2 are branches with differing development philosophies, each is currently managed by an internal Owner focusing on different aspects. These branches cater to developers with varying needs. Now, the [V1](https://github.com/nxtrace/Ntrace-V1/) and [V2](https://github.com/sjlleo/MoeTrace) branch has established its own separate repository. For a considerably long period in the future, we plan to maintain the development and upkeep of both branches simultaneously. - ## How To Use Document Language: English | [简体中文](README_zh_CN.md) -Currently, **V2 version** is a completely redesigned project and is recruiting beta testers for this revamped version. If you are interested, please check out [sjlleo/MoeTrace](https://github.com/sjlleo/MoeTrace). +Regarding the NTrace-V1 and NTrace-core repositories:
+Both will largely remain consistent with each other. All development work is done within the NTrace-V1 repository. The NTrace-V1 repository releases new versions first. After running stably for an undetermined period, we will synchronize that version to NTrace-core. This means that the NTrace-V1 repository serves as a "beta" or "testing" version.
+Please note, there are exceptions to this synchronization. If a version of NTrace-V1 encounters a serious bug, NTrace-core will skip that flawed version and synchronize directly to the next version that resolves the issue. -For the **enhanced version of V1**, please visit [nxtrace/Ntrace-V1](https://github.com/nxtrace/Ntrace-V1). ### Automated Install * Linux @@ -435,7 +430,7 @@ We hope you can give us as much feedback as possible on IP geolocation errors (s Although other third-party APIs are integrated in this project, please refer to the official website of the third-party APIs for specific TOS and AUP. If you encounter IP data errors, please contact them directly to correct them. For feedback related to corrections about IP information, we currently have two channels available: ->- [IP 错误报告汇总帖](https://github.com/sjlleo/nexttrace/issues/41) in the GITHUB ISSUES section of this project (Recommended) +>- [IP 错误报告汇总帖](https://github.com/nxtrace/NTrace-core/issues/41) in the GITHUB ISSUES section of this project (Recommended) >- This project's dedicated correction email: `correction@moeqing.com` (Please note that this email is only for correcting IP-related information. For other feedback, please submit an ISSUE) How to obtain the freshly baked binary executable of the latest commit? @@ -443,4 +438,4 @@ How to obtain the freshly baked binary executable of the latest commit? ## Star History -[![Star History Chart](https://api.star-history.com/svg?repos=sjlleo/nexttrace&type=Date)](https://star-history.com/#sjlleo/nexttrace&Date) +[![Star History Chart](https://api.star-history.com/svg?repos=nxtrace/NTrace-core&type=Date)](https://star-history.com/#nxtrace/NTrace-core&Date) diff --git a/README_zh_CN.md b/README_zh_CN.md index 6f44ead..95b399a 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -46,27 +46,17 @@ 我们非常感谢 [DMIT](https://dmit.io) 和 [Misaka](https://misaka.io) 和 [Skywolf](https://skywolf.cloud) 提供了支持本项目所需的网络基础设施。 -## Announcement - -LeoMoeAPI v1 将于2024 年 9 月 1 日结束服务支持,届时依赖其提供服务的 **v1.1.7** 以下的版本将无法使用。请至 [Ntrace-V1 仓库下载](https://github.com/nxtrace/Ntrace-V1/releases) NextTrace。 - -由于 NextTrace V1 与 V2 分支是两个开发方向理念不完全相同的分支,目前由内部分别有一名 Owner 负责,各有其侧重点,面向不同需求的开发者,现 [V1](https://github.com/nxtrace/Ntrace-V1/) 和 [V2](https://github.com/sjlleo/MoeTrace) 分支分别已建立独立仓库,在未来相当长的一段时间里,我们会同时维护两个分支的开发与维护。 - ## How To Use Document Language: [English](README.md) | 简体中文 -目前 **V2版本** 为全新的重构项目,其正在招募内测该重构版本的用户,若有意请查看 [sjlleo/MoeTrace](https://github.com/sjlleo/MoeTrace)。 - -关于 **V1增强版本** 请转至 [nxtrace/Ntrace-V1](https://github.com/nxtrace/Ntrace-V1)。 - -## How To Use - -Document Language: [English](README.md) | 简体中文 +关于NTrace-V1和NTrace-core两个仓库的说明:
+二者将大体上保持一致。所有的开发工作均在NTrace-V1仓库中进行。NTrace-V1仓库首先发布新版本,在稳定运行一段时间后(时长不定),我们会把版本同步至NTrace-core。这意味着NTrace-V1仓库充当了一个“测试版”的角色。
+请注意,版本同步也存在例外。如果NTrace-V1的某个版本出现了严重的bug,NTrace-core会跳过这一有缺陷的版本,直接同步到下一个修复了该问题的版本。 ### Before Using -使用 NextTrace 之前,我们建议您先阅读 [#IP 数据以及精准度说明](https://github.com/sjlleo/nexttrace/blob/main/README_zh_CN.md#ip-%E6%95%B0%E6%8D%AE%E4%BB%A5%E5%8F%8A%E7%B2%BE%E5%87%86%E5%BA%A6%E8%AF%B4%E6%98%8E),在了解您自己的对数据精准度需求以后再进行抉择。 +使用 NextTrace 之前,我们建议您先阅读 [#IP 数据以及精准度说明](https://github.com/nxtrace/NTrace-core/blob/main/README_zh_CN.md#ip-%E6%95%B0%E6%8D%AE%E4%BB%A5%E5%8F%8A%E7%B2%BE%E5%87%86%E5%BA%A6%E8%AF%B4%E6%98%8E),在了解您自己的对数据精准度需求以后再进行抉择。 [NextTrace 的Telegram频道](https://t.me/nexttrace)由项目成员负责,会传递一部分通知,也会发布一些成员自己分享的小工具。项目成员的意见可作为未来项目发展的可能方向,随着开发进度变化可能会有所改动,不代表未来一定会实装,正式定稿公告会发布于 Issue 中。 @@ -381,7 +371,7 @@ Arguments: ## 第三方 IP 数据库 API 开发接口 -NextTrace 所有的的 IP 地理位置 `API DEMO` 可以参考[这里](https://github.com/sjlleo/nexttrace/blob/main/ipgeo/) +NextTrace 所有的的 IP 地理位置 `API DEMO` 可以参考[这里](https://github.com/nxtrace/NTrace-core/blob/main/ipgeo/) 你可以在这里添加你自己的 API 接口,为了 NextTrace 能够正确显示你接口中的内容,请参考 `leo.go` 中所需要的信息 @@ -442,7 +432,7 @@ nexttrace --pow-provider sakura ## IP 数据以及精准度说明 对于IP相关信息的纠错反馈,我们目前开放了两个渠道: ->- 本项目的GITHUB ISSUES区中的[IP 错误报告汇总帖](https://github.com/sjlleo/nexttrace/issues/41) +>- 本项目的GITHUB ISSUES区中的[IP 错误报告汇总帖](https://github.com/nxtrace/NTrace-core/issues/41) >- 本项目的纠错专用邮箱: `correction@moeqing.com` (请注意此邮箱仅供IP相关信息纠错专用,其他反馈请发送ISSUE) NextTrace 有多个数据源可以选择,目前默认使用的 LeoMoeAPI 为我们项目维护的数据源。 @@ -500,3 +490,9 @@ LAX,US,California,Los Anegles ``` 需要注意的是,NextTrace 支持自动匹配 CSV 中的城市名,如果您的 PTR 记录中有 `losangeles`,您可以只添加上面一条记录就可以正常识别并读取。 + +rkflow in GitHub Actions. + +## Star History + +[![Star History Chart](https://api.star-history.com/svg?repos=nxtrace/NTrace-core&type=Date)](https://star-history.com/#nxtrace/NTrace-core&Date) diff --git a/fast_trace/fast_trace_test.go b/fast_trace/fast_trace_test.go index e5fe70d..ae37618 100644 --- a/fast_trace/fast_trace_test.go +++ b/fast_trace/fast_trace_test.go @@ -1,36 +1,30 @@ package fastTrace import ( - "fmt" - "os" - "os/signal" "testing" - - "github.com/nxtrace/NTrace-core/trace" - "github.com/nxtrace/NTrace-core/wshandle" ) func TestTrace(t *testing.T) { - pFastTrace := ParamsFastTrace{ - SrcDev: "", - SrcAddr: "", - BeginHop: 1, - MaxHops: 30, - RDns: false, - AlwaysWaitRDNS: false, - Lang: "", - PktSize: 52, - } - ft := FastTracer{ParamsFastTrace: pFastTrace} - // 建立 WebSocket 连接 - w := wshandle.New() - w.Interrupt = make(chan os.Signal, 1) - signal.Notify(w.Interrupt, os.Interrupt) - defer func() { - w.Conn.Close() - }() - fmt.Println("TCP v4") - ft.TracerouteMethod = trace.TCPTrace + //pFastTrace := ParamsFastTrace{ + // SrcDev: "", + // SrcAddr: "", + // BeginHop: 1, + // MaxHops: 30, + // RDns: false, + // AlwaysWaitRDNS: false, + // Lang: "", + // PktSize: 52, + //} + //ft := FastTracer{ParamsFastTrace: pFastTrace} + //// 建立 WebSocket 连接 + //w := wshandle.New() + //w.Interrupt = make(chan os.Signal, 1) + //signal.Notify(w.Interrupt, os.Interrupt) + //defer func() { + // w.Conn.Close() + //}() + //fmt.Println("TCP v4") + //ft.TracerouteMethod = trace.TCPTrace //ft.tracert(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.EDU) //fmt.Println("TCP v6") //ft.tracert_v6(TestIPsCollection.Beijing.Location, TestIPsCollection.Beijing.EDU) diff --git a/go.mod b/go.mod index abcb111..d196e41 100644 --- a/go.mod +++ b/go.mod @@ -6,16 +6,16 @@ require ( github.com/akamensky/argparse v1.4.0 github.com/google/gopacket v1.1.19 github.com/oschwald/maxminddb-golang v1.12.0 - github.com/spf13/viper v1.16.0 + github.com/spf13/viper v1.17.0 github.com/stretchr/testify v1.8.4 github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 - github.com/tsosunchia/powclient v0.1.3 - golang.org/x/net v0.15.0 - golang.org/x/sync v0.3.0 + github.com/tsosunchia/powclient v0.1.4 + golang.org/x/net v0.16.0 + golang.org/x/sync v0.4.0 ) require ( - github.com/davecgh/go-spew v1.1.1 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -23,12 +23,16 @@ require ( github.com/mattn/go-isatty v0.0.19 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/sagikazarmark/locafero v0.3.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.10.0 // indirect github.com/spf13/cast v1.5.1 // indirect - github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/subosito/gotenv v1.6.0 // indirect + go.uber.org/multierr v1.11.0 // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect golang.org/x/text v0.13.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect ) @@ -41,6 +45,6 @@ require ( github.com/tidwall/gjson v1.17.0 github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/sys v0.13.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 81c0a37..4ea66be 100644 --- a/go.sum +++ b/go.sum @@ -49,8 +49,9 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -162,30 +163,32 @@ github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6 github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rodaine/table v1.1.0 h1:/fUlCSdjamMY8VifdQRIu3VWZXYLY7QHFkVorS8NTr4= github.com/rodaine/table v1.1.0/go.mod h1:Qu3q5wi1jTQD6B6HsP6szie/S4w1QUQ8pq22pz9iL8g= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= -github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= +github.com/sagikazarmark/locafero v0.3.0 h1:zT7VEGWC2DTflmccN/5T1etyKvxSxpHsjb9cJvm4SvQ= +github.com/sagikazarmark/locafero v0.3.0/go.mod h1:w+v7UsPNFwzF1cHuOajOOzoq4U7v/ig1mpRjqV+Bu1U= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/spf13/afero v1.10.0 h1:EaGW2JJh15aKOejeuJ+wpFSHnbd7GE6Wvp3TsNhb6LY= github.com/spf13/afero v1.10.0/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= -github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= -github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.16.0 h1:rGGH0XDZhdUOryiDWjmIvUSWpbNqisK8Wk0Vyefw8hc= -github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1FofRzQg= +github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI= +github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -205,8 +208,8 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -github.com/tsosunchia/powclient v0.1.3 h1:L29HQdyZZ0Vcrn0ZzNIyrTpLOnycm3oHF46sYJ+vkhQ= -github.com/tsosunchia/powclient v0.1.3/go.mod h1:Pm4MP3QqN74SfNskPpFIEyT+NQrcABGoXkkeRwjlMEE= +github.com/tsosunchia/powclient v0.1.4 h1:iAXUOiGPLJJTnzVSD0PY+4kBWm+SEMQZzd5ntEk1t0c= +github.com/tsosunchia/powclient v0.1.4/go.mod h1:Pm4MP3QqN74SfNskPpFIEyT+NQrcABGoXkkeRwjlMEE= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -217,6 +220,8 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -234,6 +239,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -289,8 +296,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.16.0 h1:7eBu7KsSvFDtSXUIDbh3aqlK4DPsZ1rByC8PFfBThos= +golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -310,8 +317,8 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -350,8 +357,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -506,8 +513,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/pow/pow.go b/pow/pow.go index c539826..0b823fd 100644 --- a/pow/pow.go +++ b/pow/pow.go @@ -23,10 +23,13 @@ func GetToken(fastIp string, host string, port string) (string, error) { if proxyUrl != nil { getTokenParams.Proxy = proxyUrl } - var err error + var ( + token string + err error + ) // 尝试三次RetToken,如果都失败了,异常退出 for i := 0; i < 3; i++ { - token, err := powclient.RetToken(getTokenParams) + token, err = powclient.RetToken(getTokenParams) if err != nil { continue } @@ -38,5 +41,5 @@ func GetToken(fastIp string, host string, port string) (string, error) { } fmt.Println("RetToken failed 3 times, please try again after a while, exit") os.Exit(1) - return "", nil + return "", err } diff --git a/printer/basic.go b/printer/basic.go index 686743a..e0ceb66 100644 --- a/printer/basic.go +++ b/printer/basic.go @@ -41,13 +41,14 @@ func CopyRight() { color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "zhshch@athorx.com"), ) - MoeQingOrgCopyRight() - PluginCopyRight() + moeQingOrgCopyRight() + sponsor() + //PluginCopyRight() } -func MoeQingOrgCopyRight() { +func moeQingOrgCopyRight() { fmt.Fprintf(color.Output, "%s\n%s %s\n%s %s\n\n", - color.New(color.FgHiYellow, color.Bold).Sprintf("%s", "MoeQing Network"), + color.New(color.FgGreen, color.Bold).Sprintf("%s", "Supported by MoeQing Network"), color.New(color.FgWhite, color.Bold).Sprintf("%s", "YekongTAT"), color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "yekongtat@gmail.com"), color.New(color.FgWhite, color.Bold).Sprintf("%s", "Haima"), @@ -55,14 +56,23 @@ func MoeQingOrgCopyRight() { ) } -func PluginCopyRight() { - fmt.Fprintf(color.Output, "%s\n%s %s\n\n", - color.New(color.FgGreen, color.Bold).Sprintf("%s", "NextTrace Map Plugin Author"), - color.New(color.FgWhite, color.Bold).Sprintf("%s", "Tso"), - color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "tsosunchia@gmail.com"), +func sponsor() { + fmt.Fprintf(color.Output, "%s\n%s\n%s\n%s\n", + color.New(color.FgGreen, color.Bold).Sprintf("%s", "Sponsored by the following entities"), + color.New(color.FgWhite, color.Bold).Sprintf("%s", "DMIT.io"), + color.New(color.FgWhite, color.Bold).Sprintf("%s", "Misaka.io"), + color.New(color.FgWhite, color.Bold).Sprintf("%s", "Skywolf.cloud"), ) } +//func PluginCopyRight() { +// fmt.Fprintf(color.Output, "%s\n%s %s\n\n", +// color.New(color.FgGreen, color.Bold).Sprintf("%s", "NextTrace Map Plugin Author"), +// color.New(color.FgWhite, color.Bold).Sprintf("%s", "Tso"), +// color.New(color.FgHiBlack, color.Bold).Sprintf("%s", "tsosunchia@gmail.com"), +// ) +//} + func PrintTraceRouteNav(ip net.IP, domain string, dataOrigin string, maxHops int, packetSize int) { fmt.Println("IP Geo Data Provider: " + dataOrigin) diff --git a/util/latency.go b/util/latency.go index 4ac384d..93f45df 100644 --- a/util/latency.go +++ b/util/latency.go @@ -1,18 +1,26 @@ package util import ( + "crypto/tls" "fmt" + "io" "log" "net" + "net/http" "strings" "time" "github.com/fatih/color" ) +type ResponseInfo struct { + IP string + Latency string + Content string +} + var ( - result string - results = make(chan string) + results = make(chan ResponseInfo) ) var FastIpCache = "" @@ -31,49 +39,75 @@ func GetFastIP(domain string, port string, enableOutput bool) string { } for _, ip := range ips { - go checkLatency(ip.String(), port) + go checkLatency(domain, ip.String(), port) } + var result ResponseInfo + select { case result = <-results: case <-time.After(1 * time.Second): - } - if result == "" { log.Fatal("IP connection has been timeout, please check your network") - } - res := strings.Split(result, "-") - if len(ips) > 1 { + } + + if len(ips) > 0 { if enableOutput { - _, _ = fmt.Fprintf(color.Output, "%s prefered API IP - %s - %s\n", + _, _ = fmt.Fprintf(color.Output, "%s prefered API IP - %s - %s - %s", color.New(color.FgWhite, color.Bold).Sprintf("[NextTrace API]"), - color.New(color.FgGreen, color.Bold).Sprintf("%s", res[0]), - color.New(color.FgCyan, color.Bold).Sprintf("%sms", res[1]), + color.New(color.FgGreen, color.Bold).Sprintf("%s", result.IP), + color.New(color.FgCyan, color.Bold).Sprintf("%sms", result.Latency), + color.New(color.FgGreen, color.Bold).Sprintf("%s", result.Content), ) } } - FastIpCache = res[0] - return res[0] + FastIpCache = result.IP + return result.IP } -func checkLatency(ip string, port string) { +func checkLatency(domain string, ip string, port string) { start := time.Now() if !strings.Contains(ip, ".") { ip = "[" + ip + "]" } - conn, err := net.DialTimeout("tcp", ip+":"+port, time.Second*1) + + // 自定义DialContext以使用指定的IP连接 + transport := &http.Transport{ + //DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) { + // return net.DialTimeout(network, addr, 1*time.Second) + //}, + TLSClientConfig: &tls.Config{ + ServerName: domain, + }, + TLSHandshakeTimeout: 1 * time.Second, + } + + client := &http.Client{ + Transport: transport, + Timeout: 2 * time.Second, + } + + //此处虽然是 https://domain/ 但是实际上会使用指定的IP连接 + req, err := http.NewRequest("GET", "https://"+ip+":"+port+"/", nil) if err != nil { + results <- ResponseInfo{IP: ip, Latency: "error", Content: ""} return } - defer func(conn net.Conn) { - err := conn.Close() - if err != nil { - return - } - }(conn) - if result == "" { - result = fmt.Sprintf("%s-%.2f", ip, float64(time.Since(start))/float64(time.Millisecond)) - results <- result + req.Host = domain + resp, err := client.Do(req) + if err != nil { + results <- ResponseInfo{IP: ip, Latency: "error", Content: ""} return } + defer resp.Body.Close() + + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + results <- ResponseInfo{IP: ip, Latency: "error", Content: ""} + return + } + bodyString := string(bodyBytes) + + latency := fmt.Sprintf("%.2f", float64(time.Since(start))/float64(time.Millisecond)) + results <- ResponseInfo{IP: ip, Latency: latency, Content: bodyString} } diff --git a/util/latency_test.go b/util/latency_test.go index 4d5f85a..e7088f6 100644 --- a/util/latency_test.go +++ b/util/latency_test.go @@ -1,9 +1,6 @@ package util -import ( - "testing" -) - -func TestGetFastIP(t *testing.T) { - GetFastIP("api.leo.moe", "443", true) -} +//github action test 不支持v6 这里会报错 +//func TestGetFastIP(t *testing.T) { +// GetFastIP("api.leo.moe", "443", true) +//} diff --git a/util/util.go b/util/util.go index 35e0908..6af2960 100644 --- a/util/util.go +++ b/util/util.go @@ -154,6 +154,10 @@ func DomainLookUp(host string, ipVersion string, dotServer string, disableOutput func GetenvDefault(key, defVal string) string { val, ok := os.LookupEnv(key) if ok { + _, ok := os.LookupEnv("NEXTTRACE_DEBUG") + if ok { + fmt.Println("ENV", key, "detected as", val) + } return val } return defVal diff --git a/wshandle/client.go b/wshandle/client.go index de7dc58..f5a6dfd 100644 --- a/wshandle/client.go +++ b/wshandle/client.go @@ -187,6 +187,7 @@ func createWsConn() *WsConn { host, port = util.GetHostAndPort() // 如果 host 是一个 IP 使用默认域名 if valid := net.ParseIP(host); valid != nil { + fastIp = host host = "api.leo.moe" } else { // 默认配置完成,开始寻找最优 IP