@@ -10,6 +10,7 @@ import (
1010
1111 "github.com/Jigsaw-Code/outline-sdk/transport"
1212 "github.com/Jigsaw-Code/outline-sdk/x/smart"
13+ "github.com/getlantern/flashlight/v7/ops"
1314)
1415
1516type proxyless interface {
@@ -53,6 +54,8 @@ func NewProxylessDialer() Dialer {
5354
5455// DialContext dials out to the domain or IP address representing a destination site.
5556func (d * proxylessDialer ) DialContext (ctx context.Context , network , address string ) (net.Conn , error ) {
57+ op := ops .Begin ("proxyless_dialer" )
58+ defer op .End ()
5659 deadline , _ := ctx .Deadline ()
5760 log .Debugf ("Time remaining: %v for ctx: %v" , time .Until (deadline ), ctx .Err ())
5861
@@ -67,46 +70,51 @@ func (d *proxylessDialer) DialContext(ctx context.Context, network, address stri
6770 // The smart dialer requires the port to be specified, so we add it if it's
6871 // missing. We can't do this in the dialer itself because the scheme
6972 // is stripped by the time the dialer is called.
70- addr , host , err := normalizeAddrHost (address )
73+ addr , domain , err := normalizeAddrHost (address )
7174 if err != nil {
7275 log .Errorf ("Failed to normalize address: %v" , err )
76+ op .FailIf (err )
7377 return nil , err
7478 }
75- dialer , err := d .getOrCreateDialer (ctx , host , addr )
79+ dialer , err := d .getOrCreateDialer (ctx , domain , op )
7680 if err != nil {
77- d .onFailure (host , err )
81+ d .onFailure (domain , err )
82+ op .FailIf (err )
7883 return nil , fmt .Errorf ("failed to create smart dialer: %v" , err )
7984 }
8085
8186 // Store the dialer in the map right away so that we can use it for future requests.
8287 // If the dialer fails, we'll store a failing dialer in the map.
83- d .onSuccess (host , dialer )
88+ d .onSuccess (domain , dialer )
8489 streamConn , err := dialer .DialStream (ctx , addr )
8590 if err != nil {
8691 log .Errorf ("❌ Failed to dial stream for %s: %v" , address , err )
87- d .onFailure (host , err )
88- return nil , fmt .Errorf ("failed to dial stream with new dialer: %v" , err )
92+ dialErr := fmt .Errorf ("failed to dial stream with proxyless dialer: %v" , err )
93+ d .onFailure (domain , dialErr )
94+ op .FailIf (dialErr )
95+ return nil , dialErr
8996 }
9097 log .Debugf ("✅ Successfully dialed proxyless to %s" , address )
9198 return streamConn , nil
9299}
93100
94101// getOrCreateDialer gets or creates a dialer for the given host.
95102// If a dialer already exists, it returns the existing one.
96- func (d * proxylessDialer ) getOrCreateDialer (ctx context.Context , host , addr string ) (transport.StreamDialer , error ) {
103+ func (d * proxylessDialer ) getOrCreateDialer (ctx context.Context , domain string , op * ops. Op ) (transport.StreamDialer , error ) {
97104 // Check if we already have a dialer for this host
98- if dialer , ok := successfulDialers .Load (host ); ok {
99- log .Debugf ("Using existing dialer for host: %s" , host )
105+ if dialer , ok := successfulDialers .Load (domain ); ok {
106+ log .Debugf ("Using existing dialer for domain: %s" , domain )
107+ op .Set ("status" , "existing" )
100108 return dialer .(transport.StreamDialer ), nil
101109 }
102110
103- // Create a new dialer
104- domains := []string {host }
105- dialer , err := d .newDialer (ctx , domains , d .configBytes )
111+ op .Set ("status" , "new" )
112+ dialer , err := d .newDialer (ctx , []string {domain }, d .configBytes )
106113 if err != nil {
107- log .Errorf ("❌ Failed to create smart dialer for %v: %v" , host , err )
114+ log .Errorf ("❌ Failed to create smart dialer for %v: %v" , domain , err )
108115 return nil , err
109116 }
117+ log .Debugf ("✅ Successfully created smart dialer to %s" , domain )
110118 return dialer , nil
111119}
112120
0 commit comments