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
c130fe14
Commit
c130fe14
authored
Sep 20, 2017
by
Steven Allen
Committed by
GitHub
Sep 20, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #36 from libp2p/feat/better-conn-check
use optimized 'HaveConnToPeer' checks
parents
e5826f12
ee8d7e13
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
10 deletions
+5
-10
package.json
package.json
+2
-2
swarm.go
swarm.go
+3
-8
No files found.
package.json
View file @
c130fe14
...
...
@@ -69,9 +69,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
TMNkpso2WRMevXC8ZxgyBhJvoEHvk24SNeUr9Mf9UM1a
"
,
"hash"
:
"Qm
PQnnKQxdtUg8FPXa7BEEkR8gcgo8BuU3T6jtTCB4CR6M
"
,
"name"
:
"go-peerstream"
,
"version"
:
"2.0.
2
"
"version"
:
"2.0.
3
"
},
{
"author"
:
"whyrusleeping"
,
...
...
swarm.go
View file @
c130fe14
...
...
@@ -273,7 +273,7 @@ func (s *Swarm) SetStreamHandler(handler inet.StreamHandler) {
// NewStreamWithPeer creates a new stream on any available connection to p
func
(
s
*
Swarm
)
NewStreamWithPeer
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
*
Stream
,
error
)
{
// if we have no connections, try connecting.
if
len
(
s
.
Connectio
nsToPeer
(
p
)
)
==
0
{
if
!
s
.
HaveCon
nsToPeer
(
p
)
{
log
.
Debug
(
"Swarm: NewStreamWithPeer no connections. Attempting to connect..."
)
if
_
,
err
:=
s
.
Dial
(
ctx
,
p
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -288,16 +288,11 @@ func (s *Swarm) NewStreamWithPeer(ctx context.Context, p peer.ID) (*Stream, erro
// ConnectionsToPeer returns all the live connections to p
func
(
s
*
Swarm
)
ConnectionsToPeer
(
p
peer
.
ID
)
[]
*
Conn
{
return
wrapConns
(
p
s
.
ConnsWithGroup
(
p
,
s
.
swarm
.
Conns
()
))
return
wrapConns
(
s
.
swarm
.
ConnsWithGroup
(
p
))
}
func
(
s
*
Swarm
)
HaveConnsToPeer
(
p
peer
.
ID
)
bool
{
for
_
,
c
:=
range
s
.
swarm
.
Conns
()
{
if
c
.
InGroup
(
p
)
{
return
true
}
}
return
false
return
len
(
s
.
swarm
.
ConnsWithGroup
(
p
))
>
0
}
// Connections returns a slice of all connections.
...
...
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