Skip to content

Commit

Permalink
add udp entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ginuerzh committed Dec 16, 2023
1 parent e78a75d commit 4a6d9b1
Show file tree
Hide file tree
Showing 29 changed files with 915 additions and 130 deletions.
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
# GOST-PLUS

A cross-platform GUI client for [GOST.PLUS](https://gost.plus) built with [gioui](https://gioui.org).
A cross-platform GUI client for GOST.PLUS built with [gioui](https://gioui.org).

## Features

### File Tunnel

Expose local files to the public network.

<img src="assets/file-tunnel.gif">

### HTTP Tunnel

Expose local HTTP service to the public network.

<img src="assets/http-tunnel.gif">

### TCP Tunnel

Expose local TCP service to the public network.

<img src="assets/tcp-tunnel.gif">

### UDP Tunnel

Expose local UDP service to the public network.

<img src="assets/udp-tunnel.gif">

## Screenshot

### Desktop

<img src="img/list.png" width="512" />
<img src="img/menu.png" width="512" />
<img src="img/add.png" width="512" />
<img src="img/edit.png" width="512" />
<img src="assets/list.png" width="512" />
<img src="assets/menu.png" width="512" />
<img src="assets/add.png" width="512" />
<img src="assets/edit.png" width="512" />

### Mobile

<img src="img/list-android.png" width="512" />
<img src="img/add-android.png" width="512" />
<img src="img/edit-android.png" width="512" />
<img src="assets/list-android.png" width="512" />
<img src="assets/add-android.png" width="512" />
<img src="assets/edit-android.png" width="512" />
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/file-tunnel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/http-tunnel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/tcp-tunnel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/udp-tunnel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ type Tunnel struct {
Username string `yaml:",omitempty"`
Password string `yaml:",omitempty"`
EnableTLS bool `yaml:"enableTLS,omitempty"`
Keepalive bool `yaml:",omitempty"`
TTL int `yaml:"ttl,omitempty"`

Favorite bool
Closed bool
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
gioui.org v0.4.1
gioui.org/x v0.4.0
github.com/go-gost/core v0.0.0-20231119081403-abc73f2ca2b7
github.com/go-gost/x v0.0.0-20231130113937-b1390dda1cc8
github.com/go-gost/x v0.0.0-20231216062858-f847fa533e98
github.com/google/uuid v1.4.0
github.com/spf13/viper v1.18.1
golang.org/x/exp/shiny v0.0.0-20231206192017-f3f8817b8deb
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ github.com/go-gost/tls-dissector v0.0.2-0.20220408131628-aac992c27451 h1:xj8gUZG
github.com/go-gost/tls-dissector v0.0.2-0.20220408131628-aac992c27451/go.mod h1:/9QfdewqmHdaE362Hv5nDaSWLx3pCmtD870d6GaquXs=
github.com/go-gost/x v0.0.0-20231130113937-b1390dda1cc8 h1:aM2tAfTg4+oBiB161GrYbRBhUHQM1CYNiDNYsqoVAlE=
github.com/go-gost/x v0.0.0-20231130113937-b1390dda1cc8/go.mod h1:YaeMQsu+I8Q3bxPFeo5MbnmLsAdbGUxxG3A4mvUt2YE=
github.com/go-gost/x v0.0.0-20231216062858-f847fa533e98 h1:dFjwqp6SUJhDlFOBeBZXn5b2DqRjdbyBt+6w40+6cR8=
github.com/go-gost/x v0.0.0-20231216062858-f847fa533e98/go.mod h1:YaeMQsu+I8Q3bxPFeo5MbnmLsAdbGUxxG3A4mvUt2YE=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372 h1:FQivqchis6bE2/9uF70M2gmmLpe82esEm2QadL0TEJo=
Expand Down
38 changes: 20 additions & 18 deletions tunnel/entrypoint/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,34 @@ func Delete(id string) {
}

func LoadConfig() {
for _, ep := range config.Global().EntryPoints {
if ep == nil {
for _, cfg := range config.Global().EntryPoints {
if cfg == nil {
continue
}

s := createEntryPoint(ep.Type, tunnel.Options{
ID: ep.ID,
Name: ep.Name,
Endpoint: ep.Endpoint,
Hostname: ep.Hostname,
Username: ep.Username,
Password: ep.Password,
EnableTLS: ep.EnableTLS,
ep := createEntryPoint(cfg.Type, tunnel.Options{
ID: cfg.ID,
Name: cfg.Name,
Endpoint: cfg.Endpoint,
Hostname: cfg.Hostname,
Username: cfg.Username,
Password: cfg.Password,
EnableTLS: cfg.EnableTLS,
Keepalive: cfg.Keepalive,
TTL: cfg.TTL,
})
if s == nil {
if ep == nil {
continue
}

if ep.Closed {
s.Close()
if cfg.Closed {
ep.Close()
} else {
s.Run()
ep.Run()
}

s.Favorite(ep.Favorite)
Add(s)
ep.Favorite(cfg.Favorite)
Add(ep)
}
}

Expand Down Expand Up @@ -174,8 +176,8 @@ func createEntryPoint(st string, opts tunnel.Options) EntryPoint {
switch st {
case TCPEntryPoint:
return NewTCPEntryPoint(options...)
// case UDPEntryPoint:
// return NewU(options...)
case UDPEntryPoint:
return NewUDPEntryPoint(options...)
default:
return nil
}
Expand Down
9 changes: 7 additions & 2 deletions tunnel/entrypoint/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"sync"
"sync/atomic"
"time"

"github.com/go-gost/core/chain"
"github.com/go-gost/core/handler"
Expand All @@ -17,7 +18,7 @@ import (
chain_parser "github.com/go-gost/x/config/parsing/chain"
"github.com/go-gost/x/handler/forward/local"
"github.com/go-gost/x/hop"
"github.com/go-gost/x/listener/tcp"
"github.com/go-gost/x/listener/udp"
mdx "github.com/go-gost/x/metadata"
xservice "github.com/go-gost/x/service"
"github.com/google/uuid"
Expand Down Expand Up @@ -108,6 +109,10 @@ func (s *udpEntryPoint) init() error {
},
Listener: &config.ListenerConfig{
Type: "udp",
Metadata: map[string]any{
"keepalive": s.opts.Keepalive,
"ttl": time.Duration(s.opts.TTL) * time.Second,
},
},
Forwarder: &config.ForwarderConfig{
Nodes: []*config.ForwardNodeConfig{
Expand Down Expand Up @@ -153,7 +158,7 @@ func (s *udpEntryPoint) Run() (err error) {
}

cfg := s.config.Services[0]
ln := tcp.NewListener(
ln := udp.NewListener(
listener.AddrOption(cfg.Addr),
listener.LoggerOption(log.WithFields(map[string]any{"kind": "listener", "listener": "udp"})),
)
Expand Down
14 changes: 14 additions & 0 deletions tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Options struct {
Username string
Password string
EnableTLS bool
Keepalive bool
TTL int
}

type Option func(opts *Options)
Expand Down Expand Up @@ -82,6 +84,18 @@ func EnableTLSOption(b bool) Option {
}
}

func KeepaliveOption(b bool) Option {
return func(opts *Options) {
opts.Keepalive = b
}
}

func TTLOption(ttl int) Option {
return func(opts *Options) {
opts.TTL = ttl
}
}

type Tunnel interface {
ID() string
Type() string
Expand Down
30 changes: 16 additions & 14 deletions ui/icons/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ func init() {
var (
IconApp *widget.Image

IconHome = mustIcon(icons.ActionHome)
IconFavorite = mustIcon(icons.ActionFavorite)
IconAdd = mustIcon(icons.ContentAdd)
IconSettings = mustIcon(icons.ActionSettings)
IconDone = mustIcon(icons.ActionDone)
IconTunnelState = mustIcon(icons.ToggleRadioButtonChecked)
IconForward = mustIcon(icons.NavigationChevronRight)
IconEdit = mustIcon(icons.EditorModeEdit)
IconDelete = mustIcon(icons.ActionDelete)
IconStart = mustIcon(icons.AVPlayArrow)
IconStop = mustIcon(icons.AVStop)
IconBack = mustIcon(icons.NavigationArrowBack)
IconClose = mustIcon(icons.ContentClear)
IconCopy = mustIcon(icons.ContentContentCopy)
IconHome = mustIcon(icons.ActionHome)
IconFavorite = mustIcon(icons.ActionFavorite)
IconAdd = mustIcon(icons.ContentAdd)
IconSettings = mustIcon(icons.ActionSettings)
IconDone = mustIcon(icons.ActionDone)
IconTunnelState = mustIcon(icons.ToggleRadioButtonChecked)
IconForward = mustIcon(icons.NavigationChevronRight)
IconEdit = mustIcon(icons.EditorModeEdit)
IconDelete = mustIcon(icons.ActionDelete)
IconStart = mustIcon(icons.AVPlayArrow)
IconStop = mustIcon(icons.AVStop)
IconBack = mustIcon(icons.NavigationArrowBack)
IconClose = mustIcon(icons.ContentClear)
IconCopy = mustIcon(icons.ContentContentCopy)
IconVisibility = mustIcon(icons.ActionVisibility)
IconVisibilityOff = mustIcon(icons.ActionVisibilityOff)
)

func mustIcon(data []byte) *widget.Icon {
Expand Down
2 changes: 2 additions & 0 deletions ui/page/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func (p *entryPointPage) Layout(gtx C, th *material.Theme) D {
switch s.Type() {
case entrypoint.TCPEntryPoint:
p.router.SwitchTo(Route{Path: PageEditTCPEntryPoint, ID: s.ID()})
case entrypoint.UDPEntryPoint:
p.router.SwitchTo(Route{Path: PageEditUDPEntryPoint, ID: s.ID()})
}
op.InvalidateOp{}.Add(gtx.Ops)
}
Expand Down
Loading

0 comments on commit 4a6d9b1

Please sign in to comment.