Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivansete-status committed Apr 30, 2024
1 parent e3ce42c commit 3d400a4
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions waku/waku_lightpush/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ proc handleRequest*(

if reqDecodeRes.isErr():
pushResponseInfo = decodeRpcFailure & ": " & $reqDecodeRes.error
# error "bad lightpush request", error = $reqDecodeRes.error
elif reqDecodeRes.get().request.isNone():
pushResponseInfo = emptyRequestBodyFailure
# error "lightpush request is none"
elif wl.requestRateLimiter.isSome() and not wl.requestRateLimiter.get().tryConsume(1):
isRejectedDueRateLimit = true
let pushRpcRequest = reqDecodeRes.get()
debug "lightpush request rejected due rate limit exceeded",
peerId = peerId, requestId = pushRpcRequest.requestId
# debug "lightpush request rejected due rate limit exceeded",
# peerid = peerId, requestId = pushRpcRequest.requestId
pushResponseInfo = TooManyRequestsMessage
waku_service_requests_rejected.inc(labelValues = ["Lightpush"])
else:
Expand All @@ -60,14 +62,25 @@ proc handleRequest*(
pubSubTopic = request.get().pubSubTopic
message = request.get().message
waku_lightpush_messages.inc(labelValues = ["PushRequest"])
debug "push request",
peerId = peerId,
requestId = requestId,
pubsubTopic = pubsubTopic,
hash = pubsubTopic.computeMessageHash(message).to0xHex()

# let msgHash = pubsubTopic.computeMessageHash(message).to0xHex()

# debug "lightpush request",
# peerId = peerId,
# requestId = requestId,
# pubsubTopic = pubsubTopic,
# msg_hash = msgHash

let handleRes = await wl.pushHandler(peerId, pubsubTopic, message)
isSuccess = handleRes.isOk()

# if isSuccess:
# debug "lightpush request processed correctly",
# lightpush_client_peer_id = shortLog(peerId),
# requestId = requestId,
# pubsubTopic = pubsubTopic,
# msg_hash = msgHash

pushResponseInfo = (if isSuccess: "OK" else: handleRes.error)

if not isSuccess and not isRejectedDueRateLimit:
Expand Down

0 comments on commit 3d400a4

Please sign in to comment.