Add vmess legacy server and test

This commit is contained in:
世界
2022-08-01 12:23:34 +08:00
parent 15c8853f66
commit d0c9fdcf66
10 changed files with 81 additions and 50 deletions

View File

@@ -41,10 +41,12 @@ func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogg
users: options.Users,
}
service := vmess.NewService[int](adapter.NewUpstreamContextHandler(inbound.newConnection, inbound.newPacketConnection, inbound))
err := service.UpdateUsers(common.MapIndexed(options.Users, func(index int, user option.VMessUser) int {
err := service.UpdateUsers(common.MapIndexed(options.Users, func(index int, it option.VMessUser) int {
return index
}), common.Map(options.Users, func(user option.VMessUser) string {
return user.UUID
}), common.Map(options.Users, func(it option.VMessUser) string {
return it.UUID
}), common.Map(options.Users, func(it option.VMessUser) int {
return it.AlterId
}))
if err != nil {
return nil, err
@@ -68,11 +70,15 @@ func (h *VMess) Start() error {
return E.Cause(err, "create TLS config")
}
}
return h.myInboundAdapter.Start()
return common.Start(
h.service,
&h.myInboundAdapter,
)
}
func (h *VMess) Close() error {
return common.Close(
h.service,
&h.myInboundAdapter,
common.PtrOrNil(h.tlsConfig),
)