Skip to content

Commit f774c0d

Browse files
authored
Merge pull request #285 from nxtrace/main
SYNC
2 parents 5cc0815 + 69588b0 commit f774c0d

File tree

9 files changed

+67
-78
lines changed

9 files changed

+67
-78
lines changed

.cross_compile.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ for pl in ${PLATFORMS}; do
2929
-ldflags "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
3030
-X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
3131
-X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
32-
-w -s"
32+
-w -s -checklinkname=0"
3333
else
3434
go build -trimpath -o ${TARGET} \
3535
-ldflags "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
3636
-X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
3737
-X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
38-
-w -s"
38+
-w -s -checklinkname=0"
3939
fi
4040
done
4141
export CGO_ENABLED=0
@@ -49,13 +49,13 @@ done
4949
-ldflags "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
5050
-X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
5151
-X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
52-
-w -s"
52+
-w -s -checklinkname=0"
5353
else
5454
go build -trimpath -o ${TARGET} \
5555
-ldflags "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
5656
-X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
5757
-X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
58-
-w -s"
58+
-w -s -checklinkname=0"
5959
fi
6060

6161

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ jobs:
135135
- name: Set up Go
136136
uses: actions/setup-go@v5
137137
with:
138-
go-version: '1.22'
138+
go-version: '1.23'
139139
- name: Get project dependencies
140140
run: go mod download
141141
- name: Build
@@ -144,7 +144,7 @@ jobs:
144144
-ldflags "-X 'github.com/nxtrace/NTrace-core/config.Version=${BUILD_VERSION}' \
145145
-X 'github.com/nxtrace/NTrace-core/config.BuildDate=${BUILD_DATE}' \
146146
-X 'github.com/nxtrace/NTrace-core/config.CommitID=${COMMIT_SHA1}'\
147-
-w -s"
147+
-checklinkname=0 -w -s"
148148
- name: Upload files to Artifacts
149149
uses: actions/upload-artifact@v4
150150
with:

.github/workflows/test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ jobs:
3131
- name: Set up Go
3232
uses: actions/setup-go@v5
3333
with:
34-
go-version: '1.22'
34+
go-version: '1.23'
3535
- name: Checkout codebase
3636
uses: actions/checkout@v4
3737
- name: Test with unix
3838
if: ${{ matrix.os != 'windows-latest' }}
39-
run: sudo go test -v -coverprofile='coverage.out' -covermode=count ./...
39+
run: sudo go test -v -ldflags=-checklinkname=0 -coverprofile='coverage.out' -covermode=count ./...
4040
- name: Test with windows
4141
if: ${{ matrix.os == 'windows-latest' }}
42-
run: go test -v -coverprofile='coverage.out' -covermode=count ./...
42+
run: go test -v -ldflags=-checklinkname=0 -coverprofile='coverage.out' -covermode=count ./...

README.md

-15
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,6 @@ Please note, the repositories for all of the above installation methods are main
128128
* `Release` provides compiled binary executables for many systems and different architectures. If none are available, you can compile it yourself.
129129
* Some essential dependencies of this project are not fully implemented on `Windows` by `Golang`, so currently, `NextTrace` is in an experimental support phase on the `Windows` platform.
130130
131-
* Install from source
132-
133-
After installing Go >= 1.20 yourself, you can use the following command to install
134-
135-
```shell
136-
go install github.com/nxtrace/NTrace-core@latest
137-
```
138-
*because of the version constraints conflict, you can not install `NTrace-V1` by this*
139-
After installation, the executable is in the `$GOPATH/bin` directory. If you have not set `GOPATH`, it is in the `$HOME/go/bin` directory.
140-
The binary file name is consistent with the project name. You need to replace the `nexttrace` command below with `NTrace-core`.
141-
If you want to be consistent with the commands below, you can rename the binary after executing the `go install` command
142-
```shell
143-
mv $GOPATH/bin/NTrace-core $GOPATH/bin/nexttrace
144-
```
145-
146131
### Get Started
147132
148133
`NextTrace` uses the `ICMP` protocol to perform TraceRoute requests by default, which supports both `IPv4` and `IPv6`

README_zh_CN.md

-17
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,6 @@ Document Language: [English](README.md) | 简体中文
138138
* `Release`里面为很多系统以及不同架构提供了编译好的二进制可执行文件,如果没有可以自行编译。
139139
* 一些本项目的必要依赖在`Windows``Golang`底层实现不完全,所以目前`NextTrace``Windows`平台出于实验性支持阶段。
140140

