Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使 vmess inbound 的 clients 可配置, 这样可以实现一个模块替换 vmess 中的验证模块 #1920

Closed
wants to merge 4 commits into from

Conversation

remote-v2ray
Copy link
Contributor

有了这个功能的话, 可以实现远程用户验证

proxy/vmess/inbound-remote/inbound.go

// +build !confonly

package inbound

import (
	"context"

	"v2ray.com/core/common"
	"v2ray.com/core/proxy/vmess/inbound"
)

func init() {
	// 取消 vmess inbound 的注册
	common.UnRegisterConfig((*inbound.Config)(nil))
	common.Must(common.RegisterConfig((*inbound.Config)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
		options := inbound.HandlerOptions{
			// 重新实现用户验证模块
			Clients: &RemoteUserValidator{},
		}
		// 注册修改了用户验证模块后的 vmess inbound
		return inbound.New(ctx, config.(*inbound.Config), options)
	}))
}

proxy/vmess/inbound-remote/validator.go

// +build !confonly

package inbound

import "v2ray.com/core/common/protocol"

type RemoteUserValidator struct {
}

// 在这里实现远程用户和本地用户的验证和转换即可
func (v *RemoteUserValidator) Get(userHash []byte) (*protocol.MemoryUser, protocol.Timestamp, bool) {
	return nil, 0, false
}

// 以下三个接口均可不实现
func (v *RemoteUserValidator) Add(u *protocol.MemoryUser) error {
	return nil
}

func (v *RemoteUserValidator) Remove(email string) bool {
	return false
}

// Close implements common.Closable.
func (v *RemoteUserValidator) Close() error {
	return nil
}

@remote-v2ray
Copy link
Contributor Author

https://github.com/remote-v2ray/vmess-remote 用户验证模块替换完成

@remote-v2ray
Copy link
Contributor Author

也许直接复制替换整个 vmess 模块更为简单

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant