sing-box/inbound/builder.go

51 lines
2.0 KiB
Go
Raw Permalink Normal View History

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