diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-05-13 11:01:57 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-05-13 11:01:57 +0100 |
| commit | e0b1bbb42f88a165965a340e614db6e86f66b8a6 (patch) | |
| tree | 7d88c0534c83a368463fbcf4d724012e871d4b00 /internal/clients/remote | |
| parent | 1c56e05adcdd8846708557d631dfb6f73bc26db0 (diff) | |
refactor
Diffstat (limited to 'internal/clients/remote')
| -rw-r--r-- | internal/clients/remote/connection.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/internal/clients/remote/connection.go b/internal/clients/remote/connection.go index 5941115..2d97d14 100644 --- a/internal/clients/remote/connection.go +++ b/internal/clients/remote/connection.go @@ -93,31 +93,31 @@ func (c *Connection) initServerPort(server string) { // Start the server connection. Build up SSH session and send some DTail commands. func (c *Connection) Start(ctx context.Context, cancel context.CancelFunc, throttleCh, statsCh chan struct{}) { // Throttle how many connections can be established concurrently (based on ch length) - logger.Debug("Throttling connection", len(throttleCh), cap(throttleCh)) + logger.Debug(c.Server, "Throttling connection", len(throttleCh), cap(throttleCh)) select { case throttleCh <- struct{}{}: case <-ctx.Done(): - logger.Debug("Not establishing connection as context is done", len(throttleCh), cap(throttleCh), c.Server) + logger.Debug(c.Server, "Not establishing connection as context is done", len(throttleCh), cap(throttleCh)) return } - logger.Debug("Throttling says that the connection can be established", len(throttleCh), cap(throttleCh), c.Server) + logger.Debug(c.Server, "Throttling says that the connection can be established", len(throttleCh), cap(throttleCh)) go func() { defer func() { if !c.throttlingDone { - logger.Debug("Unthrottling connection (1)", len(throttleCh), cap(throttleCh), c.Server) + logger.Debug(c.Server, "Unthrottling connection (1)", len(throttleCh), cap(throttleCh)) c.throttlingDone = true <-throttleCh } cancel() }() - if err := c.dial(ctx, cancel, c.Server, c.port, throttleCh, statsCh); err != nil { + if err := c.dial(ctx, cancel, throttleCh, statsCh); err != nil { logger.Warn(c.Server, c.port, err) if c.hostKeyCallback.Untrusted(fmt.Sprintf("%s:%d", c.Server, c.port)) { - logger.Debug("Not trusting host", c.Server, c.port) + logger.Debug(c.Server, "Not trusting host") } } }() @@ -126,16 +126,16 @@ func (c *Connection) Start(ctx context.Context, cancel context.CancelFunc, throt } // Dail into a new SSH connection. Close connection in case of an error. -func (c *Connection) dial(ctx context.Context, cancel context.CancelFunc, host string, port int, throttleCh, statsCh chan struct{}) error { - logger.Debug("Incrementing connection stats", host) +func (c *Connection) dial(ctx context.Context, cancel context.CancelFunc, throttleCh, statsCh chan struct{}) error { + logger.Debug(c.Server, "Incrementing connection stats") statsCh <- struct{}{} defer func() { - logger.Debug("Decrementing connection stats", host) + logger.Debug(c.Server, "Decrementing connection stats") <-statsCh }() - logger.Debug("Dialing into the connection", host) - address := fmt.Sprintf("%s:%d", host, port) + logger.Debug(c.Server, "Dialing into the connection") + address := fmt.Sprintf("%s:%d", c.Server, c.port) client, err := ssh.Dial("tcp", address, c.config) if err != nil { @@ -201,7 +201,7 @@ func (c *Connection) handle(ctx context.Context, cancel context.CancelFunc, sess } if !c.throttlingDone { - logger.Debug("Unthrottling connection (2)", len(throttleCh), cap(throttleCh), c.Server) + logger.Debug(c.Server, "Unthrottling connection (2)", len(throttleCh), cap(throttleCh)) c.throttlingDone = true <-throttleCh } |
