mirror of
https://github.com/xtaci/kcptun.git
synced 2024-04-21 12:32:32 +00:00
upd test
This commit is contained in:
+2
-2
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/xtaci/tcpraw"
|
||||
)
|
||||
|
||||
var dialCount int
|
||||
var dialCount uint64
|
||||
|
||||
func dial(config *Config, block kcp.BlockCrypt) (*kcp.UDPSession, error) {
|
||||
defer func() {
|
||||
@@ -38,7 +38,7 @@ func dial(config *Config, block kcp.BlockCrypt) (*kcp.UDPSession, error) {
|
||||
}
|
||||
|
||||
// assign remote addr
|
||||
remoteAddr = fmt.Sprintf("%v:%v", matches[1], minPort+dialCount%(maxPort-minPort+1))
|
||||
remoteAddr = fmt.Sprintf("%v:%v", matches[1], uint64(minPort)+dialCount%uint64(maxPort-minPort+1))
|
||||
}
|
||||
|
||||
if config.TCP {
|
||||
|
||||
+23
-6
@@ -3,19 +3,36 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDial(t *testing.T) {
|
||||
reg := regexp.MustCompile(`(.*)\:([0-9]{1,5})-?([0-9]{1,5})?`)
|
||||
strs := reg.FindStringSubmatch("0.0.0.0:20000-21000")
|
||||
for i := 0; i < len(strs); i++ {
|
||||
fmt.Println(strs[i])
|
||||
matches := reg.FindStringSubmatch("www.unknown.unknown:20000-21000")
|
||||
for i := 0; i < len(matches); i++ {
|
||||
fmt.Println(matches[i])
|
||||
}
|
||||
|
||||
strs = reg.FindStringSubmatch("0.0.0.0:20000")
|
||||
for i := 0; i < len(strs); i++ {
|
||||
fmt.Println(strs[i])
|
||||
minPort, err := strconv.Atoi(matches[2])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
maxPort, err := strconv.Atoi(matches[3])
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
t.Log("minport:", minPort)
|
||||
t.Log("maxport:", maxPort)
|
||||
|
||||
remoteAddr := fmt.Sprintf("%v:%v", matches[1], uint64(minPort)+dialCount%uint64(maxPort-minPort+1))
|
||||
|
||||
t.Log("RemoteAddr:", remoteAddr)
|
||||
|
||||
testcase2 := "1.2.3.4:20000"
|
||||
matches = reg.FindStringSubmatch(testcase2)
|
||||
for i := 0; i < len(matches); i++ {
|
||||
t.Log(testcase2, "submatch", i, matches[i])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user