Skip to content

Commit

Permalink
add ssu connector
Browse files Browse the repository at this point in the history
  • Loading branch information
ginuerzh committed Feb 2, 2020
1 parent 4133cf3 commit 6ce3639
Show file tree
Hide file tree
Showing 19 changed files with 756 additions and 590 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ gost - GO Simple Tunnel
* [权限控制](https://docs.ginuerzh.xyz/gost/permission/)
* [负载均衡](https://docs.ginuerzh.xyz/gost/load-balancing/)
* [路由控制](https://docs.ginuerzh.xyz/gost/bypass/)
* [DNS控制](https://docs.ginuerzh.xyz/gost/dns/)
* DNS[解析](https://docs.ginuerzh.xyz/gost/resolver/)[代理](https://docs.ginuerzh.xyz/gost/dns/)
* [TUN/TAP设备](https://docs.ginuerzh.xyz/gost/tuntap/)

Wiki站点: <https://docs.ginuerzh.xyz/gost/>
Expand Down
2 changes: 1 addition & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Features
* [Permission control](https://docs.ginuerzh.xyz/gost/en/permission/)
* [Load balancing](https://docs.ginuerzh.xyz/gost/en/load-balancing/)
* [Routing control](https://docs.ginuerzh.xyz/gost/en/bypass/)
* [DNS control](https://docs.ginuerzh.xyz/gost/en/dns/)
* DNS [resolver](https://docs.ginuerzh.xyz/gost/resolver/) and [proxy](https://docs.ginuerzh.xyz/gost/dns/)
* [TUN/TAP device](https://docs.ginuerzh.xyz/gost/en/tuntap/)

Wiki: <https://docs.ginuerzh.xyz/gost/en/>
Expand Down
62 changes: 0 additions & 62 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,68 +64,6 @@ type Transporter interface {
Multiplex() bool
}

// tcpTransporter is a raw TCP transporter.
type tcpTransporter struct{}

// TCPTransporter creates a raw TCP client.
func TCPTransporter() Transporter {
return &tcpTransporter{}
}

func (tr *tcpTransporter) Dial(addr string, options ...DialOption) (net.Conn, error) {
opts := &DialOptions{}
for _, option := range options {
option(opts)
}

timeout := opts.Timeout
if timeout <= 0 {
timeout = DialTimeout
}
if opts.Chain == nil {
return net.DialTimeout("tcp", addr, timeout)
}
return opts.Chain.Dial(addr)
}

func (tr *tcpTransporter) Handshake(conn net.Conn, options ...HandshakeOption) (net.Conn, error) {
return conn, nil
}

func (tr *tcpTransporter) Multiplex() bool {
return false
}

// udpTransporter is a raw UDP transporter.
type udpTransporter struct{}

// UDPTransporter creates a raw UDP client.
func UDPTransporter() Transporter {
return &udpTransporter{}
}

func (tr *udpTransporter) Dial(addr string, options ...DialOption) (net.Conn, error) {
opts := &DialOptions{}
for _, option := range options {
option(opts)
}

timeout := opts.Timeout
if timeout <= 0 {
timeout = DialTimeout
}

return net.DialTimeout("udp", addr, timeout)
}

func (tr *udpTransporter) Handshake(conn net.Conn, options ...HandshakeOption) (net.Conn, error) {
return conn, nil
}

func (tr *udpTransporter) Multiplex() bool {
return false
}

// DialOptions describes the options for Transporter.Dial.
type DialOptions struct {
Timeout time.Duration
Expand Down
28 changes: 12 additions & 16 deletions cmd/gost/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
tr = gost.ObfsHTTPTransporter()
case "ftcp":
tr = gost.FakeTCPTransporter()
case "udp":
tr = gost.UDPTransporter()
default:
tr = gost.TCPTransporter()
}
Expand All @@ -216,6 +218,8 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
connector = gost.ShadowConnector(node.User)
case "ss2":
connector = gost.Shadow2Connector(node.User)
case "ssu":
connector = gost.ShadowUDPConnector(node.User)
case "direct":
connector = gost.SSHDirectForwardConnector()
case "remote":
Expand Down Expand Up @@ -414,31 +418,23 @@ func (r *route) GenRouters() ([]router, error) {
chain.Nodes()[len(chain.Nodes())-1].Client.Transporter = gost.SSHForwardTransporter()
}
ln, err = gost.TCPListener(node.Addr)
case "udp":
ln, err = gost.UDPListener(node.Addr, &gost.UDPListenConfig{
TTL: ttl,
Backlog: node.GetInt("backlog"),
QueueSize: node.GetInt("queue"),
})
case "rtcp":
// Directly use SSH port forwarding if the last chain node is forward+ssh
if chain.LastNode().Protocol == "forward" && chain.LastNode().Transport == "ssh" {
chain.Nodes()[len(chain.Nodes())-1].Client.Connector = gost.SSHRemoteForwardConnector()
chain.Nodes()[len(chain.Nodes())-1].Client.Transporter = gost.SSHForwardTransporter()
}
ln, err = gost.TCPRemoteForwardListener(node.Addr, chain)
case "udp":
ln, err = gost.UDPDirectForwardListener(node.Addr, &gost.UDPForwardListenConfig{
TTL: ttl,
Backlog: node.GetInt("backlog"),
QueueSize: node.GetInt("queue"),
})
case "rudp":
ln, err = gost.UDPRemoteForwardListener(node.Addr,
chain,
&gost.UDPForwardListenConfig{
TTL: ttl,
Backlog: node.GetInt("backlog"),
QueueSize: node.GetInt("queue"),
})
case "ssu":
ln, err = gost.ShadowUDPListener(node.Addr,
node.User,
&gost.UDPForwardListenConfig{
&gost.UDPListenConfig{
TTL: ttl,
Backlog: node.GetInt("backlog"),
QueueSize: node.GetInt("queue"),
Expand Down Expand Up @@ -519,7 +515,7 @@ func (r *route) GenRouters() ([]router, error) {
case "redirect":
handler = gost.TCPRedirectHandler()
case "ssu":
handler = gost.ShadowUDPdHandler()
handler = gost.ShadowUDPHandler()
case "sni":
handler = gost.SNIHandler()
case "tun":
Expand Down
2 changes: 2 additions & 0 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (h *dnsHandler) dumpMsgHeader(m *dns.Msg) string {
return buf.String()
}

// DNSOptions is options for DNS Listener.
type DNSOptions struct {
Mode string
UDPSize int
Expand All @@ -132,6 +133,7 @@ type dnsListener struct {
errc chan error
}

// DNSListener creates a Listener for DNS proxy server.
func DNSListener(addr string, options *DNSOptions) (Listener, error) {
if options == nil {
options = &DNSOptions{}
Expand Down
Loading

0 comments on commit 6ce3639

Please sign in to comment.