mirror of https://github.com/v2ray/v2ray-core
merge duplicated code
parent
275c92b6fa
commit
c29f1c8cf0
|
@ -70,15 +70,11 @@ type handlerServer struct {
|
|||
}
|
||||
|
||||
func (s *handlerServer) AddInbound(ctx context.Context, request *AddInboundRequest) (*AddInboundResponse, error) {
|
||||
rawHandler, err := core.CreateObject(s.s, request.Inbound)
|
||||
if err != nil {
|
||||
if err := core.AddInboundHandler(s.s, request.Inbound); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
handler, ok := rawHandler.(inbound.Handler)
|
||||
if !ok {
|
||||
return nil, newError("not an InboundHandler.")
|
||||
}
|
||||
return &AddInboundResponse{}, s.ihm.AddHandler(ctx, handler)
|
||||
|
||||
return &AddInboundResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *handlerServer) RemoveInbound(ctx context.Context, request *RemoveInboundRequest) (*RemoveInboundResponse, error) {
|
||||
|
@ -104,15 +100,10 @@ func (s *handlerServer) AlterInbound(ctx context.Context, request *AlterInboundR
|
|||
}
|
||||
|
||||
func (s *handlerServer) AddOutbound(ctx context.Context, request *AddOutboundRequest) (*AddOutboundResponse, error) {
|
||||
rawHandler, err := core.CreateObject(s.s, request.Outbound)
|
||||
if err != nil {
|
||||
if err := core.AddOutboundHandler(s.s, request.Outbound); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
handler, ok := rawHandler.(outbound.Handler)
|
||||
if !ok {
|
||||
return nil, newError("not an OutboundHandler.")
|
||||
}
|
||||
return &AddOutboundResponse{}, s.ohm.AddHandler(ctx, handler)
|
||||
return &AddOutboundResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *handlerServer) RemoveOutbound(ctx context.Context, request *RemoveOutboundRequest) (*RemoveOutboundResponse, error) {
|
||||
|
|
62
v2ray.go
62
v2ray.go
|
@ -60,22 +60,25 @@ type Instance struct {
|
|||
running bool
|
||||
}
|
||||
|
||||
func addInboundHandlers(server *Instance, configs []*InboundHandlerConfig) error {
|
||||
if len(configs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
func AddInboundHandler(server *Instance, config *InboundHandlerConfig) error {
|
||||
inboundManager := server.GetFeature(inbound.ManagerType()).(inbound.Manager)
|
||||
rawHandler, err := CreateObject(server, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler, ok := rawHandler.(inbound.Handler)
|
||||
if !ok {
|
||||
return newError("not an InboundHandler")
|
||||
}
|
||||
if err := inboundManager.AddHandler(context.Background(), handler); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addInboundHandlers(server *Instance, configs []*InboundHandlerConfig) error {
|
||||
for _, inboundConfig := range configs {
|
||||
rawHandler, err := CreateObject(server, inboundConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler, ok := rawHandler.(inbound.Handler)
|
||||
if !ok {
|
||||
return newError("not an InboundHandler")
|
||||
}
|
||||
if err := inboundManager.AddHandler(context.Background(), handler); err != nil {
|
||||
if err := AddInboundHandler(server, inboundConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -83,22 +86,25 @@ func addInboundHandlers(server *Instance, configs []*InboundHandlerConfig) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func addOutboundHandlers(server *Instance, configs []*OutboundHandlerConfig) error {
|
||||
if len(configs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
func AddOutboundHandler(server *Instance, config *OutboundHandlerConfig) error {
|
||||
outboundManager := server.GetFeature(outbound.ManagerType()).(outbound.Manager)
|
||||
rawHandler, err := CreateObject(server, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler, ok := rawHandler.(outbound.Handler)
|
||||
if !ok {
|
||||
return newError("not an OutboundHandler")
|
||||
}
|
||||
if err := outboundManager.AddHandler(context.Background(), handler); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addOutboundHandlers(server *Instance, configs []*OutboundHandlerConfig) error {
|
||||
for _, outboundConfig := range configs {
|
||||
rawHandler, err := CreateObject(server, outboundConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler, ok := rawHandler.(outbound.Handler)
|
||||
if !ok {
|
||||
return newError("not an OutboundHandler")
|
||||
}
|
||||
if err := outboundManager.AddHandler(context.Background(), handler); err != nil {
|
||||
if err := AddOutboundHandler(server, outboundConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue