Browse Source

implement maximum reconnect

multi-tenant
forest 2 months ago
parent
commit
a3362a19df
3 changed files with 46 additions and 16 deletions
  1. +42
    -14
      main_client.go
  2. +3
    -1
      tunnel-lib/client.go
  3. +1
    -1
      tunnel-lib/util.go

+ 42
- 14
main_client.go View File

@ -34,20 +34,21 @@ import (
)
type ClientConfig struct {
DebugLog bool
ClientId string
GreenhouseDomain string
GreenhouseAPIToken string
GreenhouseThresholdPort int
ServerAddr string
Servers []string
DefaultTunnels *LiveConfigUpdate
CaCertificateFilesGlob string
ClientTlsKeyFile string
ClientTlsCertificateFile string
CaCertificate string
ClientTlsKey string
ClientTlsCertificate string
DebugLog bool
ClientId string
GreenhouseDomain string
GreenhouseAPIToken string
GreenhouseThresholdPort int
MaximumConnectionRetrySeconds int
ServerAddr string
Servers []string
DefaultTunnels *LiveConfigUpdate
CaCertificateFilesGlob string
ClientTlsKeyFile string
ClientTlsCertificateFile string
CaCertificate string
ClientTlsKey string
ClientTlsCertificate string
// use this when a local proxy is required to talk to the threshold server.
// if you set the hostname to "gateway", like "LocalSOCKS5Address": "gateway:1080"
@ -77,6 +78,23 @@ type ThresholdTenantInfo struct {
ThresholdServers []string
}
type maximumBackoff struct {
Maximum time.Duration
Base tunnel.Backoff
}
func (bo *maximumBackoff) NextBackOff() time.Duration {
result := bo.Base.NextBackOff()
if result > bo.Maximum {
return bo.Maximum
}
return result
}
func (bo *maximumBackoff) Reset() {
bo.Base.Reset()
}
type clientAdminAPI struct{}
// Client State
@ -356,7 +374,16 @@ func runClient(configFileName *string) {
}
}
maximumConnectionRetrySeconds := 60
if config.MaximumConnectionRetrySeconds != 0 {
maximumConnectionRetrySeconds = config.MaximumConnectionRetrySeconds
}
for _, server := range clientServers {
// make a separate backoff instance for each server.
myBackoff := maximumBackoff{
Maximum: time.Second * time.Duration(maximumConnectionRetrySeconds),
Base: tunnel.NewExponentialBackoff(),
}
clientStateChanges := make(chan *tunnel.ClientStateChange)
tunnelClientConfig := &tunnel.ClientConfig{
DebugLog: config.DebugLog,
@ -366,6 +393,7 @@ func runClient(configFileName *string) {
Proxy: proxyFunc,
Dial: dialFunction,
StateChanges: clientStateChanges,
Backoff: &myBackoff,
}
client, err := tunnel.NewClient(tunnelClientConfig)


+ 3
- 1
tunnel-lib/client.go View File

@ -202,9 +202,11 @@ func NewClient(cfg *ClientConfig) (*Client, error) {
proxy = (&TCPProxy{FetchLocalAddr: cfg.FetchLocalAddr, DebugLog: cfg.DebugLog}).Proxy
}
var bo Backoff = newForeverBackoff()
var bo Backoff
if cfg.Backoff != nil {
bo = cfg.Backoff
} else {
bo = NewExponentialBackoff()
}
client := &Client{


+ 1
- 1
tunnel-lib/util.go View File

@ -33,7 +33,7 @@ type expBackoff struct {
bk *backoff.ExponentialBackOff
}
func newForeverBackoff() *expBackoff {
func NewExponentialBackoff() *expBackoff {
eb := &expBackoff{
bk: backoff.NewExponentialBackOff(),
}


Loading…
Cancel
Save