Skip to content

Commit

Permalink
Merge pull request #185 from r4f4ss/log_trace
Browse files Browse the repository at this point in the history
Replace log trace strings to easily readable
  • Loading branch information
r4f4ss authored Oct 9, 2024
2 parents 1446e66 + b4bbdce commit 4605c46
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions p2p/discover/portal_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func (p *PortalProtocol) pingInner(node *enode.Node) (*portalwire.Pong, error) {
CustomPayload: customPayloadBytes,
}

p.Log.Trace("Sending ping request", "protocol", p.protocolName, "ip", p.Self().IP().String(), "source", p.Self().ID(), "target", node.ID(), "ping", pingRequest)
p.Log.Trace(">> PING/"+p.protocolName, "protocol", p.protocolName, "ip", p.Self().IP().String(), "source", p.Self().ID(), "target", node.ID(), "ping", pingRequest)
pingRequestBytes, err := pingRequest.MarshalSSZ()
if err != nil {
return nil, err
Expand All @@ -443,7 +443,7 @@ func (p *PortalProtocol) pingInner(node *enode.Node) (*portalwire.Pong, error) {
return nil, err
}

p.Log.Trace("Received ping response", "source", p.Self().ID(), "target", node.ID(), "res", talkResp)
p.Log.Trace("<< PONG/"+p.protocolName, "source", p.Self().ID(), "target", node.ID(), "res", talkResp)

return p.processPong(node, talkResp)
}
Expand All @@ -462,7 +462,7 @@ func (p *PortalProtocol) findNodes(node *enode.Node, distances []uint) ([]*enode
Distances: distancesBytes,
}

p.Log.Trace("Sending find nodes request", "id", node.ID(), "findNodes", findNodes)
p.Log.Trace(">> FIND_NODES/"+p.protocolName, "id", node.ID(), "findNodes", findNodes)
findNodesBytes, err := findNodes.MarshalSSZ()
if err != nil {
p.Log.Error("failed to marshal find nodes request", "err", err)
Expand All @@ -487,7 +487,7 @@ func (p *PortalProtocol) findContent(node *enode.Node, contentKey []byte) (byte,
ContentKey: contentKey,
}

p.Log.Trace("Sending find content request", "id", node.ID(), "findContent", findContent)
p.Log.Trace(">> FIND_CONTENT/"+p.protocolName, "id", node.ID(), "findContent", findContent)
findContentBytes, err := findContent.MarshalSSZ()
if err != nil {
p.Log.Error("failed to marshal find content request", "err", err)
Expand All @@ -514,7 +514,7 @@ func (p *PortalProtocol) offer(node *enode.Node, offerRequest *OfferRequest) ([]
ContentKeys: contentKeys,
}

p.Log.Trace("Sending offer request", "offer", offer)
p.Log.Trace(">> OFFER/"+p.protocolName, "offer", offer)
offerBytes, err := offer.MarshalSSZ()
if err != nil {
p.Log.Error("failed to marshal offer request", "err", err)
Expand Down Expand Up @@ -552,7 +552,7 @@ func (p *PortalProtocol) processOffer(target *enode.Node, resp []byte, request *
return nil, err
}

p.Log.Trace("Received accept response", "id", target.ID(), "accept", accept)
p.Log.Trace("<< ACCEPT/"+p.protocolName, "id", target.ID(), "accept", accept)
p.table.addFoundNode(target, true)

var contentKeyLen int
Expand Down Expand Up @@ -643,7 +643,7 @@ func (p *PortalProtocol) processOffer(target *enode.Node, resp []byte, request *
p.Log.Error("failed to write to utp connection", "err", err)
return
}
p.Log.Trace("Sent content response", "id", target.ID(), "contents", contents, "size", written)
p.Log.Trace(">> CONTENT/"+p.protocolName, "id", target.ID(), "contents", contents, "size", written)
return
}
}
Expand Down Expand Up @@ -672,7 +672,7 @@ func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte,
return 0xff, nil, err
}

p.Log.Trace("Received content response", "id", target.ID(), "content", content)
p.Log.Trace("<< CONTENT/"+p.protocolName, "id", target.ID(), "content", content)
p.table.addFoundNode(target, true)
return resp[1], content.Content, nil
case portalwire.ContentConnIdSelector:
Expand All @@ -682,7 +682,7 @@ func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte,
return 0xff, nil, err
}

