1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 09:36:34 -05:00

better port picker

This commit is contained in:
Darien Raymond 2017-01-16 14:18:13 +01:00
parent 9a0ddb78ff
commit d6f8528075
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -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 {