From 29ab6dec6026b073af42edb5f3b3f244dd306e1c Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet <juan@benet.ai> Date: Sun, 19 Oct 2014 05:49:07 -0700 Subject: [PATCH] added msg counters to logs --- net/conn/multiconn.go | 11 +++++++++++ net/swarm/conn.go | 11 ++++++++--- net/swarm/swarm_test.go | 6 ++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/net/conn/multiconn.go b/net/conn/multiconn.go index 59c52b7f9..26c64be71 100644 --- a/net/conn/multiconn.go +++ b/net/conn/multiconn.go @@ -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 } } diff --git a/net/swarm/conn.go b/net/swarm/conn.go index 629e946a7..5abd77c44 100644 --- a/net/swarm/conn.go +++ b/net/swarm/conn.go @@ -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) } } diff --git a/net/swarm/swarm_test.go b/net/swarm/swarm_test.go index e05e36807..e778a4f57 100644 --- a/net/swarm/swarm_test.go +++ b/net/swarm/swarm_test.go @@ -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")) } } -- GitLab