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
p2p
go-p2p-swarm
Commits
084fffea
Commit
084fffea
authored
Apr 01, 2021
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make IsFdConsumingAddr a standalone utility func
parent
df0ab8b9
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
51 deletions
+56
-51
swarm.go
swarm.go
+1
-1
swarm_dial.go
swarm_dial.go
+2
-2
swarm_test.go
swarm_test.go
+0
-48
util_test.go
util_test.go
+53
-0
No files found.
swarm.go
View file @
084fffea
...
...
@@ -122,7 +122,7 @@ func NewSwarm(ctx context.Context, local peer.ID, peers peerstore.Peerstore, bwc
}
s
.
dsync
=
newDialSync
(
s
.
startDialWorker
)
s
.
limiter
=
newDialLimiter
(
s
.
dialAddr
,
s
.
I
sFdConsumingAddr
)
s
.
limiter
=
newDialLimiter
(
s
.
dialAddr
,
i
sFdConsumingAddr
)
s
.
proc
=
goprocessctx
.
WithContext
(
ctx
)
s
.
ctx
=
goprocessctx
.
OnClosingContext
(
s
.
proc
)
s
.
backf
.
init
(
s
.
ctx
)
...
...
swarm_dial.go
View file @
084fffea
...
...
@@ -630,7 +630,7 @@ func (s *Swarm) rankAddrs(addrs []ma.Multiaddr) []ma.Multiaddr {
if
!
manet
.
IsPrivateAddr
(
a
)
{
tier
|=
0
b0010
}
if
s
.
I
sFdConsumingAddr
(
a
)
{
if
i
sFdConsumingAddr
(
a
)
{
tier
|=
0
b0001
}
...
...
@@ -726,7 +726,7 @@ func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (tra
// A Non-circuit address which has the TCP/UNIX protocol is deemed FD consuming.
// For a circuit-relay address, we look at the address of the relay server/proxy
// and use the same logic as above to decide.
func
(
s
*
Swarm
)
I
sFdConsumingAddr
(
addr
ma
.
Multiaddr
)
bool
{
func
i
sFdConsumingAddr
(
addr
ma
.
Multiaddr
)
bool
{
first
,
_
:=
ma
.
SplitFunc
(
addr
,
func
(
c
ma
.
Component
)
bool
{
return
c
.
Protocol
()
.
Code
==
ma
.
P_CIRCUIT
})
...
...
swarm_test.go
View file @
084fffea
...
...
@@ -15,7 +15,6 @@ import (
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/test"
.
"github.com/libp2p/go-libp2p-swarm"
.
"github.com/libp2p/go-libp2p-swarm/testing"
...
...
@@ -387,53 +386,6 @@ func TestConnectionGating(t *testing.T) {
}
}
func
TestIsFdConsuming
(
t
*
testing
.
T
)
{
tcs
:=
map
[
string
]
struct
{
addr
string
isFdConsuming
bool
}{
"tcp"
:
{
addr
:
"/ip4/127.0.0.1/tcp/20"
,
isFdConsuming
:
true
,
},
"quic"
:
{
addr
:
"/ip4/127.0.0.1/udp/0/quic"
,
isFdConsuming
:
false
,
},
"addr-without-registered-transport"
:
{
addr
:
"/ip4/127.0.0.1/tcp/20/ws"
,
isFdConsuming
:
true
,
},
"relay-tcp"
:
{
addr
:
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/20/p2p-circuit/p2p/%s"
,
test
.
RandPeerIDFatal
(
t
)),
isFdConsuming
:
true
,
},
"relay-quic"
:
{
addr
:
fmt
.
Sprintf
(
"/ip4/127.0.0.1/udp/20/quic/p2p-circuit/p2p/%s"
,
test
.
RandPeerIDFatal
(
t
)),
isFdConsuming
:
false
,
},
"relay-without-serveraddr"
:
{
addr
:
fmt
.
Sprintf
(
"/p2p-circuit/p2p/%s"
,
test
.
RandPeerIDFatal
(
t
)),
isFdConsuming
:
true
,
},
"relay-without-registered-transport-server"
:
{
addr
:
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/20/ws/p2p-circuit/p2p/%s"
,
test
.
RandPeerIDFatal
(
t
)),
isFdConsuming
:
true
,
},
}
ctx
:=
context
.
Background
()
sw
:=
GenSwarm
(
t
,
ctx
)
sk
:=
sw
.
Peerstore
()
.
PrivKey
(
sw
.
LocalPeer
())
require
.
NotNil
(
t
,
sk
)
for
name
:=
range
tcs
{
maddr
,
err
:=
ma
.
NewMultiaddr
(
tcs
[
name
]
.
addr
)
require
.
NoError
(
t
,
err
,
name
)
require
.
Equal
(
t
,
tcs
[
name
]
.
isFdConsuming
,
sw
.
IsFdConsumingAddr
(
maddr
),
name
)
}
}
func
TestNoDial
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
swarms
:=
makeSwarms
(
ctx
,
t
,
2
)
...
...
util_test.go
0 → 100644
View file @
084fffea
package
swarm
import
(
"fmt"
"testing"
"github.com/libp2p/go-libp2p-core/test"
ma
"github.com/multiformats/go-multiaddr"
"github.com/stretchr/testify/require"
)
func
TestIsFdConsuming
(
t
*
testing
.
T
)
{
tcs
:=
map
[
string
]
struct
{
addr
string
isFdConsuming
bool
}{
"tcp"
:
{
addr
:
"/ip4/127.0.0.1/tcp/20"
,
isFdConsuming
:
true
,
},
"quic"
:
{
addr
:
"/ip4/127.0.0.1/udp/0/quic"
,
isFdConsuming
:
false
,
},
"addr-without-registered-transport"
:
{
addr
:
"/ip4/127.0.0.1/tcp/20/ws"
,
isFdConsuming
:
true
,
},
"relay-tcp"
:
{
addr
:
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/20/p2p-circuit/p2p/%s"
,
test
.
RandPeerIDFatal
(
t
)),
isFdConsuming
:
true
,
},
"relay-quic"
:
{
addr
:
fmt
.
Sprintf
(
"/ip4/127.0.0.1/udp/20/quic/p2p-circuit/p2p/%s"
,
test
.
RandPeerIDFatal
(
t
)),
isFdConsuming
:
false
,
},
"relay-without-serveraddr"
:
{
addr
:
fmt
.
Sprintf
(
"/p2p-circuit/p2p/%s"
,
test
.
RandPeerIDFatal
(
t
)),
isFdConsuming
:
true
,
},
"relay-without-registered-transport-server"
:
{
addr
:
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/20/ws/p2p-circuit/p2p/%s"
,
test
.
RandPeerIDFatal
(
t
)),
isFdConsuming
:
true
,
},
}
for
name
:=
range
tcs
{
maddr
,
err
:=
ma
.
NewMultiaddr
(
tcs
[
name
]
.
addr
)
require
.
NoError
(
t
,
err
,
name
)
require
.
Equal
(
t
,
tcs
[
name
]
.
isFdConsuming
,
isFdConsumingAddr
(
maddr
),
name
)
}
}
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