sing-box/inbound/builder.go

55 lines
2.1 KiB
Go
Raw Normal View History

2022-07-02 06:07:50 +00:00
package inbound
import (
"context"
"github.com/sagernet/sing-box/adapter"
C "github.com/sagernet/sing-box/constant"
2022-10-25 04:55:00 +00:00
"github.com/sagernet/sing-box/experimental/libbox/platform"
2022-07-02 06:07:50 +00:00
"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
)
2024-06-11 13:16:33 +00:00
func New(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.Inbound, platformInterface platform.Interface) (adapter.Inbound, error) {
2022-07-25 03:29:46 +00:00
if options.Type == "" {
return nil, E.New("missing inbound type")
2022-07-02 17:57:04 +00:00
}
2022-07-02 06:07:50 +00:00
switch options.Type {
2022-07-18 04:32:31 +00:00
case C.TypeTun:
2024-06-11 13:16:33 +00:00
return NewTun(ctx, router, logger, tag, options.TunOptions, platformInterface)
2022-07-18 04:32:31 +00:00
case C.TypeRedirect:
2024-06-11 13:16:33 +00:00
return NewRedirect(ctx, router, logger, tag, options.RedirectOptions), nil
2022-07-18 04:32:31 +00:00
case C.TypeTProxy:
2024-06-11 13:16:33 +00:00
return NewTProxy(ctx, router, logger, tag, options.TProxyOptions), nil
2022-07-02 06:07:50 +00:00
case C.TypeDirect:
2024-06-11 13:16:33 +00:00
return NewDirect(ctx, router, logger, tag, options.DirectOptions), nil
2023-08-04 09:13:46 +00:00
case C.TypeSOCKS:
2024-06-11 13:16:33 +00:00
return NewSocks(ctx, router, logger, tag, options.SocksOptions), nil
2022-07-02 06:07:50 +00:00
case C.TypeHTTP:
2024-06-11 13:16:33 +00:00
return NewHTTP(ctx, router, logger, tag, options.HTTPOptions)
2022-07-02 06:07:50 +00:00
case C.TypeMixed:
2024-06-11 13:16:33 +00:00
return NewMixed(ctx, router, logger, tag, options.MixedOptions), nil
2022-07-02 06:07:50 +00:00
case C.TypeShadowsocks:
2024-06-11 13:16:33 +00:00
return NewShadowsocks(ctx, router, logger, tag, options.ShadowsocksOptions)
2022-07-18 04:32:31 +00:00
case C.TypeVMess:
2024-06-11 13:16:33 +00:00
return NewVMess(ctx, router, logger, tag, options.VMessOptions)
2022-08-08 00:56:04 +00:00
case C.TypeTrojan:
2024-06-11 13:16:33 +00:00
return NewTrojan(ctx, router, logger, tag, options.TrojanOptions)
2022-08-10 12:19:16 +00:00
case C.TypeNaive:
2024-06-11 13:16:33 +00:00
return NewNaive(ctx, router, logger, tag, options.NaiveOptions)
case C.TypeHysteria:
2024-06-11 13:16:33 +00:00
return NewHysteria(ctx, router, logger, tag, options.HysteriaOptions)
case C.TypeShadowTLS:
2024-06-11 13:16:33 +00:00
return NewShadowTLS(ctx, router, logger, tag, options.ShadowTLSOptions)
case C.TypeVLESS:
2024-06-11 13:16:33 +00:00
return NewVLESS(ctx, router, logger, tag, options.VLESSOptions)
2023-07-23 06:42:19 +00:00
case C.TypeTUIC:
2024-06-11 13:16:33 +00:00
return NewTUIC(ctx, router, logger, tag, options.TUICOptions)
2023-08-31 12:07:32 +00:00
case C.TypeHysteria2:
2024-06-11 13:16:33 +00:00
return NewHysteria2(ctx, router, logger, tag, options.Hysteria2Options)
2022-07-02 06:07:50 +00:00
default:
2022-07-02 17:57:04 +00:00
return nil, E.New("unknown inbound type: ", options.Type)
2022-07-02 06:07:50 +00:00
}
}