better port picker

pull/362/head
Darien Raymond 8 years ago
parent 9a0ddb78ff
commit d6f8528075
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -2,20 +2,21 @@ package scenarios
import (
"net"
"sync/atomic"
"time"
"github.com/golang/protobuf/proto"
"v2ray.com/core"
"v2ray.com/core/common"
v2net "v2ray.com/core/common/net"
)
var (
port uint32 = 40000
)
func pickPort() v2net.Port {
return v2net.Port(atomic.AddUint32(&port, 1))
listener, err := net.Listen("tcp4", ":0")
common.Must(err)
defer listener.Close()
addr := listener.Addr().(*net.TCPAddr)
return v2net.Port(addr.Port)
}
func xor(b []byte) []byte {

Loading…
Cancel
Save