@cryptotaxi247 / kubo / commits / 0fc95d5ad

log(swarm, netmessage) Event: connSetup(begin|success)

+ netmessage is now loggable License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Nov 25, 2014 at 04:45 UTC 0fc95d5add39a3c5341e05348bc76294f239ba93
3 files changed +16 -4
net/message/message.go
+11
@@ -10,6 +10,7 @@ import (
10 type NetMessage interface {
11 Peer() peer.Peer
12 Data() []byte
13 + Loggable() map[string]interface{}
14 }
15
16 // New is the interface for constructing a new message.
@@ -35,6 +36,16 @@ func (m *message) Data() []byte {
36 return m.data
37 }
38
39 +func (m *message) Loggable() map[string]interface{} {
40 + return map[string]interface{}{
41 + "netMessage": map[string]interface{}{
42 + "recipient": m.Peer(),
43 + // TODO sizeBytes? bytes? lenBytes?
44 + "size": len(m.Data()),
45 + },
46 + }
47 +}
48 +
49 // FromObject creates a message from a protobuf-marshallable message.
50 func FromObject(p peer.Peer, data proto.Message) (NetMessage, error) {
51 bytes, err := proto.Marshal(data)
net/swarm/conn.go
+3 -4
@@ -122,7 +122,6 @@ func (s *Swarm) peerMultiConn(p peer.Peer) (*conn.MultiConn, error) {
122 s.Children().Add(1)
123 mc.Children().Add(1) // child of Conn as well.
124 go s.fanInSingle(mc)
125 - log.Debugf("added new multiconn: %s", mc)
125 return mc, nil
126 }
127
@@ -133,7 +132,7 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
132 return nil, errors.New("Tried to start nil connection.")
133 }
134
136 - log.Debugf("%s Started connection: %s", c.LocalPeer(), c.RemotePeer())
135 + log.Event(context.TODO(), "connSetupBegin", c.LocalPeer(), c.RemotePeer())
136
137 // add address of connection to Peer. Maybe it should happen in connSecure.
138 // NOT adding this address here, because the incoming address in TCP
@@ -163,8 +162,7 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
162 return nil, err
163 }
164 mc.Add(c)
166 - log.Debugf("multiconn added new conn %s", c)
167 -
165 + log.Event(context.TODO(), "connSetupSuccess", c.LocalPeer(), c.RemotePeer())
166 return c, nil
167 }
168
@@ -200,6 +198,7 @@ func (s *Swarm) fanOut() {
198
199 i++
200 log.Debugf("%s sent message to %s (%d)", s.local, msg.Peer(), i)
201 + log.Event(context.TODO(), "sendMessage", s.local, msg)
202 // queue it in the connection's buffer
203 c.Out() <- msg.Data()
204 }
net/swarm/swarm.go
+2
@@ -151,6 +151,8 @@ func (s *Swarm) Dial(peer peer.Peer) (conn.Conn, error) {
151 return nil, err
152 }
153
154 + // TODO replace the TODO ctx with a context passed in from caller
155 + log.Event(context.TODO(), "dial", peer)
156 return c, nil
157 }
158