Skip to content

Commit

Permalink
Finish
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Oct 28, 2024
1 parent 77906f1 commit ffc0654
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
19 changes: 3 additions & 16 deletions x/configurl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (
"errors"
"fmt"
"net/url"
"strconv"
"strings"

"github.com/Jigsaw-Code/outline-sdk/transport"
"github.com/Jigsaw-Code/outline-sdk/transport/tlsfrag"
)

// ConfigToDialer enables the creation of stream and packet dialers based on a config. The config is
Expand Down Expand Up @@ -144,21 +142,10 @@ func NewDefaultConfigToDialer() *ConfigToDialer {

registerTLSStreamDialer(p, "tls", p.NewStreamDialerFromConfig)

p.RegisterStreamDialerType("tlsfrag", func(ctx context.Context, config *Config) (transport.StreamDialer, error) {
sd, err := p.NewStreamDialerFromConfig(ctx, config.BaseConfig)
if err != nil {
return nil, err
}
lenStr := config.URL.Opaque
fixedLen, err := strconv.Atoi(lenStr)
if err != nil {
return nil, fmt.Errorf("invalid tlsfrag option: %v. It should be in tlsfrag:<number> format", lenStr)
}
return tlsfrag.NewFixedLenStreamDialer(sd, fixedLen)
})
registerTLSFragStreamDialer(p, "tlsfrag", p.NewStreamDialerFromConfig)

p.RegisterStreamDialerType("ws", newWebsocketStreamDialerFactory(p.NewStreamDialerFromConfig))
p.RegisterPacketDialerType("ws", newWebsocketPacketDialerFactory(p.NewStreamDialerFromConfig))
registerWebsocketStreamDialer(p, "ws", p.NewStreamDialerFromConfig)
registerWebsocketPacketDialer(p, "ws", p.NewStreamDialerFromConfig)

return p
}
Expand Down
39 changes: 39 additions & 0 deletions x/configurl/tlsfrag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package configurl

import (
"context"
"fmt"
"strconv"

"github.com/Jigsaw-Code/outline-sdk/transport"
"github.com/Jigsaw-Code/outline-sdk/transport/tlsfrag"
)

func registerTLSFragStreamDialer(r StreamDialerRegistry, typeID string, newSD NewStreamDialerFunc) {
r.RegisterStreamDialerType(typeID, func(ctx context.Context, config *Config) (transport.StreamDialer, error) {
sd, err := newSD(ctx, config.BaseConfig)
if err != nil {
return nil, err
}
lenStr := config.URL.Opaque
fixedLen, err := strconv.Atoi(lenStr)
if err != nil {
return nil, fmt.Errorf("invalid tlsfrag option: %v. It should be in tlsfrag:<number> format", lenStr)
}
return tlsfrag.NewFixedLenStreamDialer(sd, fixedLen)
})
}
12 changes: 6 additions & 6 deletions x/configurl/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (c *wsToStreamConn) CloseWrite() error {
return c.Close()
}

func newWebsocketStreamDialerFactory(newSD NewStreamDialerFunc) NewStreamDialerFunc {
return func(ctx context.Context, config *Config) (transport.StreamDialer, error) {
func registerWebsocketStreamDialer(r StreamDialerRegistry, typeID string, newSD NewStreamDialerFunc) {
r.RegisterStreamDialerType(typeID, func(ctx context.Context, config *Config) (transport.StreamDialer, error) {
sd, err := newSD(ctx, config.BaseConfig)
if err != nil {
return nil, err
Expand Down Expand Up @@ -102,11 +102,11 @@ func newWebsocketStreamDialerFactory(newSD NewStreamDialerFunc) NewStreamDialerF
}
return &wsToStreamConn{wsConn}, nil
}), nil
}
})
}

func newWebsocketPacketDialerFactory(newSD NewStreamDialerFunc) NewPacketDialerFunc {
return func(ctx context.Context, config *Config) (transport.PacketDialer, error) {
func registerWebsocketPacketDialer(r PacketDialerRegistry, typeID string, newSD NewStreamDialerFunc) {
r.RegisterPacketDialerType(typeID, func(ctx context.Context, config *Config) (transport.PacketDialer, error) {
sd, err := newSD(ctx, config.BaseConfig)
if err != nil {
return nil, err
Expand Down Expand Up @@ -136,5 +136,5 @@ func newWebsocketPacketDialerFactory(newSD NewStreamDialerFunc) NewPacketDialerF
}
return wsConn, nil
}), nil
}
})
}

0 comments on commit ffc0654

Please sign in to comment.