1. 连接方式自适应,不手动配置,防止因为选错,反而导致无法连接成功

2. 端口号允许1-65535
This commit is contained in:
kony
2025-03-06 14:05:38 +08:00
parent d6ff0d85d6
commit 91e1960172
6 changed files with 60 additions and 28 deletions

View File

@@ -4,5 +4,5 @@ Website = "https://goodlink.kony.vip"
Icon = "theme/favicon.png"
Name = "goodlink-windows-amd64-ui"
ID = "goodlink.kony.vip"
Version = "1.5.30"
Build = 2
Version = "1.5.31"
Build = 9

View File

@@ -19,7 +19,7 @@ var (
m_local_state = 0 //0: 停止, 1: 启动, 2: 连接成功
)
func GetLocalQuicConn(conn *net.UDPConn, addr *tun.AddrType, conn_type int, count int) (*tun.TunActive, *tun.TunPassive, quic.Connection, quic.Stream, error) {
func GetLocalQuicConn(conn *net.UDPConn, addr *tun.AddrType, conn_type2 int, count int) (*tun.TunActive, *tun.TunPassive, quic.Connection, quic.Stream, error) {
var tun_active *tun.TunActive
var tun_passive *tun.TunPassive
@@ -32,6 +32,11 @@ func GetLocalQuicConn(conn *net.UDPConn, addr *tun.AddrType, conn_type int, coun
ConnectCount: count,
}
conn_type := 0 // 被动连接
if addr.WanPort1 == addr.WanPort2 {
conn_type = 1 // 主动连接
}
switch conn_type {
case 0:
utils.Log().Debug("请求连接对端")

View File

@@ -169,32 +169,48 @@ func getStunIpPort2(conn *net.UDPConn, addr string) (string, int, int, error) {
if err != nil {
return "", 0, 0, err
}
/*
var change_ip, wan_ip2 string
var change_port, wan_port2 int
var change_ip, wan_ip2 string
var change_port, wan_port2 int
change_ip, change_port, err = getStunIpPort4(response[20:], n, 0x0005, magicCookie, transactionID)
if err == nil {
response, n, err = getStunResponse(conn, fmt.Sprintf("%s:%d", change_ip, change_port), buf)
change_ip, change_port, err = getStunIpPort4(response[20:], n, 0x0005, magicCookie, transactionID)
if err == nil {
wan_ip2, wan_port2, err = getStunIpPort4(response[20:], n, 0x0001, magicCookie, transactionID)
if err != nil {
wan_ip2, wan_port2, err = getStunIpPort4(response[20:], n, 0x0020, magicCookie, transactionID)
}
response, n, err = getStunResponse(conn, fmt.Sprintf("%s:%d", change_ip, change_port), buf)
if err == nil {
if wan_ip1 != wan_ip2 {
utils.Log().ErrorF("wan_ip: %s, %s", wan_ip1, wan_ip2)
wan_ip2, wan_port2, err = getStunIpPort4(response[20:], n, 0x0001, magicCookie, transactionID)
if err != nil {
wan_ip2, wan_port2, err = getStunIpPort4(response[20:], n, 0x0020, magicCookie, transactionID)
}
if err == nil {
if wan_ip1 != wan_ip2 {
utils.Log().ErrorF("wan_ip: %s, %s", wan_ip1, wan_ip2)
}
return wan_ip1, wan_port1, wan_port2, nil
}
return wan_ip1, wan_port1, wan_port2, nil
}
return wan_ip1, wan_port1, 0, err
}
return wan_ip1, wan_port1, 0, err
}
*/
return wan_ip1, wan_port1, 0, nil
}
func GetWanIpPort2(conn *net.UDPConn) (string, int, int) {
func GetWanIpPort2(conn *net.UDPConn) (wan_ip string, wan_port1 int, wan_port2 int) {
utils.Log().Debug("获取本端地址")
for {
wan_ip, wan_port1, _, _ = getStunIpPort2(conn, "stun.easyvoip.com:3478")
time.Sleep(10 * time.Millisecond)
_, wan_port2, _, _ = getStunIpPort2(conn, "stun.easyvoip.com:3479")
if wan_port1 != 0 && wan_port2 != 0 {
break
}
time.Sleep(3 * time.Second)
}
return
}
func GetWanIpPort2_2(conn *net.UDPConn) (string, int, int) {
utils.Log().Debug("获取本端地址")
n2 := 0
@@ -238,6 +254,18 @@ func GetWanIpPort() (string, int, int) {
func TestStun() {
conn4, _ := net.ListenUDP("udp4", nil)
wan_ip, wan_port1, wan_port2, _ := getStunIpPort2(conn4, "stun.easyvoip.com:3478")
log.Printf("wan_ip: %s, wan_port1: %d, wan_port2: %d\n", wan_ip, wan_port1, wan_port2)
time.Sleep(10 * time.Millisecond)
wan_ip, wan_port1, wan_port2, _ = getStunIpPort2(conn4, "stun.easyvoip.com:3479")
log.Printf("wan_ip: %s, wan_port1: %d, wan_port2: %d\n", wan_ip, wan_port1, wan_port2)
time.Sleep(10 * time.Millisecond)
}
func TestStun2() {
conn4, _ := net.ListenUDP("udp4", nil)
for c := 0; c < 100; c++ {
log.Printf("c: %d", c)
for _, stun_svr := range config.GetConfig().StunList {

View File

@@ -53,8 +53,8 @@ func (c *LocalUI) GetLocalAddr() (string, error) {
func (c *LocalUI) GetContainer() *fyne.Container {
return container.NewVBox(
container.New(layout.NewFormLayout(), widget.NewRichTextWithText("连接方式: "), c.radio_conn_type),
container.New(layout.NewFormLayout(), widget.NewRichTextWithText("访问权限: "), c.radio1),
//container.New(layout.NewFormLayout(), widget.NewRichTextWithText("连接方式: "), c.radio_conn_type),
//container.New(layout.NewFormLayout(), widget.NewRichTextWithText("访问权限: "), c.radio1),
container.New(layout.NewFormLayout(), widget.NewRichTextWithText("访问端口: "), c.box_local_port),
)
}

View File

@@ -19,14 +19,14 @@ func (n *portEntry) Keyboard() mobile.KeyboardType {
}
func (n *portEntry) ResetPlaceHolder() {
n.SetPlaceHolder("范围: 1024-65535")
n.SetPlaceHolder("范围: 1-65535")
}
func NewPortEntry(port string) *portEntry {
e := &portEntry{}
e.ExtendBaseWidget(e)
e.Validator = func(port string) error {
if n, err := strconv.Atoi(port); err == nil && n >= 1024 && n <= 65535 {
if n, err := strconv.Atoi(port); err == nil && n >= 1 && n <= 65535 {
return nil
}
return errors.New("请输入正确的端口号")

View File

@@ -57,7 +57,6 @@ func start_button_click() {
var err error
var remote_addr string
var local_addr string
//先对需要填写的数据进行校验
switch m_stats_start_button {
@@ -68,8 +67,8 @@ func start_button_click() {
}
switch m_radio_work_type.Selected {
case "Local":
if local_addr, err = m_ui_local.GetLocalAddr(); err != nil {
SetLogLabel(err.Error())
if m_ui_local.GetLocalPort() == "" {
SetLogLabel("请填写访问端口号")
return
}
case "Remote":
@@ -143,7 +142,7 @@ func start_button_click() {
m_mg_start.Add(1)
go func() {
defer m_mg_start.Done()
if err := pro.RunLocal(m_ui_local.GetConnType(), local_addr, m_validated_key.Text); err != nil {
if err := pro.RunLocal(m_ui_local.GetConnType(), "0.0.0.0:"+m_ui_local.GetLocalPort(), m_validated_key.Text); err != nil {
SetLogLabel(err.Error())
}
m_stats_start_button = 0