p.Log.Trace("Received returned content response", "id", target.ID(), "resp", common.Bytes2Hex(resp), "connIdMsg", connIdMsg)
p.Log.Trace("<< CONTENT_CONNECTION_ID/"+p.protocolName, "id", target.ID(), "resp", common.Bytes2Hex(resp), "connIdMsg", connIdMsg)
p.table.addFoundNode(target, true)
connctx, conncancel := context.WithTimeout(p.closeCtx, defaultUTPConnectTimeout)
laddr := p.utp.Addr().(*utp.Addr)
Expand Down Expand Up @@ -714,7 +714,7 @@ func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte,
p.Log.Error("failed to read from utp connection", "err", err)
return 0xff, nil, err
}
p.Log.Trace("Received content response", "id", target.ID(), "size", len(data), "data", data)
p.Log.Trace("<< CONTENT/"+p.protocolName, "id", target.ID(), "size", len(data), "data", data)
return resp[1], data, nil
case portalwire.ContentEnrsSelector:
enrs := &portalwire.Enrs{}
Expand All @@ -724,7 +724,7 @@ func (p *PortalProtocol) processContent(target *enode.Node, resp []byte) (byte,
return 0xff, nil, err
}

p.Log.Trace("Received content response", "id", target.ID(), "enrs", enrs)
p.Log.Trace("<< CONTENT_ENRS/"+p.protocolName, "id", target.ID(), "enrs", enrs)
p.table.addFoundNode(target, true)
nodes := p.filterNodes(target, enrs.Enrs, nil)
return resp[1], nodes, nil
Expand Down Expand Up @@ -779,7 +779,7 @@ func (p *PortalProtocol) filterNodes(target *enode.Node, enrs [][]byte, distance
nodes = append(nodes, n)
}

p.Log.Trace("Received nodes response", "id", target.ID(), "total", len(enrs), "verified", verified, "nodes", nodes)
p.Log.Trace("<< NODES/"+p.protocolName, "id", target.ID(), "total", len(enrs), "verified", verified, "nodes", nodes)
return nodes
}

Expand All @@ -796,15 +796,15 @@ func (p *PortalProtocol) processPong(target *enode.Node, resp []byte) (*portalwi
return nil, err
}

p.Log.Trace("Received pong response", "id", target.ID(), "pong", pong)
p.Log.Trace("<< PONG_RESPONSE/"+p.protocolName, "id", target.ID(), "pong", pong)

customPayload := &portalwire.PingPongCustomData{}
err = customPayload.UnmarshalSSZ(pong.CustomPayload)
if err != nil {
return nil, err
}

p.Log.Trace("Received pong response", "id", target.ID(), "pong", pong, "customPayload", customPayload)
p.Log.Trace("<< PONG_RESPONSE/"+p.protocolName, "id", target.ID(), "pong", pong, "customPayload", customPayload)
p.table.addFoundNode(target, true)

