2022-07-02 14:07:50 +08:00
|
|
|
package outbound
|
|
|
|
|
|
|
|
import (
|
2022-07-30 00:29:22 +08:00
|
|
|
"context"
|
|
|
|
|
2022-07-02 14:07:50 +08:00
|
|
|
"github.com/sagernet/sing-box/adapter"
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
|
|
|
"github.com/sagernet/sing-box/log"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
2022-07-08 23:03:57 +08:00
|
|
|
E "github.com/sagernet/sing/common/exceptions"
|
2022-07-02 14:07:50 +08:00
|
|
|
)
|
|
|
|
|
2023-04-08 08:58:01 +08:00
|
|
|
func New(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.Outbound) (adapter.Outbound, error) {
|
2022-07-25 11:29:46 +08:00
|
|
|
if options.Type == "" {
|
|
|
|
return nil, E.New("missing outbound type")
|
2022-07-03 01:57:04 +08:00
|
|
|
}
|
2023-04-08 08:58:01 +08:00
|
|
|
ctx = ContextWithTag(ctx, tag)
|
2022-07-02 14:07:50 +08:00
|
|
|
switch options.Type {
|
|
|
|
case C.TypeDirect:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewDirect(router, logger, tag, options.DirectOptions)
|
2022-07-03 23:23:18 +08:00
|
|
|
case C.TypeBlock:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewBlock(logger, tag), nil
|
2022-07-23 09:15:47 +08:00
|
|
|
case C.TypeDNS:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewDNS(router, tag), nil
|
2023-08-04 17:13:46 +08:00
|
|
|
case C.TypeSOCKS:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewSocks(router, logger, tag, options.SocksOptions)
|
2022-07-03 23:23:18 +08:00
|
|
|
case C.TypeHTTP:
|
2023-08-29 13:43:42 +08:00
|
|
|
return NewHTTP(ctx, router, logger, tag, options.HTTPOptions)
|
2022-07-02 14:07:50 +08:00
|
|
|
case C.TypeShadowsocks:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewShadowsocks(ctx, router, logger, tag, options.ShadowsocksOptions)
|
2022-07-18 12:32:31 +08:00
|
|
|
case C.TypeVMess:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewVMess(ctx, router, logger, tag, options.VMessOptions)
|
2022-08-08 08:56:04 +08:00
|
|
|
case C.TypeTrojan:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewTrojan(ctx, router, logger, tag, options.TrojanOptions)
|
2022-08-16 23:37:51 +08:00
|
|
|
case C.TypeWireGuard:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewWireGuard(ctx, router, logger, tag, options.WireGuardOptions)
|
2022-08-19 15:42:57 +08:00
|
|
|
case C.TypeHysteria:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewHysteria(ctx, router, logger, tag, options.HysteriaOptions)
|
2022-08-21 00:59:49 +08:00
|
|
|
case C.TypeTor:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewTor(ctx, router, logger, tag, options.TorOptions)
|
2022-08-21 19:36:08 +08:00
|
|
|
case C.TypeSSH:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewSSH(ctx, router, logger, tag, options.SSHOptions)
|
2022-08-31 14:21:53 +08:00
|
|
|
case C.TypeShadowTLS:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewShadowTLS(ctx, router, logger, tag, options.ShadowTLSOptions)
|
2022-09-12 17:30:54 +08:00
|
|
|
case C.TypeShadowsocksR:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewShadowsocksR(ctx, router, logger, tag, options.ShadowsocksROptions)
|
2022-09-12 21:59:27 +08:00
|
|
|
case C.TypeVLESS:
|
2023-04-08 08:58:01 +08:00
|
|
|
return NewVLESS(ctx, router, logger, tag, options.VLESSOptions)
|
2023-07-23 14:42:19 +08:00
|
|
|
case C.TypeTUIC:
|
|
|
|
return NewTUIC(ctx, router, logger, tag, options.TUICOptions)
|
2023-08-31 20:07:32 +08:00
|
|
|
case C.TypeHysteria2:
|
|
|
|
return NewHysteria2(ctx, router, logger, tag, options.Hysteria2Options)
|
2022-07-21 21:03:41 +08:00
|
|
|
case C.TypeSelector:
|
2023-11-28 12:00:28 +08:00
|
|
|
return NewSelector(ctx, router, logger, tag, options.SelectorOptions)
|
2022-09-15 15:22:08 +08:00
|
|
|
case C.TypeURLTest:
|
2023-04-13 09:03:08 +08:00
|
|
|
return NewURLTest(ctx, router, logger, tag, options.URLTestOptions)
|
2022-07-02 14:07:50 +08:00
|
|
|
default:
|
2022-07-03 01:57:04 +08:00
|
|
|
return nil, E.New("unknown outbound type: ", options.Type)
|
2022-07-02 14:07:50 +08:00
|
|
|
}
|
|
|
|
}
|