Skip to content

Commit

Permalink
add reverse api support.(XTLS#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
tat5522 committed Mar 25, 2021
1 parent e0910ab commit 7640482
Show file tree
Hide file tree
Showing 11 changed files with 1,499 additions and 17 deletions.
8 changes: 8 additions & 0 deletions app/reverse/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ func (b *Bridge) monitor() error {
return nil
}

func (b *Bridge) GetTag() string {
return b.tag
}

func (b *Bridge) GetDomain() string {
return b.domain
}

func (b *Bridge) Start() error {
return b.monitorTask.Start()
}
Expand Down
68 changes: 68 additions & 0 deletions app/reverse/command/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package command

//go:generate go run github.com/xtls/xray-core/common/errors/errorgen

import (
"context"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/reverse"
"google.golang.org/grpc"
)

// reverseServer is an implementation of ReverseService.
type reverseServer struct {
s *core.Instance
reverse reverse.Manager
}

func (s *reverseServer) AddBridge(ctx context.Context, request *AddBridgeRequest) (*AddBridgeResponse, error) {
err := s.reverse.AddBridge(ctx, request.Config)
return &AddBridgeResponse{}, err
}

func (s *reverseServer) RemoveBridge(ctx context.Context, request *RemoveBridgeRequest) (*RemoveBridgeResponse, error) {
err := s.reverse.RemoveBridge(ctx, request.Tag)
return &RemoveBridgeResponse{}, err
}

func (s *reverseServer) AddPortal(ctx context.Context, request *AddPortalRequest) (*AddPortalResponse, error) {
err := s.reverse.AddPortal(ctx, request.Config)
return &AddPortalResponse{}, err
}

func (s *reverseServer) RemovePortal(ctx context.Context, request *RemovePortalRequest) (*RemovePortalResponse, error) {
err := s.reverse.RemovePortal(ctx, request.Tag)
return &RemovePortalResponse{}, err
}

func (s *reverseServer) mustEmbedUnimplementedReverseServiceServer() {}

type service struct {
v *core.Instance
}

func (s *service) Register(server *grpc.Server) {
m := &reverseServer{
s: s.v,
reverse: nil,
}

common.Must(s.v.RequireFeatures(func(reverse reverse.Manager) {
m.reverse = reverse
}))

RegisterReverseServiceServer(server, m)

// For compatibility purposes
vCoreDesc := ReverseService_ServiceDesc
vCoreDesc.ServiceName = "v2ray.core.app.reverse.command.ReverseService"
server.RegisterService(&vCoreDesc, m)
}

func init() {
common.Must(common.RegisterConfig((*Config)(nil), func(ctx context.Context, cfg interface{}) (interface{}, error) {
s := core.MustFromContext(ctx)
return &service{v: s}, nil
}))
}
Loading

0 comments on commit 7640482

Please sign in to comment.