Skip to content

Commit

Permalink
Adding chained server info to error logs closes #2960
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Aug 17, 2015
1 parent fa2139c commit 31dadf3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/github.com/getlantern/balancer/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/github.com/getlantern/chained/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/github.com/getlantern/flashlight/client/chained.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand Down

0 comments on commit 31dadf3

Please sign in to comment.