141-
* 从源码安装
142-
143-
您可在自行安装Go >= 1.20后,使用以下命令安装
144-
145-
```shell
146-
go install github.com/nxtrace/NTrace-core@latest
147-
```
148-
*由于go.mod文件声明和文件目录冲突的问题,你不能用go install命令安装 `NTrace-V1` 版本*
149-
安装后可执行文件在`$GOPATH/bin`目录下,如果您没有设置`GOPATH`,则在`$HOME/go/bin`目录下。
150-
安装后二进制文件名称与项目名称保持一致,你需要将下文中的 `nexttrace` 命令替换为 `NTrace-core` 使用
151-
如果你希望与下文命令保持一致,可以在执行 `go install` 命令后重命名二进制文件
152-
153-
```shell
154-
mv $GOPATH/bin/NTrace-core $GOPATH/bin/nexttrace
155-
```
156-
157-
158141
### Get Started
159142

160143
`NextTrace` 默认使用`ICMP`协议发起`TraceRoute`请求,该协议同时支持`IPv4``IPv6`

go.mod

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/nxtrace/NTrace-core
22

3-
go 1.22.10
3+
go 1.23.4
44

55
require (
66
github.com/akamensky/argparse v1.4.0
@@ -10,7 +10,7 @@ require (
1010
github.com/stretchr/testify v1.10.0
1111
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635
1212
github.com/tsosunchia/powclient v0.1.5
13-
golang.org/x/net v0.33.0
13+
golang.org/x/net v0.34.0
1414
golang.org/x/sync v0.10.0
1515
)
1616

@@ -19,20 +19,20 @@ require (
1919
github.com/fsnotify/fsnotify v1.8.0 // indirect
2020
github.com/hashicorp/hcl v1.0.0 // indirect
2121
github.com/magiconair/properties v1.8.9 // indirect
22-
github.com/mattn/go-colorable v0.1.13 // indirect
22+
github.com/mattn/go-colorable v0.1.14 // indirect
2323
github.com/mattn/go-isatty v0.0.20 // indirect
2424
github.com/mitchellh/mapstructure v1.5.0 // indirect
2525
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
2626
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
27-
github.com/sagikazarmark/locafero v0.6.0 // indirect
27+
github.com/sagikazarmark/locafero v0.7.0 // indirect
2828
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
2929
github.com/sourcegraph/conc v0.3.0 // indirect
30-
github.com/spf13/afero v1.11.0 // indirect
30+
github.com/spf13/afero v1.12.0 // indirect
3131
github.com/spf13/cast v1.7.1 // indirect
3232
github.com/spf13/pflag v1.0.5 // indirect
3333
github.com/subosito/gotenv v1.6.0 // indirect
3434
go.uber.org/multierr v1.11.0 // indirect
35-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
35+
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
3636
golang.org/x/text v0.21.0 // indirect
3737
gopkg.in/ini.v1 v1.67.0 // indirect
3838
)
@@ -45,6 +45,6 @@ require (
4545
github.com/tidwall/gjson v1.18.0
4646
github.com/tidwall/match v1.1.1 // indirect
4747
github.com/tidwall/pretty v1.2.1 // indirect
48-
golang.org/x/sys v0.28.0 // indirect
48+
golang.org/x/sys v0.29.0 // indirect
4949
gopkg.in/yaml.v3 v3.0.1 // indirect
5050
)

go.sum

+12-14
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ github.com/lionsoul2014/ip2region v2.11.2+incompatible h1:+VRsGcrHz8ewXI/2UzTptJ
2626
github.com/lionsoul2014/ip2region v2.11.2+incompatible/go.mod h1:+ZBN7PBoh5gG6/y0ZQ85vJDBe21WnfbRrQQwTfliJJI=
2727
github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
2828
github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
29-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
30-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
31-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
29+
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
30+
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
3231
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
3332
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
3433
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
@@ -48,14 +47,14 @@ github.com/rodaine/table v1.3.0 h1:4/3S3SVkHnVZX91EHFvAMV7K42AnJ0XuymRR2C5HlGE=
4847
github.com/rodaine/table v1.3.0/go.mod h1:47zRsHar4zw0jgxGxL9YtFfs7EGN6B/TaS+/Dmk4WxU=
4948
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
5049
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
51-
github.com/sagikazarmark/locafero v0.6.0 h1:ON7AQg37yzcRPU69mt7gwhFEBwxI6P9T4Qu3N51bwOk=
52-
github.com/sagikazarmark/locafero v0.6.0/go.mod h1:77OmuIc6VTraTXKXIs/uvUxKGUXjE1GbemJYHqdNjX0=
50+
github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo=
51+
github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k=
5352
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
5453
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
5554
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
5655
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
57-
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
58-
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
56+
github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs=
57+
github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4=
5958
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
6059
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
6160
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
@@ -89,23 +88,22 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
8988
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
9089
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
9190
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
92-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo=
93-
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c=
91+
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 h1:yqrTHse8TCMW1M1ZCP+VAR/l0kKxwaAIqN/il7x4voA=
92+
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8/go.mod h1:tujkw807nyEEAamNbDrEGzRav+ilXA7PCRAd6xsmwiU=
9493
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
9594
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
9695
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
9796
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
98-
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
99-
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
97+
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
98+
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
10099
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
101100
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
102101
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
103102
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
104103
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
105-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
106104
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
107-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
108-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
105+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
106+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
109107
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
110108
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
111109
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=

pow/pow.go

+29-13
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@ import (
66
"github.com/tsosunchia/powclient"
77
"net/url"
88
"os"
9+
"os/signal"
10+
"syscall"
11+
"time"
912
)
1013

1114
const (
1215
baseURL = "/v3/challenge"
1316
)
1417

1518
func GetToken(fastIp string, host string, port string) (string, error) {
19+
// 捕获中断信号
20+
sigChan := make(chan os.Signal, 1)
21+
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
1622
getTokenParams := powclient.NewGetTokenParams()
1723
u := url.URL{Scheme: "https", Host: fastIp + ":" + port, Path: baseURL}
1824
getTokenParams.BaseUrl = u.String()
@@ -26,20 +32,30 @@ func GetToken(fastIp string, host string, port string) (string, error) {
2632
var (
2733
token string
2834
err error
35+
done = make(chan bool)
2936
)
30-
// 尝试三次RetToken,如果都失败了,异常退出
31-
for i := 0; i < 3; i++ {
32-
token, err = powclient.RetToken(getTokenParams)
33-
if err != nil {
34-
continue
37+
// 在 goroutine 中处理阻塞调用
38+
go func() {
39+
for i := 0; i < 3; i++ {
40+
token, err = powclient.RetToken(getTokenParams)
41+
if err != nil {
42+
continue // 如果失败则重试
43+
}
44+
done <- true // 成功后通知主线程
45+
return
3546
}
36-
//fmt.Println("GetToken success", token, getTokenParams.UserAgent)
37-
return token, nil
38-
}
39-
if err != nil {
40-
fmt.Println(err)
47+
done <- false // 失败后通知主线程
48+
}()
49+
50+
select {
51+
case <-sigChan: // 监听中断信号
52+
return "", fmt.Errorf("Program interrupted by user ") // 添加返回值
53+
case success := <-done: // 等待 goroutine 完成
54+
if success {
55+
return token, nil
56+
}
57+
return "", fmt.Errorf("RetToken failed 3 times, please try again later")
58+
case <-time.After(10 * time.Second): // 超时处理
59+
return "", fmt.Errorf("RetToken timed out(10s), please check your network") // 添加返回值
4160
}
42-
fmt.Println("RetToken failed 3 times, please try again after a while, exit")
43-
os.Exit(1)
44-
return "", err
4561
}

util/latency.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"log"
88
"net"
99
"net/http"
10+
"os"
11+
"os/signal"
1012
"strings"
1113
"time"
1214

@@ -57,12 +59,17 @@ func GetFastIP(domain string, port string, enableOutput bool) string {
5759

5860
var result ResponseInfo
5961

62+
sigChan := make(chan os.Signal, 1)
63+
signal.Notify(sigChan, os.Interrupt)
64+
6065
select {
6166
case result = <-results:
62-
//等待5s没有结果 视为连不上API了
67+
// 正常返回结果
6368
case <-time.After(timeout):
64-
log.Println("IP connection has been timeout, please check your network")
65-
69+
log.Println("IP connection has been timeout(5s), please check your network")
70+
case <-sigChan: // 响应中断信号
71+
log.Println("Program interrupted by user")
72+
os.Exit(0)
6673
}
6774

6875
//if len(ips) > 0 {

0 commit comments

Comments
 (0)