sing-box/outbound/builder.go

66 lines
2.3 KiB
Go
Raw Permalink Normal View History

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