add router, fix transport

This commit is contained in:
Page Fault
2020-06-10 08:51:29 +00:00
parent a3ee9af30b
commit 38b30b00f5
21 changed files with 926 additions and 56 deletions
+6 -2
View File
@@ -6,6 +6,7 @@ import (
"github.com/p4gefau1t/trojan-go/proxy"
"github.com/p4gefau1t/trojan-go/tunnel"
"github.com/p4gefau1t/trojan-go/tunnel/mux"
"github.com/p4gefau1t/trojan-go/tunnel/router"
"github.com/p4gefau1t/trojan-go/tunnel/simplesocks"
"github.com/p4gefau1t/trojan-go/tunnel/socks"
"github.com/p4gefau1t/trojan-go/tunnel/transport"
@@ -16,7 +17,7 @@ import (
const Name = "CLIENT"
// GenerateClientTree generate general outbound protocol stack
func GenerateClientTree(isMux bool, isWebsocket bool) []string {
func GenerateClientTree(isMux bool, isWebsocket bool, isRouter bool) []string {
clientStack := []string{transport.Name}
if isWebsocket {
clientStack = append(clientStack, websocket.Name)
@@ -25,6 +26,9 @@ func GenerateClientTree(isMux bool, isWebsocket bool) []string {
if isMux {
clientStack = append(clientStack, []string{mux.Name, simplesocks.Name}...)
}
if isRouter {
clientStack = append(clientStack, router.Name)
}
return clientStack
}
@@ -32,7 +36,7 @@ func init() {
proxy.RegisterProxyCreator(Name, func(ctx context.Context) (*proxy.Proxy, error) {
cfg := config.FromContext(ctx, Name).(*Config)
serverStack := []string{socks.Name}
clientStack := GenerateClientTree(cfg.Mux.Enabled, cfg.Websocket.Enabled)
clientStack := GenerateClientTree(cfg.Mux.Enabled, cfg.Websocket.Enabled, cfg.Router.Enabled)
c, err := proxy.CreateClientStack(ctx, clientStack)
if err != nil {
return nil, err
+9 -4
View File
@@ -3,16 +3,21 @@ package client
import "github.com/p4gefau1t/trojan-go/config"
type MuxConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
Enabled bool `json,yaml:"enabled"`
}
type WebsocketConfig struct {
Enabled bool `json:"enabled" yaml:"enabled"`
Enabled bool `json,yaml:"enabled"`
}
type RouterConfig struct {
Enabled bool `json,yaml:"enabled"`
}
type Config struct {
Mux MuxConfig `json:"mux" yaml:"mux"`
Websocket WebsocketConfig `json:"websocket" yaml:"websocket"`
Mux MuxConfig `json,yaml:"mux"`
Websocket WebsocketConfig `json,yaml:"websocket"`
Router RouterConfig `json,yaml:"router"`
}
func init() {
+1 -1
View File
@@ -15,7 +15,7 @@ func init() {
proxy.RegisterProxyCreator(Name, func(ctx context.Context) (*proxy.Proxy, error) {
cfg := config.FromContext(ctx, Name).(*client.Config)
serverStack := []string{dokodemo.Name}
clientStack := client.GenerateClientTree(cfg.Mux.Enabled, cfg.Websocket.Enabled)
clientStack := client.GenerateClientTree(cfg.Mux.Enabled, cfg.Websocket.Enabled, cfg.Router.Enabled)
c, err := proxy.CreateClientStack(ctx, clientStack)
if err != nil {
return nil, err
+1 -1
View File
@@ -15,7 +15,7 @@ func init() {
proxy.RegisterProxyCreator(Name, func(ctx context.Context) (*proxy.Proxy, error) {
cfg := config.FromContext(ctx, Name).(*client.Config)
serverStack := []string{tproxy.Name}
clientStack := client.GenerateClientTree(cfg.Mux.Enabled, cfg.Websocket.Enabled)
clientStack := client.GenerateClientTree(cfg.Mux.Enabled, cfg.Websocket.Enabled, false)
c, err := proxy.CreateClientStack(ctx, clientStack)
if err != nil {
return nil, err