sing-box/outbound/builder.go

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