mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-05-05 18:09:26 +00:00
add eligibility check in Lightpush protocol
This commit is contained in:
parent
d20f64f0f8
commit
5e038f6a4b
@ -1218,35 +1218,6 @@ proc lightpushPublish*(
|
|||||||
debug "in lightpushPublish"
|
debug "in lightpushPublish"
|
||||||
debug "eligibilityProof: ", eligibilityProof
|
debug "eligibilityProof: ", eligibilityProof
|
||||||
|
|
||||||
# FIXME: THIS SHOULD NOT BE CHECKED HERE!
|
|
||||||
# CHECKING ELIGIBILITY HERE MEANS CHECKING OUR OWN REQUEST BEFORE IT IS SENT
|
|
||||||
debug "in lightpushPublish"
|
|
||||||
debug "eligibilityProof: ", eligibilityProof
|
|
||||||
|
|
||||||
#[
|
|
||||||
if node.peerManager.eligibilityManager.isNone():
|
|
||||||
# the service node doesn't want to check eligibility
|
|
||||||
debug "eligibilityManager is disabled - skipping eligibility check"
|
|
||||||
else:
|
|
||||||
debug "eligibilityManager is enabled"
|
|
||||||
var em = node.peerManager.eligibilityManager.get()
|
|
||||||
|
|
||||||
try:
|
|
||||||
debug "checking eligibilityProof..."
|
|
||||||
|
|
||||||
# Check if eligibility proof is provided before accessing it
|
|
||||||
if eligibilityProof.isNone():
|
|
||||||
let msg = "Eligibility proof is required"
|
|
||||||
return lighpushErrorResult(PAYMENT_REQUIRED, msg)
|
|
||||||
|
|
||||||
let isEligible = await em.isEligibleTxId(eligibilityProof.get())
|
|
||||||
|
|
||||||
except CatchableError:
|
|
||||||
let msg = "Eligibility check threw exception: " & getCurrentExceptionMsg()
|
|
||||||
return lighpushErrorResult(PAYMENT_REQUIRED, msg)
|
|
||||||
|
|
||||||
debug "Eligibility check passed!"
|
|
||||||
]#
|
|
||||||
return await lightpushPublishHandler(node, pubsubForPublish, message, eligibilityProof, toPeer)
|
return await lightpushPublishHandler(node, pubsubForPublish, message, eligibilityProof, toPeer)
|
||||||
|
|
||||||
## Waku RLN Relay
|
## Waku RLN Relay
|
||||||
|
|||||||
@ -86,8 +86,48 @@ proc handleRequest*(
|
|||||||
msg_hash = msg_hash,
|
msg_hash = msg_hash,
|
||||||
receivedTime = getNowInNanosecondTime()
|
receivedTime = getNowInNanosecondTime()
|
||||||
|
|
||||||
# FIXME: pass eligibilityProof here??????
|
# Check eligibility if manager is available
|
||||||
# What is pushHandler, where is it defined?
|
if wl.peerManager.eligibilityManager.isSome():
|
||||||
|
debug "eligibilityManager is enabled"
|
||||||
|
let em = wl.peerManager.eligibilityManager.get()
|
||||||
|
|
||||||
|
try:
|
||||||
|
debug "checking eligibilityProof..."
|
||||||
|
|
||||||
|
# Check if eligibility proof is provided
|
||||||
|
if pushRequest.eligibilityProof.isNone():
|
||||||
|
let msg = "Eligibility proof is required"
|
||||||
|
error "lightpush request handling error", error = msg
|
||||||
|
return LightpushResponse(
|
||||||
|
requestId: pushRequest.requestId,
|
||||||
|
statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32,
|
||||||
|
statusDesc: some(msg),
|
||||||
|
)
|
||||||
|
|
||||||
|
let isEligible = await em.isEligibleTxId(pushRequest.eligibilityProof.get())
|
||||||
|
if isEligible.isErr():
|
||||||
|
let msg = "Eligibility check failed: " & isEligible.error
|
||||||
|
error "lightpush request handling error", error = msg
|
||||||
|
return LightpushResponse(
|
||||||
|
requestId: pushRequest.requestId,
|
||||||
|
statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32,
|
||||||
|
statusDesc: some(msg),
|
||||||
|
)
|
||||||
|
|
||||||
|
debug "Eligibility check passed!"
|
||||||
|
|
||||||
|
except CatchableError:
|
||||||
|
let msg = "Eligibility check threw exception: " & getCurrentExceptionMsg()
|
||||||
|
error "lightpush request handling error", error = msg
|
||||||
|
return LightpushResponse(
|
||||||
|
requestId: pushRequest.requestId,
|
||||||
|
statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32,
|
||||||
|
statusDesc: some(msg),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
# the service node doesn't want to check eligibility
|
||||||
|
debug "eligibilityManager is disabled - skipping eligibility check"
|
||||||
|
|
||||||
let handleRes = await wl.pushHandler(peerId, pubsubTopic, pushRequest.message)
|
let handleRes = await wl.pushHandler(peerId, pubsubTopic, pushRequest.message)
|
||||||
|
|
||||||
isSuccess = handleRes.isOk()
|
isSuccess = handleRes.isOk()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user