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
5dea71d2
Commit
5dea71d2
authored
Sep 05, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm: add optimized method for checking connectedness to peer
parent
48ef0bb9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
2 deletions
+10
-2
swarm.go
swarm.go
+9
-0
swarm_net.go
swarm_net.go
+1
-2
No files found.
swarm.go
View file @
5dea71d2
...
...
@@ -286,6 +286,15 @@ func (s *Swarm) ConnectionsToPeer(p peer.ID) []*Conn {
return
wrapConns
(
ps
.
ConnsWithGroup
(
p
,
s
.
swarm
.
Conns
()))
}
func
(
s
*
Swarm
)
HaveConnsToPeer
(
p
peer
.
ID
)
bool
{
for
_
,
c
:=
range
s
.
swarm
.
Conns
()
{
if
c
.
InGroup
(
p
)
{
return
true
}
}
return
false
}
// Connections returns a slice of all connections.
func
(
s
*
Swarm
)
Connections
()
[]
*
Conn
{
return
wrapConns
(
s
.
swarm
.
Conns
())
...
...
swarm_net.go
View file @
5dea71d2
...
...
@@ -123,8 +123,7 @@ func (n *Network) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
// Connectedness returns a state signaling connection capabilities
// For now only returns Connected || NotConnected. Expand into more later.
func
(
n
*
Network
)
Connectedness
(
p
peer
.
ID
)
inet
.
Connectedness
{
c
:=
n
.
Swarm
()
.
ConnectionsToPeer
(
p
)
if
len
(
c
)
>
0
{
if
n
.
Swarm
()
.
HaveConnsToPeer
(
p
)
{
return
inet
.
Connected
}
return
inet
.
NotConnected
...
...
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