1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/proxy/testing/proxy.go

36 lines
769 B
Go
Raw Normal View History

package testing
import (
"fmt"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/common"
"v2ray.com/core/proxy/registry"
)
var count = 0
func randomString() string {
count++
return fmt.Sprintf("-%d", count)
}
func RegisterInboundConnectionHandlerCreator(prefix string, creator registry.InboundHandlerFactory) (string, error) {
for {
name := prefix + randomString()
err := registry.RegisterInboundHandlerCreator(name, creator)
2016-08-18 02:34:21 -04:00
if err != common.ErrDuplicatedName {
return name, err
}
}
}
func RegisterOutboundConnectionHandlerCreator(prefix string, creator registry.OutboundHandlerFactory) (string, error) {
for {
name := prefix + randomString()
err := registry.RegisterOutboundHandlerCreator(name, creator)
2016-08-18 02:34:21 -04:00
if err != common.ErrDuplicatedName {
return name, err
}
}
}