Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed May 28, 2024
1 parent 0e1ec02 commit c69e025
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions x/psiphon/psiphon.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package psiphon
import (
"context"
"encoding/json"
"errors"
"fmt"
"net"
"runtime"
Expand Down Expand Up @@ -62,6 +63,7 @@ func LoadConfig(configJSON []byte) (*Config, error) {
config.DisableLocalHTTPProxy = true
config.DisableLocalSocksProxy = true
config.ClientPlatform = fmt.Sprintf("OutlineSDK/%s/%s", runtime.GOOS, runtime.GOARCH)
// TODO(fortuna): Figure out a better way to do this to allow the user to override config options.
err = config.Commit(false)
if err != nil {
return nil, fmt.Errorf("config commit failed: %w", err)
Expand All @@ -73,7 +75,7 @@ func (cfg *Config) NewDialer(ctx context.Context) (*Dialer, error) {
// Will receive a value when the tunnel has successfully connected.
connected := make(chan struct{}, 1)
// Will receive a value if an error occurs during the connection sequence.
errored := make(chan error, 1)
errCh := make(chan error, 1)

// Set up NoticeWriter to receive events.
psi.SetNoticeWriter(psi.NewNoticeReceiver(
Expand All @@ -85,15 +87,15 @@ func (cfg *Config) NewDialer(ctx context.Context) (*Dialer, error) {
// We'll interpret it as a connection error and abort.
err = fmt.Errorf("failed to unmarshal notice JSON: %w", err)
select {
case errored <- err:
case errCh <- err:
default:
}
return
}
switch event.Type {
case "EstablishTunnelTimeout":
select {
case errored <- clientlib.ErrTimeout:
case errCh <- context.DeadlineExceeded:
default:
}
case "Tunnels":
Expand Down Expand Up @@ -130,10 +132,10 @@ func (cfg *Config) NewDialer(ctx context.Context) (*Dialer, error) {
case <-connected:
needsCleanup = false
return &Dialer{cancel, controller}, nil
case err := <-errored:
case err := <-errCh:
cancel()
if err != clientlib.ErrTimeout {
err = fmt.Errorf("tunnel start produced error: %w", err)
if !errors.Is(err, context.DeadlineExceeded) {
err = fmt.Errorf("failed to start Psiphon tunnel: %w", err)
}
return nil, err
}
Expand Down

0 comments on commit c69e025

Please sign in to comment.