Compare commits
1 Commits
9186173322
...
501ba87c2d
Author | SHA1 | Date |
---|---|---|
wpetit | 501ba87c2d |
|
@ -2,6 +2,7 @@ package tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -19,7 +20,6 @@ type RemoteClient struct {
|
||||||
onClientAuthHook OnClientAuthHook
|
onClientAuthHook OnClientAuthHook
|
||||||
onClientConnectHook OnClientConnectHook
|
onClientConnectHook OnClientConnectHook
|
||||||
onClientDisconnectHook OnClientDisconnectHook
|
onClientDisconnectHook OnClientDisconnectHook
|
||||||
conn net.Conn
|
|
||||||
sess *smux.Session
|
sess *smux.Session
|
||||||
control *control.Control
|
control *control.Control
|
||||||
remoteAddr net.Addr
|
remoteAddr net.Addr
|
||||||
|
@ -33,21 +33,38 @@ func (c *RemoteClient) Accept(ctx context.Context, conn *kcp.UDPSession) error {
|
||||||
config.KeepAliveInterval = 10 * time.Second
|
config.KeepAliveInterval = 10 * time.Second
|
||||||
config.KeepAliveTimeout = 2 * config.KeepAliveInterval
|
config.KeepAliveTimeout = 2 * config.KeepAliveInterval
|
||||||
|
|
||||||
sess, err := smux.Server(conn, config)
|
var (
|
||||||
if err != nil {
|
sess *smux.Session
|
||||||
return errors.WithStack(err)
|
err error
|
||||||
}
|
ctrl *control.Control
|
||||||
|
)
|
||||||
|
|
||||||
control := control.New()
|
for {
|
||||||
|
logger.Debug(ctx, "creating server session")
|
||||||
|
|
||||||
if err := control.Init(ctx, sess, true); err != nil {
|
sess, err = smux.Server(conn, config)
|
||||||
return errors.WithStack(err)
|
if err != nil {
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrl = control.New()
|
||||||
|
|
||||||
|
err = ctrl.Init(ctx, sess, true)
|
||||||
|
|
||||||
|
if err != nil && errors.Is(err, io.ErrClosedPipe) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
c.sess = sess
|
c.sess = sess
|
||||||
c.remoteAddr = conn.RemoteAddr()
|
c.remoteAddr = conn.RemoteAddr()
|
||||||
c.control = control
|
c.control = ctrl
|
||||||
c.conn = conn
|
|
||||||
|
|
||||||
if c.onClientConnectHook != nil {
|
if c.onClientConnectHook != nil {
|
||||||
if err := c.onClientConnectHook.OnClientConnect(ctx, c); err != nil {
|
if err := c.onClientConnectHook.OnClientConnect(ctx, c); err != nil {
|
||||||
|
@ -101,12 +118,7 @@ func (c *RemoteClient) Close() {
|
||||||
c.sess.Close()
|
c.sess.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.conn != nil {
|
|
||||||
c.conn.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
c.sess = nil
|
c.sess = nil
|
||||||
c.conn = nil
|
|
||||||
c.control = nil
|
c.control = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue