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
29ab6dec
Commit
29ab6dec
authored
Oct 19, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added msg counters to logs
parent
63d6ee6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
5 deletions
+23
-5
net/conn/multiconn.go
net/conn/multiconn.go
+11
-0
net/swarm/conn.go
net/swarm/conn.go
+8
-3
net/swarm/swarm_test.go
net/swarm/swarm_test.go
+4
-2
No files found.
net/conn/multiconn.go
View file @
29ab6dec
...
...
@@ -132,6 +132,7 @@ func (c *MultiConn) fanOut() {
c
.
Children
()
.
Add
(
1
)
defer
c
.
Children
()
.
Done
()
i
:=
0
for
{
select
{
case
<-
c
.
Closing
()
:
...
...
@@ -140,6 +141,7 @@ func (c *MultiConn) fanOut() {
// send data out through our "best connection"
case
m
,
more
:=
<-
c
.
duplex
.
Out
:
if
!
more
{
log
.
Info
(
"%s out channel closed"
,
c
)
return
}
sc
:=
c
.
BestConn
()
...
...
@@ -147,6 +149,9 @@ func (c *MultiConn) fanOut() {
// maybe this should be a logged error, not a panic.
panic
(
"sending out multiconn without any live connection"
)
}
i
++
log
.
Info
(
"%s sending (%d)"
,
sc
,
i
)
sc
.
Out
()
<-
m
}
}
...
...
@@ -160,6 +165,8 @@ func (c *MultiConn) fanInSingle(child Conn) {
// cleanup all data associated with this child Connection.
defer
func
()
{
log
.
Info
(
"closing: %s"
,
child
)
// in case it still is in the map, remove it.
c
.
Lock
()
delete
(
c
.
conns
,
child
.
ID
())
...
...
@@ -174,6 +181,7 @@ func (c *MultiConn) fanInSingle(child Conn) {
}
}()
i
:=
0
for
{
select
{
case
<-
c
.
Closing
()
:
// multiconn closing
...
...
@@ -184,8 +192,11 @@ func (c *MultiConn) fanInSingle(child Conn) {
case
m
,
more
:=
<-
child
.
In
()
:
// receiving data
if
!
more
{
log
.
Info
(
"%s in channel closed"
,
child
)
return
// closed
}
i
++
log
.
Info
(
"%s received (%d)"
,
child
,
i
)
c
.
duplex
.
In
<-
m
}
}
...
...
net/swarm/conn.go
View file @
29ab6dec
...
...
@@ -136,6 +136,7 @@ func (s *Swarm) fanOut() {
s
.
Children
()
.
Add
(
1
)
defer
s
.
Children
()
.
Done
()
i
:=
0
for
{
select
{
case
<-
s
.
Closing
()
:
...
...
@@ -143,6 +144,7 @@ func (s *Swarm) fanOut() {
case
msg
,
ok
:=
<-
s
.
Outgoing
:
if
!
ok
{
log
.
Info
(
"%s outgoing channel closed"
,
s
)
return
}
...
...
@@ -157,8 +159,8 @@ func (s *Swarm) fanOut() {
continue
}
// log.Debug("[peer: %s] Sent message [to = %s]", s.local, msg.Peer())
i
++
log
.
Debug
(
"%s sent message to %s (%d)"
,
s
.
local
,
msg
.
Peer
(),
i
)
// queue it in the connection's buffer
c
.
Out
()
<-
msg
.
Data
()
}
...
...
@@ -182,6 +184,7 @@ func (s *Swarm) fanInSingle(c conn.Conn) {
c
.
Children
()
.
Done
()
// child of Conn as well.
}()
i
:=
0
for
{
select
{
case
<-
s
.
Closing
()
:
// Swarm closing
...
...
@@ -192,9 +195,11 @@ func (s *Swarm) fanInSingle(c conn.Conn) {
case
data
,
ok
:=
<-
c
.
In
()
:
if
!
ok
{
log
.
Info
(
"%s in channel closed"
,
c
)
return
// channel closed.
}
// log.Debug("[peer: %s] Received message [from = %s]", s.local, c.Peer)
i
++
log
.
Debug
(
"%s received message from %s (%d)"
,
s
.
local
,
c
.
RemotePeer
(),
i
)
s
.
Incoming
<-
msg
.
New
(
c
.
RemotePeer
(),
data
)
}
}
...
...
net/swarm/swarm_test.go
View file @
29ab6dec
...
...
@@ -16,6 +16,7 @@ import (
)
func
pong
(
ctx
context
.
Context
,
swarm
*
Swarm
)
{
i
:=
0
for
{
select
{
case
<-
ctx
.
Done
()
:
...
...
@@ -23,7 +24,8 @@ func pong(ctx context.Context, swarm *Swarm) {
case
m1
:=
<-
swarm
.
Incoming
:
if
bytes
.
Equal
(
m1
.
Data
(),
[]
byte
(
"ping"
))
{
m2
:=
msg
.
New
(
m1
.
Peer
(),
[]
byte
(
"pong"
))
log
.
Debug
(
"%s pong %s"
,
swarm
.
local
,
m1
.
Peer
())
i
++
log
.
Debug
(
"%s pong %s (%d)"
,
swarm
.
local
,
m1
.
Peer
(),
i
)
swarm
.
Outgoing
<-
m2
}
}
...
...
@@ -132,7 +134,7 @@ func SubtestSwarm(t *testing.T, addrs []string, MsgNum int) {
for
k
:=
0
;
k
<
MsgNum
;
k
++
{
for
_
,
p
:=
range
*
peers
{
log
.
Debug
(
"%s ping %s"
,
s1
.
local
,
p
)
log
.
Debug
(
"%s ping %s
(%d)
"
,
s1
.
local
,
p
,
k
)
s1
.
Outgoing
<-
msg
.
New
(
p
,
[]
byte
(
"ping"
))
}
}
...
...
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