mirror of
https://github.com/xmdhs/natupnp.git
synced 2025-10-27 17:10:23 +08:00
fix
This commit is contained in:
31
main.go
31
main.go
@@ -50,21 +50,24 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if target != "" {
|
||||
err := natmap.Forward(ctx, uint16(portu), target, func(s string) {
|
||||
log.Println(s)
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
if test {
|
||||
testServer(port)
|
||||
}
|
||||
|
||||
m, s, err := natmap.NatMap(ctx, "stun.sipnet.com:3478", localAddr, uint16(portu), func(s string) {
|
||||
m, s, err := natmap.NatMap(ctx, stun, localAddr, uint16(portu), func(s string) {
|
||||
log.Println(s)
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if test {
|
||||
go testServer(port)
|
||||
}
|
||||
if target != "" {
|
||||
go natmap.Forward(ctx, uint16(portu), target, func(s string) {
|
||||
log.Println(s)
|
||||
})
|
||||
}
|
||||
|
||||
defer m.Close()
|
||||
fmt.Println(s)
|
||||
@@ -84,8 +87,10 @@ func testServer(port string) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = s.Serve(l)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
err = s.Serve(l)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -97,7 +97,10 @@ func Forward(ctx context.Context, port uint16, target string, log func(string))
|
||||
go io.Copy(c, tc)
|
||||
go io.Copy(tc, c)
|
||||
}
|
||||
for {
|
||||
f()
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
f()
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -83,11 +83,11 @@ func pickRouterClient(ctx context.Context) ([]routerClient, error) {
|
||||
}
|
||||
|
||||
switch {
|
||||
case len(ip2Clients) > 1:
|
||||
case len(ip2Clients) >= 1:
|
||||
return any2slice[routerClient](ip2Clients), nil
|
||||
case len(ip1Clients) > 1:
|
||||
case len(ip1Clients) >= 1:
|
||||
return any2slice[routerClient](ip1Clients), nil
|
||||
case len(ppp1Clients) > 1:
|
||||
case len(ppp1Clients) >= 1:
|
||||
return any2slice[routerClient](ppp1Clients), nil
|
||||
default:
|
||||
return nil, nil
|
||||
|
||||
Reference in New Issue
Block a user