mirror of
https://github.com/xmdhs/natupnp.git
synced 2025-10-28 01:12:25 +08:00
fix
This commit is contained in:
31
main.go
31
main.go
@@ -50,21 +50,24 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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)
|
log.Println(s)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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()
|
defer m.Close()
|
||||||
fmt.Println(s)
|
fmt.Println(s)
|
||||||
@@ -84,8 +87,10 @@ func testServer(port string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
err = s.Serve(l)
|
go func() {
|
||||||
if err != nil {
|
err = s.Serve(l)
|
||||||
panic(err)
|
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(c, tc)
|
||||||
go io.Copy(tc, c)
|
go io.Copy(tc, c)
|
||||||
}
|
}
|
||||||
for {
|
go func() {
|
||||||
f()
|
for {
|
||||||
}
|
f()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,11 +83,11 @@ func pickRouterClient(ctx context.Context) ([]routerClient, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case len(ip2Clients) > 1:
|
case len(ip2Clients) >= 1:
|
||||||
return any2slice[routerClient](ip2Clients), nil
|
return any2slice[routerClient](ip2Clients), nil
|
||||||
case len(ip1Clients) > 1:
|
case len(ip1Clients) >= 1:
|
||||||
return any2slice[routerClient](ip1Clients), nil
|
return any2slice[routerClient](ip1Clients), nil
|
||||||
case len(ppp1Clients) > 1:
|
case len(ppp1Clients) >= 1:
|
||||||
return any2slice[routerClient](ppp1Clients), nil
|
return any2slice[routerClient](ppp1Clients), nil
|
||||||
default:
|
default:
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user