p.radiusCache.Set([]byte(target.ID().String()), customPayload.Radius)
Expand Down Expand Up @@ -839,7 +839,7 @@ func (p *PortalProtocol) handleTalkRequest(id enode.ID, addr *net.UDPAddr, msg [
return nil
}

p.Log.Trace("received ping request", "protocol", p.protocolName, "source", id, "pingRequest", pingRequest)
p.Log.Trace("<< PING/"+p.protocolName, "protocol", p.protocolName, "source", id, "pingRequest", pingRequest)
resp, err := p.handlePing(id, pingRequest)
if err != nil {
p.Log.Error("failed to handle ping request", "err", err)
Expand All @@ -855,7 +855,7 @@ func (p *PortalProtocol) handleTalkRequest(id enode.ID, addr *net.UDPAddr, msg [
return nil
}

p.Log.Trace("received find nodes request", "protocol", p.protocolName, "source", id, "findNodesRequest", findNodesRequest)
p.Log.Trace("<< FIND_NODES/"+p.protocolName, "protocol", p.protocolName, "source", id, "findNodesRequest", findNodesRequest)
resp, err := p.handleFindNodes(addr, findNodesRequest)
if err != nil {
p.Log.Error("failed to handle find nodes request", "err", err)
Expand All @@ -871,7 +871,7 @@ func (p *PortalProtocol) handleTalkRequest(id enode.ID, addr *net.UDPAddr, msg [
return nil
}

p.Log.Trace("received find content request", "protocol", p.protocolName, "source", id, "findContentRequest", findContentRequest)
p.Log.Trace("<< FIND_NODES/"+p.protocolName, "protocol", p.protocolName, "source", id, "findContentRequest", findContentRequest)
resp, err := p.handleFindContent(id, addr, findContentRequest)
if err != nil {
p.Log.Error("failed to handle find content request", "err", err)
Expand All @@ -887,7 +887,7 @@ func (p *PortalProtocol) handleTalkRequest(id enode.ID, addr *net.UDPAddr, msg [
return nil
}

p.Log.Trace("received offer request", "protocol", p.protocolName, "source", id, "offerRequest", offerRequest)
p.Log.Trace("<< OFFER/"+p.protocolName, "protocol", p.protocolName, "source", id, "offerRequest", offerRequest)
resp, err := p.handleOffer(id, addr, offerRequest)
if err != nil {
p.Log.Error("failed to handle offer request", "err", err)
Expand Down Expand Up @@ -928,7 +928,7 @@ func (p *PortalProtocol) handlePing(id enode.ID, ping *portalwire.Ping) ([]byte,
CustomPayload: pongCustomPayloadBytes,
}

p.Log.Trace("Sending pong response", "protocol", p.protocolName, "source", id, "pong", pong)
p.Log.Trace(">> PONG/"+p.protocolName, "protocol", p.protocolName, "source", id, "pong", pong)
pongBytes, err := pong.MarshalSSZ()

if err != nil {
Expand Down Expand Up @@ -961,7 +961,7 @@ func (p *PortalProtocol) handleFindNodes(fromAddr *net.UDPAddr, request *portalw
Enrs: enrs,
}

p.Log.Trace("Sending nodes response", "protocol", p.protocolName, "source", fromAddr, "nodes", nodesMsg)
p.Log.Trace(">> NODES/"+p.protocolName, "protocol", p.protocolName, "source", fromAddr, "nodes", nodesMsg)
nodesMsgBytes, err := nodesMsg.MarshalSSZ()
if err != nil {
return nil, err
Expand Down Expand Up @@ -1012,7 +1012,7 @@ func (p *PortalProtocol) handleFindContent(id enode.ID, addr *net.UDPAddr, reque
Enrs: enrs,
}

p.Log.Trace("Sending enrs content response", "protocol", p.protocolName, "source", addr, "enrs", enrsMsg)
p.Log.Trace(">> CONTENT_ENRS/"+p.protocolName, "protocol", p.protocolName, "source", addr, "enrs", enrsMsg)
var enrsMsgBytes []byte
enrsMsgBytes, err = enrsMsg.MarshalSSZ()
if err != nil {
Expand All @@ -1033,7 +1033,7 @@ func (p *PortalProtocol) handleFindContent(id enode.ID, addr *net.UDPAddr, reque
Content: content,
}

p.Log.Trace("Sending raw content response", "protocol", p.protocolName, "source", addr, "content", rawContentMsg)
p.Log.Trace(">> CONTENT_RAW/"+p.protocolName, "protocol", p.protocolName, "source", addr, "content", rawContentMsg)

var rawContentMsgBytes []byte
rawContentMsgBytes, err = rawContentMsg.MarshalSSZ()
Expand Down Expand Up @@ -1106,7 +1106,7 @@ func (p *PortalProtocol) handleFindContent(id enode.ID, addr *net.UDPAddr, reque
Id: idBuffer,
}

p.Log.Trace("Sending connection id content response", "protocol", p.protocolName, "source", addr, "connId", connIdMsg)
p.Log.Trace(">> CONTENT_CONNECTION_ID/"+p.protocolName, "protocol", p.protocolName, "source", addr, "connId", connIdMsg)
var connIdMsgBytes []byte
connIdMsgBytes, err = connIdMsg.MarshalSSZ()
if err != nil {
Expand Down Expand Up @@ -1134,7 +1134,7 @@ func (p *PortalProtocol) handleOffer(id enode.ID, addr *net.UDPAddr, request *po
ContentKeys: contentKeyBitlist,
}

p.Log.Trace("Sending accept response", "protocol", p.protocolName, "source", addr, "accept", acceptMsg)
p.Log.Trace(">> ACCEPT/"+p.protocolName, "protocol", p.protocolName, "source", addr, "accept", acceptMsg)
var acceptMsgBytes []byte
acceptMsgBytes, err = acceptMsg.MarshalSSZ()
if err != nil {
Expand Down Expand Up @@ -1209,7 +1209,7 @@ func (p *PortalProtocol) handleOffer(id enode.ID, addr *net.UDPAddr, request *po
p.Log.Error("failed to read from utp connection", "err", err)
return
}
p.Log.Trace("Received offer content response", "id", id, "size", len(data), "data", data)
p.Log.Trace("<< OFFER_CONTENT/"+p.protocolName, "id", id, "size", len(data), "data", data)

err = p.handleOfferedContents(id, contentKeys, data)
if err != nil {
Expand All @@ -1232,7 +1232,7 @@ func (p *PortalProtocol) handleOffer(id enode.ID, addr *net.UDPAddr, request *po
ContentKeys: []byte(contentKeyBitlist),
}

p.Log.Trace("Sending accept response", "protocol", p.protocolName, "source", addr, "accept", acceptMsg)
p.Log.Trace(">> ACCEPT/"+p.protocolName, "protocol", p.protocolName, "source", addr, "accept", acceptMsg)
var acceptMsgBytes []byte
acceptMsgBytes, err = acceptMsg.MarshalSSZ()
if err != nil {
Expand Down

0 comments on commit 4605c46

Please sign in to comment.