Commit 0fc95d5a authored by Brian Tiger Chow's avatar Brian Tiger Chow

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

+ netmessage is now loggable

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 3ed9b0c4
......@@ -10,6 +10,7 @@ import (
type NetMessage interface {
Peer() peer.Peer
Data() []byte
Loggable() map[string]interface{}
}
// New is the interface for constructing a new message.
......@@ -35,6 +36,16 @@ func (m *message) Data() []byte {
return m.data
}
func (m *message) Loggable() map[string]interface{} {
return map[string]interface{}{
"netMessage": map[string]interface{}{
"recipient": m.Peer(),
// TODO sizeBytes? bytes? lenBytes?
"size": len(m.Data()),
},
}
}
// FromObject creates a message from a protobuf-marshallable message.
func FromObject(p peer.Peer, data proto.Message) (NetMessage, error) {
bytes, err := proto.Marshal(data)
......
......@@ -122,7 +122,6 @@ func (s *Swarm) peerMultiConn(p peer.Peer) (*conn.MultiConn, error) {
s.Children().Add(1)
mc.Children().Add(1) // child of Conn as well.
go s.fanInSingle(mc)
log.Debugf("added new multiconn: %s", mc)
return mc, nil
}
......@@ -133,7 +132,7 @@ func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
return nil, errors.New("Tried to start nil connection.")
}
log.Debugf("%s Started connection: %s", c.LocalPeer(), c.RemotePeer())
log.Event(context.TODO(), "connSetupBegin", c.LocalPeer(), c.RemotePeer())
// add address of connection to Peer. Maybe it should happen in connSecure.
// 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) {
return nil, err
}
mc.Add(c)
log.Debugf("multiconn added new conn %s", c)
log.Event(context.TODO(), "connSetupSuccess", c.LocalPeer(), c.RemotePeer())
return c, nil
}
......@@ -200,6 +198,7 @@ func (s *Swarm) fanOut() {
i++
log.Debugf("%s sent message to %s (%d)", s.local, msg.Peer(), i)
log.Event(context.TODO(), "sendMessage", s.local, msg)
// queue it in the connection's buffer
c.Out() <- msg.Data()
}
......
......@@ -151,6 +151,8 @@ func (s *Swarm) Dial(peer peer.Peer) (conn.Conn, error) {
return nil, err
}
// TODO replace the TODO ctx with a context passed in from caller
log.Event(context.TODO(), "dial", peer)
return c, nil
}
......
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