mirror of https://github.com/cbeuw/Cloak
Make keepalive optional on client -> server and server -> proxy connections. Use KeepAlive value in config (seconds).
This commit is contained in:
parent
6b973045d5
commit
2de034ec92
|
|
@ -23,7 +23,7 @@ import (
|
|||
var version string
|
||||
|
||||
func makeSession(sta *client.State, isAdmin bool) *mux.Session {
|
||||
log.Info("Attemtping to start a new session")
|
||||
log.Info("Attempting to start a new session")
|
||||
if !isAdmin {
|
||||
// sessionID is usergenerated. There shouldn't be a security concern because the scope of
|
||||
// sessionID is limited to its UID.
|
||||
|
|
@ -32,7 +32,7 @@ func makeSession(sta *client.State, isAdmin bool) *mux.Session {
|
|||
atomic.StoreUint32(&sta.SessionID, binary.BigEndian.Uint32(quad))
|
||||
}
|
||||
|
||||
d := net.Dialer{Control: protector}
|
||||
d := net.Dialer{Control: protector, KeepAlive: sta.KeepAlive}
|
||||
connsCh := make(chan net.Conn, sta.NumConn)
|
||||
var _sessionKey atomic.Value
|
||||
var wg sync.WaitGroup
|
||||
|
|
|
|||
|
|
@ -174,7 +174,8 @@ func dispatchConnection(conn net.Conn, sta *server.State) {
|
|||
}
|
||||
}
|
||||
proxyAddr := sta.ProxyBook[ci.ProxyMethod]
|
||||
localConn, err := net.Dial(proxyAddr.Network(), proxyAddr.String())
|
||||
d := net.Dialer{KeepAlive: sta.KeepAlive}
|
||||
localConn, err := d.Dial(proxyAddr.Network(), proxyAddr.String())
|
||||
if err != nil {
|
||||
log.Errorf("Failed to connect to %v: %v", ci.ProxyMethod, err)
|
||||
user.CloseSession(ci.SessionId, "Failed to connect to proxy server")
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type rawConfig struct {
|
|||
Transport string
|
||||
NumConn int
|
||||
StreamTimeout int
|
||||
KeepAlive int
|
||||
RemoteHost string
|
||||
RemotePort int
|
||||
}
|
||||
|
|
@ -50,6 +51,7 @@ type State struct {
|
|||
ServerName string
|
||||
NumConn int
|
||||
Timeout time.Duration
|
||||
KeepAlive time.Duration
|
||||
}
|
||||
|
||||
// semi-colon separated value. This is for Android plugin options
|
||||
|
|
@ -138,6 +140,11 @@ func (sta *State) ParseConfig(conf string) (err error) {
|
|||
} else {
|
||||
sta.Timeout = time.Duration(preParse.StreamTimeout) * time.Second
|
||||
}
|
||||
if preParse.KeepAlive <= 0 {
|
||||
sta.KeepAlive = -1
|
||||
} else {
|
||||
sta.KeepAlive = time.Duration(preParse.KeepAlive) * time.Second
|
||||
}
|
||||
sta.UID = preParse.UID
|
||||
|
||||
pub, ok := ecdh.Unmarshal(preParse.PublicKey)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ type rawConfig struct {
|
|||
AdminUID []byte
|
||||
DatabasePath string
|
||||
StreamTimeout int
|
||||
KeepAlive int
|
||||
CncMode bool
|
||||
}
|
||||
|
||||
|
|
@ -35,6 +36,7 @@ type State struct {
|
|||
Now func() time.Time
|
||||
AdminUID []byte
|
||||
Timeout time.Duration
|
||||
KeepAlive time.Duration
|
||||
|
||||
BypassUID map[[16]byte]struct{}
|
||||
staticPv crypto.PrivateKey
|
||||
|
|
@ -173,6 +175,12 @@ func (sta *State) ParseConfig(conf string) (err error) {
|
|||
sta.Timeout = time.Duration(preParse.StreamTimeout) * time.Second
|
||||
}
|
||||
|
||||
if preParse.KeepAlive <= 0 {
|
||||
sta.KeepAlive = -1
|
||||
} else {
|
||||
sta.KeepAlive = time.Duration(preParse.KeepAlive) * time.Second
|
||||
}
|
||||
|
||||
sta.RedirHost, sta.RedirPort, err = parseRedirAddr(preParse.RedirAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse RedirAddr: %v", err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue