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