sing-box/outbound/builder.go

54 lines
2.0 KiB
Go
Raw Normal View History

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
)
2022-07-30 00:29:22 +08:00
func New(ctx context.Context, router adapter.Router, logger log.ContextLogger, 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
}
2022-07-02 14:07:50 +08:00
switch options.Type {
case C.TypeDirect:
2022-08-23 21:07:35 +08:00
return NewDirect(router, logger, options.Tag, options.DirectOptions)
case C.TypeBlock:
2022-07-12 15:17:29 +08:00
return NewBlock(logger, options.Tag), nil
2022-07-23 09:15:47 +08:00
case C.TypeDNS:
2022-08-03 18:55:39 +08:00
return NewDNS(router, options.Tag), nil
2022-07-03 13:14:49 +08:00
case C.TypeSocks:
2022-07-12 15:17:29 +08:00
return NewSocks(router, logger, options.Tag, options.SocksOptions)
case C.TypeHTTP:
2022-07-18 20:40:14 +08:00
return NewHTTP(router, logger, options.Tag, options.HTTPOptions)
2022-07-02 14:07:50 +08:00
case C.TypeShadowsocks:
2022-07-30 00:29:22 +08:00
return NewShadowsocks(ctx, router, logger, options.Tag, options.ShadowsocksOptions)
2022-07-18 12:32:31 +08:00
case C.TypeVMess:
2022-08-04 10:38:20 +08:00
return NewVMess(ctx, router, logger, options.Tag, options.VMessOptions)
2022-08-08 08:56:04 +08:00
case C.TypeTrojan:
return NewTrojan(ctx, router, logger, options.Tag, options.TrojanOptions)
2022-08-16 23:37:51 +08:00
case C.TypeWireGuard:
return NewWireGuard(ctx, router, logger, options.Tag, options.WireGuardOptions)
case C.TypeHysteria:
2022-08-21 00:59:49 +08:00
return NewHysteria(ctx, router, logger, options.Tag, options.HysteriaOptions)
case C.TypeTor:
return NewTor(ctx, router, logger, options.Tag, options.TorOptions)
2022-08-21 19:36:08 +08:00
case C.TypeSSH:
return NewSSH(ctx, router, logger, options.Tag, options.SSHOptions)
case C.TypeShadowTLS:
return NewShadowTLS(ctx, router, logger, options.Tag, options.ShadowTLSOptions)
2022-09-12 17:30:54 +08:00
case C.TypeShadowsocksR:
return NewShadowsocksR(ctx, router, logger, options.Tag, options.ShadowsocksROptions)
2022-09-12 21:59:27 +08:00
case C.TypeVLESS:
return NewVLESS(ctx, router, logger, options.Tag, options.VLESSOptions)
2022-07-21 21:03:41 +08:00
case C.TypeSelector:
return NewSelector(router, logger, options.Tag, options.SelectorOptions)
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
}
}