Skip to content
GitLab
Menu
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
324aae38
Commit
324aae38
authored
Sep 05, 2016
by
Jeromy
Browse files
swarm: add optimized method for checking connectedness to peer
parent
9a9a8de2
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/net/swarm/swarm.go
View file @
324aae38
...
@@ -286,6 +286,15 @@ func (s *Swarm) ConnectionsToPeer(p peer.ID) []*Conn {
...
@@ -286,6 +286,15 @@ func (s *Swarm) ConnectionsToPeer(p peer.ID) []*Conn {
return
wrapConns
(
ps
.
ConnsWithGroup
(
p
,
s
.
swarm
.
Conns
()))
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.
// Connections returns a slice of all connections.
func
(
s
*
Swarm
)
Connections
()
[]
*
Conn
{
func
(
s
*
Swarm
)
Connections
()
[]
*
Conn
{
return
wrapConns
(
s
.
swarm
.
Conns
())
return
wrapConns
(
s
.
swarm
.
Conns
())
...
...
p2p/net/swarm/swarm_net.go
View file @
324aae38
...
@@ -123,8 +123,7 @@ func (n *Network) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
...
@@ -123,8 +123,7 @@ func (n *Network) InterfaceListenAddresses() ([]ma.Multiaddr, error) {
// Connectedness returns a state signaling connection capabilities
// Connectedness returns a state signaling connection capabilities
// For now only returns Connected || NotConnected. Expand into more later.
// For now only returns Connected || NotConnected. Expand into more later.
func
(
n
*
Network
)
Connectedness
(
p
peer
.
ID
)
inet
.
Connectedness
{
func
(
n
*
Network
)
Connectedness
(
p
peer
.
ID
)
inet
.
Connectedness
{
c
:=
n
.
Swarm
()
.
ConnectionsToPeer
(
p
)
if
n
.
Swarm
()
.
HaveConnsToPeer
(
p
)
{
if
len
(
c
)
>
0
{
return
inet
.
Connected
return
inet
.
Connected
}
}
return
inet
.
NotConnected
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