Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
9910e6a7
Commit
9910e6a7
authored
8 years ago
by
Jeromy
Browse files
Options
Download
Email Patches
Plain Diff
switching to separated conn and interface-conn packages
parent
a54a624e
master
2018-Q4-OKR
docs-improvements
feat/p2p-multiaddr
feat/pnet/working3
feat/protobuf
feat/relay-integrate
feat/udp
feature/standardize-readme
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-jccl6u
gx/update-nza0mn
jenkinsfile
kevina/fix-go-vet
multistream-ping
punching
revert-276-update-go-detect-race
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
v5.0.15
v5.0.14
v5.0.13
v5.0.12
v5.0.11
v5.0.10
v5.0.9
v5.0.8
v5.0.7
v5.0.6
v5.0.5
v5.0.4
v5.0.3
v5.0.2
v5.0.1
v5.0.0
v4.5.5
v4.5.4
v4.5.3
v4.5.2
v4.5.1
v4.5.0
v4.4.5
v4.4.4
v4.4.3
v4.4.2
v4.4.1
v4.4.0
v4.3.12
v4.3.11
v4.3.10
v4.3.9
v4.3.8
v4.3.7
v4.3.6
v4.3.5
v4.3.4
v4.3.3
v4.3.2
v4.3.1
v4.3.0
v4.2.0
v4.1.0
v4.0.4
v4.0.3
v4.0.2
v4.0.1
v4.0.0
No related merge requests found
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
p2p/net/swarm/limiter.go
+4
-4
p2p/net/swarm/limiter.go
p2p/net/swarm/limiter_test.go
+8
-8
p2p/net/swarm/limiter_test.go
p2p/net/swarm/swarm_addr.go
+2
-2
p2p/net/swarm/swarm_addr.go
p2p/net/swarm/swarm_conn.go
+5
-6
p2p/net/swarm/swarm_conn.go
p2p/net/swarm/swarm_dial.go
+4
-4
p2p/net/swarm/swarm_dial.go
p2p/net/swarm/swarm_listen.go
+2
-1
p2p/net/swarm/swarm_listen.go
package.json
+11
-5
package.json
with
36 additions
and
30 deletions
+36
-30
p2p/net/swarm/limiter.go
View file @
9910e6a7
...
...
@@ -7,11 +7,11 @@ import (
peer
"github.com/ipfs/go-libp2p-peer"
ma
"github.com/jbenet/go-multiaddr"
addrutil
"github.com/libp2p/go-addr-util"
conn
"github.com/libp2p/go-libp2p-conn"
i
conn
"github.com/libp2p/go-libp2p-
interface-
conn"
)
type
dialResult
struct
{
Conn
conn
.
Conn
Conn
i
conn
.
Conn
Err
error
}
...
...
@@ -38,14 +38,14 @@ type dialLimiter struct {
fdLimit
int
waitingOnFd
[]
*
dialJob
dialFunc
func
(
context
.
Context
,
peer
.
ID
,
ma
.
Multiaddr
)
(
conn
.
Conn
,
error
)
dialFunc
func
(
context
.
Context
,
peer
.
ID
,
ma
.
Multiaddr
)
(
i
conn
.
Conn
,
error
)
activePerPeer
map
[
peer
.
ID
]
int
perPeerLimit
int
waitingOnPeerLimit
map
[
peer
.
ID
][]
*
dialJob
}
type
dialfunc
func
(
context
.
Context
,
peer
.
ID
,
ma
.
Multiaddr
)
(
conn
.
Conn
,
error
)
type
dialfunc
func
(
context
.
Context
,
peer
.
ID
,
ma
.
Multiaddr
)
(
i
conn
.
Conn
,
error
)
func
newDialLimiter
(
df
dialfunc
)
*
dialLimiter
{
return
newDialLimiterWithParams
(
df
,
concurrentFdDials
,
defaultPerPeerRateLimit
)
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/limiter_test.go
View file @
9910e6a7
...
...
@@ -10,7 +10,7 @@ import (
peer
"github.com/ipfs/go-libp2p-peer"
ma
"github.com/jbenet/go-multiaddr"
conn
"github.com/libp2p/go-libp2p-conn"
i
conn
"github.com/libp2p/go-libp2p-
interface-
conn"
mafmt
"github.com/whyrusleeping/mafmt"
)
...
...
@@ -55,13 +55,13 @@ func tryDialAddrs(ctx context.Context, l *dialLimiter, p peer.ID, addrs []ma.Mul
}
func
hangDialFunc
(
hang
chan
struct
{})
dialfunc
{
return
func
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
)
(
conn
.
Conn
,
error
)
{
return
func
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
)
(
i
conn
.
Conn
,
error
)
{
if
mafmt
.
UTP
.
Matches
(
a
)
{
return
conn
.
Conn
(
nil
),
nil
return
i
conn
.
Conn
(
nil
),
nil
}
if
tcpPortOver
(
a
,
10
)
{
return
conn
.
Conn
(
nil
),
nil
return
i
conn
.
Conn
(
nil
),
nil
}
<-
hang
...
...
@@ -171,9 +171,9 @@ func TestFDLimiting(t *testing.T) {
func
TestTokenRedistribution
(
t
*
testing
.
T
)
{
hangchs
:=
make
(
map
[
peer
.
ID
]
chan
struct
{})
df
:=
func
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
)
(
conn
.
Conn
,
error
)
{
df
:=
func
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
)
(
i
conn
.
Conn
,
error
)
{
if
tcpPortOver
(
a
,
10
)
{
return
(
conn
.
Conn
)(
nil
),
nil
return
(
i
conn
.
Conn
)(
nil
),
nil
}
<-
hangchs
[
p
]
...
...
@@ -260,9 +260,9 @@ func TestTokenRedistribution(t *testing.T) {
}
func
TestStressLimiter
(
t
*
testing
.
T
)
{
df
:=
func
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
)
(
conn
.
Conn
,
error
)
{
df
:=
func
(
ctx
context
.
Context
,
p
peer
.
ID
,
a
ma
.
Multiaddr
)
(
i
conn
.
Conn
,
error
)
{
if
tcpPortOver
(
a
,
1000
)
{
return
conn
.
Conn
(
nil
),
nil
return
i
conn
.
Conn
(
nil
),
nil
}
time
.
Sleep
(
time
.
Millisecond
*
time
.
Duration
(
5
+
rand
.
Intn
(
100
)))
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_addr.go
View file @
9910e6a7
...
...
@@ -3,7 +3,7 @@ package swarm
import
(
ma
"github.com/jbenet/go-multiaddr"
addrutil
"github.com/libp2p/go-addr-util"
conn
"github.com/libp2p/go-libp2p-conn"
i
conn
"github.com/libp2p/go-libp2p-
interface-
conn"
)
// ListenAddresses returns a list of addresses at which this swarm listens.
...
...
@@ -11,7 +11,7 @@ func (s *Swarm) ListenAddresses() []ma.Multiaddr {
listeners
:=
s
.
swarm
.
Listeners
()
addrs
:=
make
([]
ma
.
Multiaddr
,
0
,
len
(
listeners
))
for
_
,
l
:=
range
listeners
{
if
l2
,
ok
:=
l
.
NetListener
()
.
(
conn
.
Listener
);
ok
{
if
l2
,
ok
:=
l
.
NetListener
()
.
(
i
conn
.
Listener
);
ok
{
addrs
=
append
(
addrs
,
l2
.
Multiaddr
())
}
}
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_conn.go
View file @
9910e6a7
...
...
@@ -4,13 +4,12 @@ import (
"context"
"fmt"
inet
"github.com/libp2p/go-libp2p-net"
ic
"github.com/ipfs/go-libp2p-crypto"
peer
"github.com/ipfs/go-libp2p-peer"
ma
"github.com/jbenet/go-multiaddr"
ps
"github.com/jbenet/go-peerstream"
conn
"github.com/libp2p/go-libp2p-conn"
iconn
"github.com/libp2p/go-libp2p-interface-conn"
inet
"github.com/libp2p/go-libp2p-net"
)
// Conn is a simple wrapper around a ps.Conn that also exposes
...
...
@@ -33,12 +32,12 @@ func (c *Conn) StreamConn() *ps.Conn {
return
(
*
ps
.
Conn
)(
c
)
}
func
(
c
*
Conn
)
RawConn
()
conn
.
Conn
{
func
(
c
*
Conn
)
RawConn
()
i
conn
.
Conn
{
// righly panic if these things aren't true. it is an expected
// invariant that these Conns are all of the typewe expect:
// ps.Conn wrapping a conn.Conn
// if we get something else it is programmer error.
return
(
*
ps
.
Conn
)(
c
)
.
NetConn
()
.
(
conn
.
Conn
)
return
(
*
ps
.
Conn
)(
c
)
.
NetConn
()
.
(
i
conn
.
Conn
)
}
func
(
c
*
Conn
)
String
()
string
{
...
...
@@ -94,7 +93,7 @@ func (c *Conn) Close() error {
func
wrapConn
(
psc
*
ps
.
Conn
)
(
*
Conn
,
error
)
{
// grab the underlying connection.
if
_
,
ok
:=
psc
.
NetConn
()
.
(
conn
.
Conn
);
!
ok
{
if
_
,
ok
:=
psc
.
NetConn
()
.
(
i
conn
.
Conn
);
!
ok
{
// this should never happen. if we see it ocurring it means that we added
// a Listener to the ps.Swarm that is NOT one of our net/conn.Listener.
return
nil
,
fmt
.
Errorf
(
"swarm connHandler: invalid conn (not a conn.Conn): %s"
,
psc
)
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_dial.go
View file @
9910e6a7
...
...
@@ -11,7 +11,7 @@ import (
peer
"github.com/ipfs/go-libp2p-peer"
ma
"github.com/jbenet/go-multiaddr"
addrutil
"github.com/libp2p/go-addr-util"
conn
"github.com/libp2p/go-libp2p-conn"
i
conn
"github.com/libp2p/go-libp2p-
interface-
conn"
)
// Diagram of dial sync:
...
...
@@ -284,7 +284,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
return
swarmC
,
nil
}
func
(
s
*
Swarm
)
dialAddrs
(
ctx
context
.
Context
,
p
peer
.
ID
,
remoteAddrs
<-
chan
ma
.
Multiaddr
)
(
conn
.
Conn
,
error
)
{
func
(
s
*
Swarm
)
dialAddrs
(
ctx
context
.
Context
,
p
peer
.
ID
,
remoteAddrs
<-
chan
ma
.
Multiaddr
)
(
i
conn
.
Conn
,
error
)
{
log
.
Debugf
(
"%s swarm dialing %s %s"
,
s
.
local
,
p
,
remoteAddrs
)
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
...
...
@@ -344,7 +344,7 @@ func (s *Swarm) limitedDial(ctx context.Context, p peer.ID, a ma.Multiaddr, resp
})
}
func
(
s
*
Swarm
)
dialAddr
(
ctx
context
.
Context
,
p
peer
.
ID
,
addr
ma
.
Multiaddr
)
(
conn
.
Conn
,
error
)
{
func
(
s
*
Swarm
)
dialAddr
(
ctx
context
.
Context
,
p
peer
.
ID
,
addr
ma
.
Multiaddr
)
(
i
conn
.
Conn
,
error
)
{
log
.
Debugf
(
"%s swarm dialing %s %s"
,
s
.
local
,
p
,
addr
)
connC
,
err
:=
s
.
dialer
.
Dial
(
ctx
,
addr
,
p
)
...
...
@@ -376,7 +376,7 @@ var ConnSetupTimeout = time.Minute * 5
// dialConnSetup is the setup logic for a connection from the dial side. it
// needs to add the Conn to the StreamSwarm, then run newConnSetup
func
dialConnSetup
(
ctx
context
.
Context
,
s
*
Swarm
,
connC
conn
.
Conn
)
(
*
Conn
,
error
)
{
func
dialConnSetup
(
ctx
context
.
Context
,
s
*
Swarm
,
connC
i
conn
.
Conn
)
(
*
Conn
,
error
)
{
deadline
,
ok
:=
ctx
.
Deadline
()
if
!
ok
{
...
...
This diff is collapsed.
Click to expand it.
p2p/net/swarm/swarm_listen.go
View file @
9910e6a7
...
...
@@ -8,6 +8,7 @@ import (
ma
"github.com/jbenet/go-multiaddr"
ps
"github.com/jbenet/go-peerstream"
conn
"github.com/libp2p/go-libp2p-conn"
iconn
"github.com/libp2p/go-libp2p-interface-conn"
mconn
"github.com/libp2p/go-libp2p-metrics/conn"
inet
"github.com/libp2p/go-libp2p-net"
transport
"github.com/libp2p/go-libp2p-transport"
...
...
@@ -98,7 +99,7 @@ func (s *Swarm) addListener(tptlist transport.Listener) error {
return
s
.
addConnListener
(
list
)
}
func
(
s
*
Swarm
)
addConnListener
(
list
conn
.
Listener
)
error
{
func
(
s
*
Swarm
)
addConnListener
(
list
i
conn
.
Listener
)
error
{
// AddListener to the peerstream Listener. this will begin accepting connections
// and streams!
sl
,
err
:=
s
.
swarm
.
AddListener
(
list
)
...
...
This diff is collapsed.
Click to expand it.
package.json
View file @
9910e6a7
...
...
@@ -215,21 +215,27 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
TaW4q1AbqMkpfDLUYzW18nW62GsrnFvtVcvR1pnaURm6
"
,
"hash"
:
"Qm
d4eGc7VMmVZu225mdCzsagdWJBaAVHmmvNFYSvxSUeX5
"
,
"name"
:
"go-libp2p-conn"
,
"version"
:
"1.
0
.0"
"version"
:
"1.
1
.0"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
SctCnUNkE7c7C2LGRGYrdmU9SDH3MtbAeueN7Jq1NN2q
"
,
"hash"
:
"Qm
cr6YS5QCPwejhBxZk5iFEvVEHSVzewbLVMyc64zefaUf
"
,
"name"
:
"go-libp2p-net"
,
"version"
:
"1.0.0"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
S38TTyj47fP5NVNznxpw4KpFYSU9zHkCEfmuBSkHzb6
d"
,
"hash"
:
"Qm
bidKjoAxLVE2skY74Rfw1QafReyf4w2FZqA8Sd7MxoV
d"
,
"name"
:
"go-libp2p-metrics"
,
"version"
:
"1.0.0"
"version"
:
"1.1.0"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmRxzoGdQaN6HYyqWnT82NnLLHBAZbTUvxPEfTBTjU7KCn"
,
"name"
:
"go-libp2p-interface-conn"
,
"version"
:
"0.1.0"
}
],
"gxVersion"
:
"0.4.0"
,
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help