Commit 29ab6dec authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

added msg counters to logs

parent 63d6ee6d
......@@ -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
}
}
......
......@@ -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)
}
}
......
......@@ -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"))
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment