mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-11 18:33:09 +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 "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)
|
||||
|
||||
## Waku RLN Relay
|
||||
|
||||
@ -86,8 +86,48 @@ proc handleRequest*(
|
||||
msg_hash = msg_hash,
|
||||
receivedTime = getNowInNanosecondTime()
|
||||
|
||||
# FIXME: pass eligibilityProof here??????
|
||||
# What is pushHandler, where is it defined?
|
||||
# Check eligibility if manager is available
|
||||
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)
|
||||
|
||||
isSuccess = handleRes.isOk()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user