Skip to content

Commit

Permalink
Clean up and TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Dec 24, 2024
1 parent 8df547f commit 52dcd84
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions client/go/outline/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ password: SECRET`,
firstHop: "example.com:4321",
}, {
name: "Explicit endpoint",
input: `$type: shadowsocks
input: `
endpoint:
$type: dial
address: example.com:4321
Expand All @@ -68,7 +68,7 @@ secret: SECRET`,
firstHop: "example.com:4321",
}, {
name: "Multi-hop",
input: `$type: shadowsocks
input: `
endpoint:
$type: dial
address: exit.example.com:4321
Expand Down
18 changes: 16 additions & 2 deletions client/go/outline/config/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package config

import (
"context"
"errors"
"net"

"github.com/Jigsaw-Code/outline-sdk/transport"
Expand Down Expand Up @@ -151,8 +152,21 @@ func NewDefaultTransportProvider() *TypeProvider[*TransportPair] {
packetDialers.RegisterParser("shadowsocks", func(ctx context.Context, input map[string]any) (*Dialer[net.Conn], error) {
return newShadowsocksPacketDialer(ctx, input, packetEndpoints.NewInstance)
})
transports.RegisterParser("shadowsocks", func(ctx context.Context, input map[string]any) (*TransportPair, error) {
return newShadowsocksTransport(ctx, input, streamEndpoints.NewInstance, packetEndpoints.NewInstance)

// Websocket support.
streamEndpoints.RegisterParser("websocket", func(ctx context.Context, input map[string]any) (*Endpoint[transport.StreamConn], error) {
// TODO
return nil, errors.ErrUnsupported
})
packetEndpoints.RegisterParser("websocket", func(ctx context.Context, input map[string]any) (*Endpoint[net.Conn], error) {
// TODO
return nil, errors.ErrUnsupported
})

// TODO: Introduce explit transport parser.
transports.RegisterParser("explicit", func(ctx context.Context, input map[string]any) (*TransportPair, error) {
return nil, errors.ErrUnsupported
})

return transports
}
16 changes: 13 additions & 3 deletions client/go/outline/config/shadowsocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,22 @@ func newShadowsocksStreamDialer(ctx context.Context, config ConfigNode, newSE Pa
}

func newShadowsocksPacketDialer(ctx context.Context, config ConfigNode, newPE ParseFunc[*Endpoint[net.Conn]]) (*Dialer[net.Conn], error) {
pl, err := newShadowsocksPacketListener(ctx, config, newPE)
if err != nil {
return nil, err
}
pd := transport.PacketListenerDialer{Listener: pl}
return &Dialer[net.Conn]{ConnectionProviderInfo{ConnTypeTunneled, pl.FirstHop}, pd.DialPacket}, nil
}

func newShadowsocksPacketListener(ctx context.Context, config ConfigNode, newPE ParseFunc[*Endpoint[net.Conn]]) (*PacketListener, error) {
params, err := newShadowsocksParams(config)
if err != nil {
return nil, err
}
if params.SaltGenerator != nil {
return nil, fmt.Errorf("prefix is not yet supported for PacketDialers")
}

pe, err := newPE(ctx, params.Endpoint)
if err != nil {
Expand All @@ -111,9 +123,7 @@ func newShadowsocksPacketDialer(ctx context.Context, config ConfigNode, newPE Pa
return nil, err
}
// TODO: support UDP prefix.
pd := transport.PacketListenerDialer{Listener: pl}

return &Dialer[net.Conn]{ConnectionProviderInfo{ConnTypeTunneled, pe.FirstHop}, pd.DialPacket}, nil
return &PacketListener{ConnectionProviderInfo{ConnTypeTunneled, pe.FirstHop}, pl}, nil
}

type shadowsocksParams struct {
Expand Down

0 comments on commit 52dcd84

Please sign in to comment.