Skip to content

Commit

Permalink
rename to config.NewPacketListener
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Oct 18, 2023
1 parent 1ebabd0 commit 7f5613d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
18 changes: 10 additions & 8 deletions x/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,23 @@ func newPacketDialerFromPart(innerDialer transport.PacketDialer, oneDialerConfig
}
}

// NewShadowsocksPacketListenerFromPart creates a new [transport.PacketListener] according to the given config,
// NewpacketListener creates a new [transport.PacketListener] according to the given config,
// the config must contain only one "ss://" segment.
func NewShadowsocksPacketListenerFromPart(ssConfig string) (transport.PacketListener, error) {
ssConfig = strings.TrimSpace(ssConfig)
if ssConfig == "" {
return nil, errors.New("empty config part")
func NewpacketListener(transportConfig string) (transport.PacketListener, error) {
if transportConfig = strings.TrimSpace(transportConfig); transportConfig == "" {
return nil, errors.New("config is required")
}
if strings.Contains(transportConfig, "|") {
return nil, errors.New("multi-part config is not supported")
}

url, err := url.Parse(ssConfig)
url, err := url.Parse(transportConfig)
if err != nil {
return nil, fmt.Errorf("failed to parse config part: %w", err)
return nil, fmt.Errorf("failed to parse config: %w", err)
}

if url.Scheme != "ss" {
return nil, errors.New("config scheme must be 'ss' for a PacketListener")
}

return newShadowsocksPacketListenerFromURL(url)
}
19 changes: 6 additions & 13 deletions x/examples/outline-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,22 @@

The CLI interface of OutlineVPN client for Linux.

## Usage

#### Standard

```
./outline-cli -transport "ss://<outline-server-access-key>"
```

#### Advanced (with Golang)
### Usage

```
go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-cli@latest -transport "ss://<outline-server-access-key>"
```

### Arguments

- `-transport` : the Outline server access key from the service provider, it should start with "ss://"

## Build (for Developers)
### Build

You can use the following command to build the CLI.

We recommend to setup a [go workspace](https://go.dev/blog/get-familiar-with-workspaces) to build the code. Then use the following command to build the CLI (only support Linux):

```
cd outline-sdk/x/examples/
go build -o outline-cli -ldflags="-extldflags=-static" ./outline-cli
```

> 💡 `cgo` will pull in the C runtime. By default, the C runtime is linked as a dynamic library. Sometimes this can cause problems when running the binary on different versions or distributions of Linux. To avoid this, we have added the `-ldflags="-extldflags=-static"` option. But if you only need to run the binary on the same machine, you can omit this option.
2 changes: 1 addition & 1 deletion x/examples/outline-cli/outline_packet_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type outlinePacketProxy struct {
func newOutlinePacketProxy(transportConfig string) (opp *outlinePacketProxy, err error) {
opp = &outlinePacketProxy{}

if opp.remotePl, err = config.NewShadowsocksPacketListenerFromPart(transportConfig); err != nil {
if opp.remotePl, err = config.NewpacketListener(transportConfig); err != nil {
return nil, fmt.Errorf("failed to create UDP packet listener: %w", err)
}
if opp.remote, err = network.NewPacketProxyFromPacketListener(opp.remotePl); err != nil {
Expand Down

0 comments on commit 7f5613d

Please sign in to comment.