Skip to content

Commit e726cd0

Browse files
release 1.0
1 parent 17eb9eb commit e726cd0

21 files changed

+536
-38
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
_*
3-
config.toml
3+
**/_*
4+
exec/*/config.toml
45
*.exe

api.ts renamed to exec/api.ts

File renamed without changes.
File renamed without changes.
File renamed without changes.

main.go renamed to exec/http/main.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io/ioutil"
1212
"log"
1313
"net/http"
14+
"network-measure/tool"
1415
"strconv"
1516
"time"
1617
)
@@ -67,7 +68,7 @@ func verifyStamp(c *gin.Context, timeStamp, nonce uint64) bool {
6768
}
6869

6970
func handleResolve(c *gin.Context) {
70-
var q ResolveQ
71+
var q tool.ResolveQ
7172
if err := binding.JSON.BindBody(c.Keys["body"].([]byte), &q); err != nil {
7273
_ = c.AbortWithError(http.StatusBadRequest, err).SetType(gin.ErrorTypeBind)
7374
return
@@ -77,7 +78,7 @@ func handleResolve(c *gin.Context) {
7778
return
7879
}
7980

80-
r, err := resolve(&q)
81+
r, err := tool.Resolve(&q)
8182
jsonResult(c, r, err)
8283

8384
if err == nil {
@@ -86,7 +87,7 @@ func handleResolve(c *gin.Context) {
8687
}
8788

8889
func handlePing(c *gin.Context) {
89-
var q PingQ
90+
var q tool.PingQ
9091
if err := binding.JSON.BindBody(c.Keys["body"].([]byte), &q); err != nil {
9192
_ = c.AbortWithError(http.StatusBadRequest, err).SetType(gin.ErrorTypeBind)
9293
return
@@ -96,7 +97,7 @@ func handlePing(c *gin.Context) {
9697
return
9798
}
9899

99-
r, err := ping(&q)
100+
r, err := tool.Ping(&q)
100101
jsonResult(c, r, err)
101102

102103
if err == nil {
@@ -105,13 +106,13 @@ func handlePing(c *gin.Context) {
105106
}
106107

107108
func handleTCPing(c *gin.Context) {
108-
var q TCPingQ
109+
var q tool.TCPingQ
109110
if err := binding.JSON.BindBody(c.Keys["body"].([]byte), &q); err != nil {
110111
_ = c.AbortWithError(http.StatusBadRequest, err).SetType(gin.ErrorTypeBind)
111112
return
112113
}
113114

114-
r, err := tcping(&q)
115+
r, err := tool.TCPing(&q)
115116
jsonResult(c, r, err)
116117

117118
if err == nil {
@@ -120,7 +121,7 @@ func handleTCPing(c *gin.Context) {
120121
}
121122

122123
func handleMTR(c *gin.Context) {
123-
var q MtrQ
124+
var q tool.MtrQ
124125
if err := binding.JSON.BindBody(c.Keys["body"].([]byte), &q); err != nil {
125126
_ = c.AbortWithError(http.StatusBadRequest, err).SetType(gin.ErrorTypeBind)
126127
return
@@ -130,7 +131,7 @@ func handleMTR(c *gin.Context) {
130131
return
131132
}
132133

133-
r, err := mtr(&q)
134+
r, err := tool.MTR(&q)
134135
jsonResult(c, r, err)
135136

136137
if err == nil {
@@ -139,7 +140,7 @@ func handleMTR(c *gin.Context) {
139140
}
140141

141142
func handleSpeed(c *gin.Context) {
142-
var q SpeedQ
143+
var q tool.SpeedQ
143144
if err := binding.JSON.BindBody(c.Keys["body"].([]byte), &q); err != nil {
144145
_ = c.AbortWithError(http.StatusBadRequest, err).SetType(gin.ErrorTypeBind)
145146
return
@@ -149,7 +150,7 @@ func handleSpeed(c *gin.Context) {
149150
return
150151
}
151152

152-
r, err := speed(&q)
153+
r, err := tool.Speed(&q)
153154
jsonResult(c, r, err)
154155

155156
if err == nil {
@@ -204,6 +205,15 @@ func limit(enable bool) gin.HandlerFunc {
204205
}
205206
}
206207

208+
//func _(c *gin.Context) {
209+
// fmt.Printf("[DBG] %v | %15s | %-7s %#v\n",
210+
// time.Now().Format("2006/01/02 - 15:04:05"),
211+
// c.ClientIP(),
212+
// c.Request.Method,
213+
// c.Request.URL.Path,
214+
// )
215+
//}
216+
207217
func main() {
208218
router := gin.Default()
209219
a := router.Group("/api", verify)

exec/ws/config.example.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[connection]
2+
# remote websocket endpoint
3+
remote = "ws://127.0.0.1:8081"
4+
# name for this instance
5+
name = "debug-client"
6+
# key used for verify this instance
7+
key = "keyusedforhmac"
8+
# retry times before give up
9+
retry = 10
10+
# the key used in SHA256-HMAC authentication
11+
key = "keyusedforhmac"
12+
13+
# Set corresponding item to false if you don't want to enable some test
14+
[api]
15+
resolve = true
16+
ping = true
17+
tcping = true
18+
mtr = true
19+
speed = true

exec/ws/config.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package main
2+
3+
type ConfigConn struct {
4+
Remote string `toml:"remote"`
5+
Name string `toml:"name"`
6+
Key string `toml:"key"`
7+
Retry uint32 `toml:"retry"`
8+
}
9+
10+
type ConfigAPI struct {
11+
Resolve bool `toml:"resolve"`
12+
Ping bool `toml:"ping"`
13+
TCPing bool `toml:"tcping"`
14+
MTR bool `toml:"mtr"`
15+
Speed bool `toml:"speed"`
16+
}
17+
18+
type Config struct {
19+
Conn ConfigConn `toml:"connection"`
20+
API ConfigAPI `toml:"api"`
21+
}
22+
23+
func (r *Config) SetDefault() {
24+
r.Conn.Remote = "ws://127.0.0.1:8080"
25+
r.Conn.Name = "debug-client"
26+
r.Conn.Retry = 10
27+
28+
r.API.Resolve = true
29+
r.API.Ping = true
30+
r.API.TCPing = true
31+
r.API.MTR = true
32+
r.API.Speed = true
33+
}

0 commit comments

Comments
 (0)