Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
c43e8fa3
Commit
c43e8fa3
authored
Dec 23, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixing race in testutil port
parent
fd2875f2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
util/testutil/gen.go
util/testutil/gen.go
+13
-5
No files found.
util/testutil/gen.go
View file @
c43e8fa3
...
...
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"sync"
"testing"
ci
"github.com/jbenet/go-ipfs/crypto"
...
...
@@ -49,17 +50,24 @@ func RandLocalTCPAddress() ma.Multiaddr {
// most ports above 10000 aren't in use by long running processes, so yay.
// (maybe there should be a range of "loopback" ports that are guaranteed
// to be open for the process, but naturally can only talk to self.)
if
lastPort
==
0
{
lastPort
=
10000
+
SeededRand
.
Intn
(
50000
)
lastPort
.
Lock
()
if
lastPort
.
port
==
0
{
lastPort
.
port
=
10000
+
SeededRand
.
Intn
(
50000
)
}
lastPort
++
port
:=
lastPort
.
port
lastPort
.
port
++
lastPort
.
Unlock
()
addr
:=
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/%d"
,
lastP
ort
)
addr
:=
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/%d"
,
p
ort
)
maddr
,
_
:=
ma
.
NewMultiaddr
(
addr
)
return
maddr
}
var
lastPort
=
0
var
lastPort
=
struct
{
port
int
sync
.
Mutex
}{}
// PeerNetParams is a struct to bundle together the four things
// you need to run a connection with a peer: id, 2keys, and addr.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment