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
dms3
go-dms3
Commits
b61b281e
Commit
b61b281e
authored
Dec 18, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/conns better printing of connections
parent
8b4c7cf3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
18 deletions
+36
-18
net/mux.go
net/mux.go
+1
-1
net/net.go
net/net.go
+4
-0
net/net_test.go
net/net_test.go
+27
-17
net/swarm/swarm_conn.go
net/swarm/swarm_conn.go
+4
-0
No files found.
net/mux.go
View file @
b61b281e
...
@@ -11,7 +11,7 @@ import (
...
@@ -11,7 +11,7 @@ import (
lgbl
"github.com/jbenet/go-ipfs/util/eventlog/loggables"
lgbl
"github.com/jbenet/go-ipfs/util/eventlog/loggables"
)
)
var
log
=
eventlog
.
Logger
(
"
mux2
"
)
var
log
=
eventlog
.
Logger
(
"
network
"
)
// Mux provides simple stream multixplexing.
// Mux provides simple stream multixplexing.
// It helps you precisely when:
// It helps you precisely when:
...
...
net/net.go
View file @
b61b281e
...
@@ -42,6 +42,10 @@ func (s *stream) Write(p []byte) (n int, err error) {
...
@@ -42,6 +42,10 @@ func (s *stream) Write(p []byte) (n int, err error) {
type
conn_
swarm
.
Conn
type
conn_
swarm
.
Conn
func
(
s
*
conn_
)
String
()
string
{
return
s
.
SwarmConn
()
.
String
()
}
func
(
c
*
conn_
)
SwarmConn
()
*
swarm
.
Conn
{
func
(
c
*
conn_
)
SwarmConn
()
*
swarm
.
Conn
{
return
(
*
swarm
.
Conn
)(
c
)
return
(
*
swarm
.
Conn
)(
c
)
}
}
...
...
net/net_test.go
View file @
b61b281e
package
net_test
package
net_test
import
(
import
(
"fmt"
"testing"
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
...
@@ -34,28 +35,37 @@ func TestConnectednessCorrect(t *testing.T) {
...
@@ -34,28 +35,37 @@ func TestConnectednessCorrect(t *testing.T) {
// test those connected show up correctly
// test those connected show up correctly
testConnectedness
:=
func
(
a
,
b
inet
.
Network
,
c
inet
.
Connectedness
)
{
if
a
.
Connectedness
(
b
.
LocalPeer
())
!=
c
{
t
.
Error
(
"%s is connected to %s, but Connectedness incorrect"
,
a
,
b
)
}
// test symmetric case
if
b
.
Connectedness
(
a
.
LocalPeer
())
!=
c
{
t
.
Error
(
"%s is connected to %s, but Connectedness incorrect"
,
a
,
b
)
}
}
// test connected
// test connected
testConnectedness
(
nets
[
0
],
nets
[
1
],
inet
.
Connected
)
testConnectedness
(
t
,
nets
[
0
],
nets
[
1
],
inet
.
Connected
)
testConnectedness
(
nets
[
0
],
nets
[
3
],
inet
.
Connected
)
testConnectedness
(
t
,
nets
[
0
],
nets
[
3
],
inet
.
Connected
)
testConnectedness
(
nets
[
1
],
nets
[
2
],
inet
.
Connected
)
testConnectedness
(
t
,
nets
[
1
],
nets
[
2
],
inet
.
Connected
)
testConnectedness
(
nets
[
3
],
nets
[
2
],
inet
.
Connected
)
testConnectedness
(
t
,
nets
[
3
],
nets
[
2
],
inet
.
Connected
)
// test not connected
// test not connected
testConnectedness
(
nets
[
0
],
nets
[
2
],
inet
.
NotConnected
)
testConnectedness
(
t
,
nets
[
0
],
nets
[
2
],
inet
.
NotConnected
)
testConnectedness
(
nets
[
1
],
nets
[
3
],
inet
.
NotConnected
)
testConnectedness
(
t
,
nets
[
1
],
nets
[
3
],
inet
.
NotConnected
)
for
_
,
n
:=
range
nets
{
for
_
,
n
:=
range
nets
{
n
.
Close
()
n
.
Close
()
}
}
}
}
func
testConnectedness
(
t
*
testing
.
T
,
a
,
b
inet
.
Network
,
c
inet
.
Connectedness
)
{
es
:=
"%s is connected to %s, but Connectedness incorrect. %s %s"
if
a
.
Connectedness
(
b
.
LocalPeer
())
!=
c
{
t
.
Errorf
(
es
,
a
,
b
,
printConns
(
a
),
printConns
(
b
))
}
// test symmetric case
if
b
.
Connectedness
(
a
.
LocalPeer
())
!=
c
{
t
.
Errorf
(
es
,
b
,
a
,
printConns
(
b
),
printConns
(
a
))
}
}
func
printConns
(
n
inet
.
Network
)
string
{
s
:=
fmt
.
Sprintf
(
"Connections in %s:
\n
"
,
n
)
for
_
,
c
:=
range
n
.
Conns
()
{
s
=
s
+
fmt
.
Sprintf
(
"- %s
\n
"
,
c
)
}
return
s
}
net/swarm/swarm_conn.go
View file @
b61b281e
...
@@ -40,6 +40,10 @@ func (c *Conn) RawConn() conn.Conn {
...
@@ -40,6 +40,10 @@ func (c *Conn) RawConn() conn.Conn {
return
(
*
ps
.
Conn
)(
c
)
.
NetConn
()
.
(
conn
.
Conn
)
return
(
*
ps
.
Conn
)(
c
)
.
NetConn
()
.
(
conn
.
Conn
)
}
}
func
(
c
*
Conn
)
String
()
string
{
return
fmt
.
Sprintf
(
"<SwarmConn %s>"
,
c
.
RawConn
())
}
// LocalMultiaddr is the Multiaddr on this side
// LocalMultiaddr is the Multiaddr on this side
func
(
c
*
Conn
)
LocalMultiaddr
()
ma
.
Multiaddr
{
func
(
c
*
Conn
)
LocalMultiaddr
()
ma
.
Multiaddr
{
return
c
.
RawConn
()
.
LocalMultiaddr
()
return
c
.
RawConn
()
.
LocalMultiaddr
()
...
...
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