From 31dadf302634268a7fcc765bc389f65258a37a73 Mon Sep 17 00:00:00 2001 From: Myles Horton Date: Mon, 17 Aug 2015 12:30:26 -0700 Subject: [PATCH] Adding chained server info to error logs closes #2960 --- src/github.com/getlantern/balancer/balancer.go | 5 +++-- src/github.com/getlantern/chained/dialer.go | 5 ++++- .../getlantern/flashlight/client/chained.go | 16 +++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/github.com/getlantern/balancer/balancer.go b/src/github.com/getlantern/balancer/balancer.go index e90db9565b..be2956c6bd 100644 --- a/src/github.com/getlantern/balancer/balancer.go +++ b/src/github.com/getlantern/balancer/balancer.go @@ -94,12 +94,13 @@ func (b *Balancer) DialQOS(network, addr string, targetQOS int) (net.Conn, error } log.Debugf("Dialing %s://%s with %s", network, addr, d.Label) conn, err := d.Dial(network, addr) + if err != nil { - log.Errorf("Unable to dial %s://%s: %v on pass %v...continuing", network, addr, err, i) + log.Errorf("Unable to dial via %v to %s://%s: %v on pass %v...continuing", d.Label, network, addr, err, i) d.onError(err) continue } - log.Debugf("Successfully dialed to %v://%v on pass %v", network, addr, i) + log.Debugf("Successfully dialed via %v to %v://%v on pass %v", d.Label, network, addr, i) return conn, nil } } diff --git a/src/github.com/getlantern/chained/dialer.go b/src/github.com/getlantern/chained/dialer.go index c73d22afcc..b3d6a713bd 100644 --- a/src/github.com/getlantern/chained/dialer.go +++ b/src/github.com/getlantern/chained/dialer.go @@ -19,6 +19,9 @@ type Config struct { // the server and is allowed to modify the http.Request before it passes to // the server. OnRequest func(req *http.Request) + + // Label: a optional label for debugging. + Label string } // dialer is an implementation of proxy.Dialer that proxies traffic via an @@ -38,7 +41,7 @@ func NewDialer(cfg Config) proxy.Dialer { func (d *dialer) Dial(network, addr string) (net.Conn, error) { conn, err := d.DialServer() if err != nil { - return nil, fmt.Errorf("Unable to dial server: %s", err) + return nil, fmt.Errorf("Unable to dial server %v: %s", d.Label, err) } if err := d.sendCONNECT(network, addr, conn); err != nil { // We discard this error, since we are only interested in sendCONNECT diff --git a/src/github.com/getlantern/flashlight/client/chained.go b/src/github.com/getlantern/flashlight/client/chained.go index dd4582dd51..e9e589a527 100644 --- a/src/github.com/getlantern/flashlight/client/chained.go +++ b/src/github.com/getlantern/flashlight/client/chained.go @@ -75,8 +75,16 @@ func (s *ChainedServerInfo) Dialer() (*balancer.Dialer, error) { } } + // Is this a trusted proxy that we could use for HTTP traffic? + var trusted string + if s.Trusted { + trusted = "(trusted) " + } + label := fmt.Sprintf("%schained proxy at %s", trusted, s.Addr) + ccfg := chained.Config{ DialServer: dial, + Label: label, } if s.AuthToken != "" { ccfg.OnRequest = func(req *http.Request) { @@ -85,14 +93,8 @@ func (s *ChainedServerInfo) Dialer() (*balancer.Dialer, error) { } d := chained.NewDialer(ccfg) - // Is this a trusted proxy that we could use for HTTP traffic? - var trusted string - if s.Trusted { - trusted = "(trusted) " - } - return &balancer.Dialer{ - Label: fmt.Sprintf("%schained proxy at %s", trusted, s.Addr), + Label: label, Weight: s.Weight, QOS: s.QOS, Trusted: s.Trusted,