Inbound rule support
This commit is contained in:
35
adapter/inbound/builder.go
Normal file
35
adapter/inbound/builder.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
)
|
||||
|
||||
func New(ctx context.Context, router adapter.Router, logger log.Logger, index int, options option.Inbound) (adapter.Inbound, error) {
|
||||
var tag string
|
||||
if options.Tag != "" {
|
||||
tag = options.Tag
|
||||
} else {
|
||||
tag = F.ToString(index)
|
||||
}
|
||||
inboundLogger := logger.WithPrefix(F.ToString("inbound/", options.Type, "[", tag, "]: "))
|
||||
switch options.Type {
|
||||
case C.TypeDirect:
|
||||
return NewDirect(ctx, router, inboundLogger, options.Tag, options.DirectOptions), nil
|
||||
case C.TypeSocks:
|
||||
return NewSocks(ctx, router, inboundLogger, options.Tag, options.SocksOptions), nil
|
||||
case C.TypeHTTP:
|
||||
return NewHTTP(ctx, router, inboundLogger, options.Tag, options.HTTPOptions), nil
|
||||
case C.TypeMixed:
|
||||
return NewMixed(ctx, router, inboundLogger, options.Tag, options.MixedOptions), nil
|
||||
case C.TypeShadowsocks:
|
||||
return NewShadowsocks(ctx, router, inboundLogger, options.Tag, options.ShadowsocksOptions)
|
||||
default:
|
||||
panic(F.ToString("unknown inbound type: ", options.Type))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user