Commit 3c559028 authored by Jeromy's avatar Jeromy

rewrite as single line defer logs

parent bae8b9f4
......@@ -120,12 +120,11 @@ func (bs *bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
ctx, cancelFunc := context.WithCancel(parent)
ctx = eventlog.ContextWithLoggable(ctx, eventlog.Uuid("GetBlockRequest"))
e := log.EventBegin(ctx, "GetBlockRequest", &k)
defer log.EventBegin(ctx, "GetBlockRequest", &k).Done()
log.Debugf("GetBlockRequestBegin")
defer func() {
cancelFunc()
e.Done()
log.Debugf("GetBlockRequestEnd")
}()
......
......@@ -81,8 +81,7 @@ func (s *secureSession) handshake(ctx context.Context, insecure io.ReadWriter) e
}
log.Debugf("handshake: %s <--start--> %s", s.localPeer, s.remotePeer)
e := log.EventBegin(ctx, "secureHandshake", s.localPeer)
defer e.Done()
defer log.EventBegin(ctx, "secureHandshake", s.localPeer).Done()
s.local.permanentPubKey = s.localKey.GetPublic()
myPubKeyBytes, err := s.local.permanentPubKey.Bytes()
......
......@@ -196,8 +196,7 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p peer.ID,
// getValueSingle simply performs the get value RPC with the given parameters
func (dht *IpfsDHT) getValueSingle(ctx context.Context, p peer.ID,
key u.Key) (*pb.Message, error) {
e := log.EventBegin(ctx, "getValueSingle", p, &key)
defer e.Done()
defer log.EventBegin(ctx, "getValueSingle", p, &key).Done()
pmes := pb.NewMessage(pb.Message_GET_VALUE, string(key), 0)
return dht.sendRequest(ctx, p, pmes)
......@@ -267,16 +266,14 @@ func (dht *IpfsDHT) FindLocal(id peer.ID) peer.PeerInfo {
// findPeerSingle asks peer 'p' if they know where the peer with id 'id' is
func (dht *IpfsDHT) findPeerSingle(ctx context.Context, p peer.ID, id peer.ID) (*pb.Message, error) {
e := log.EventBegin(ctx, "findPeerSingle", p, id)
defer e.Done()
defer log.EventBegin(ctx, "findPeerSingle", p, id).Done()
pmes := pb.NewMessage(pb.Message_FIND_NODE, string(id), 0)
return dht.sendRequest(ctx, p, pmes)
}
func (dht *IpfsDHT) findProvidersSingle(ctx context.Context, p peer.ID, key u.Key) (*pb.Message, error) {
e := log.EventBegin(ctx, "findProvidersSingle", p, &key)
defer e.Done()
defer log.EventBegin(ctx, "findProvidersSingle", p, &key).Done()
pmes := pb.NewMessage(pb.Message_GET_PROVIDERS, string(key), 0)
return dht.sendRequest(ctx, p, pmes)
......
......@@ -126,8 +126,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
log.Debugf("start", key)
defer log.Debugf("end", key)
e := log.EventBegin(ctx, "provide", &key)
defer e.Done()
defer log.EventBegin(ctx, "provide", &key).Done()
// add self locally
dht.providers.AddProvider(key, dht.self)
......@@ -246,8 +245,7 @@ func (dht *IpfsDHT) FindProvidersAsync(ctx context.Context, key u.Key, count int
func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key u.Key, count int, peerOut chan peer.PeerInfo) {
log := dht.log().Prefix("FindProviders(%s)", key)
e := log.EventBegin(ctx, "findProvidersAsync", &key)
defer e.Done()
defer log.EventBegin(ctx, "findProvidersAsync", &key).Done()
defer close(peerOut)
ps := pset.NewLimited(count)
......@@ -317,8 +315,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key u.Key, co
// FindPeer searches for a peer with given ID.
func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.PeerInfo, error) {
e := log.EventBegin(ctx, "FindPeer", id)
defer e.Done()
defer log.EventBegin(ctx, "FindPeer", id).Done()
// Check if were already connected to them
if pi := dht.FindLocal(id); pi.ID != "" {
......
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