sing-box/inbound/builder.go

40 lines
1.4 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"
"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-12 07:17:29 +00:00
func New(ctx context.Context, router adapter.Router, logger log.ContextLogger, options option.Inbound) (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:
return NewTun(ctx, router, logger, options.Tag, options.TunOptions)
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 06:07:50 +00:00
case C.TypeDirect:
2022-07-12 07:17:29 +00:00
return NewDirect(ctx, router, logger, options.Tag, options.DirectOptions), nil
2022-07-02 06:07:50 +00:00
case C.TypeSocks:
2022-07-12 07:17:29 +00:00
return NewSocks(ctx, router, logger, options.Tag, options.SocksOptions), nil
2022-07-02 06:07:50 +00:00
case C.TypeHTTP:
2022-07-25 00:14:09 +00:00
return NewHTTP(ctx, router, logger, options.Tag, options.HTTPOptions)
2022-07-02 06:07:50 +00:00
case C.TypeMixed:
2022-07-12 07:17:29 +00:00
return NewMixed(ctx, router, logger, options.Tag, options.MixedOptions), nil
2022-07-02 06:07:50 +00:00
case C.TypeShadowsocks:
2022-07-12 07:17:29 +00:00
return NewShadowsocks(ctx, router, logger, options.Tag, options.ShadowsocksOptions)
2022-07-18 04:32:31 +00:00
case C.TypeVMess:
return NewVMess(ctx, router, logger, options.Tag, options.VMessOptions)
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
}
}