mirror of
https://github.com/p4gefau1t/trojan-go.git
synced 2024-04-21 12:21:34 +00:00
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package forward
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/p4gefau1t/trojan-go/config"
|
|
"github.com/p4gefau1t/trojan-go/proxy"
|
|
"github.com/p4gefau1t/trojan-go/proxy/client"
|
|
"github.com/p4gefau1t/trojan-go/tunnel"
|
|
"github.com/p4gefau1t/trojan-go/tunnel/dokodemo"
|
|
)
|
|
|
|
const Name = "FORWARD"
|
|
|
|
func init() {
|
|
proxy.RegisterProxyCreator(Name, func(ctx context.Context) (*proxy.Proxy, error) {
|
|
cfg := config.FromContext(ctx, Name).(*client.Config)
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
serverStack := []string{dokodemo.Name}
|
|
clientStack := client.GenerateClientTree(cfg.TransportPlugin.Enabled, cfg.Mux.Enabled, cfg.Websocket.Enabled, cfg.Shadowsocks.Enabled, cfg.Router.Enabled)
|
|
c, err := proxy.CreateClientStack(ctx, clientStack)
|
|
if err != nil {
|
|
cancel()
|
|
return nil, err
|
|
}
|
|
s, err := proxy.CreateServerStack(ctx, serverStack)
|
|
if err != nil {
|
|
cancel()
|
|
return nil, err
|
|
}
|
|
return proxy.NewProxy(ctx, cancel, []tunnel.Server{s}, c), nil
|
|
})
|
|
}
|
|
|
|
func init() {
|
|
config.RegisterConfigCreator(Name, func() interface{} {
|
|
return new(client.Config)
|
|
})
|
|
}
|