1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-03 01:06:03 -04:00
v2fly/proxy/testing/proxy.go

35 lines
753 B
Go
Raw Normal View History

package testing
import (
"fmt"
"github.com/v2ray/v2ray-core/proxy/internal"
)
var count = 0
func randomString() string {
count++
return fmt.Sprintf("-%d", count)
}
2016-06-14 16:54:08 -04:00
func RegisterInboundConnectionHandlerCreator(prefix string, creator internal.InboundHandlerFactory) (string, error) {
for {
name := prefix + randomString()
err := internal.RegisterInboundHandlerCreator(name, creator)
2016-06-27 02:53:35 -04:00
if err != internal.ErrNameExists {
return name, err
}
}
}
2016-06-14 16:54:08 -04:00
func RegisterOutboundConnectionHandlerCreator(prefix string, creator internal.OutboundHandlerFactory) (string, error) {
for {
name := prefix + randomString()
err := internal.RegisterOutboundHandlerCreator(name, creator)
2016-06-27 02:53:35 -04:00
if err != internal.ErrNameExists {
return name, err
}
}
}