mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-02-05 06:23:28 +00:00
restore things mistakenly removed during merge
This commit is contained in:
parent
4e8de55de0
commit
fcdf674726
@ -249,11 +249,13 @@ proc selectPeer*(
|
||||
var preSelectedPeers =
|
||||
if pm.reputationManager.isSome():
|
||||
debug "Reputation enabled: consider only non-negative reputation peers"
|
||||
# FIXME: remove double loop
|
||||
for peer in peers:
|
||||
let rep = try:
|
||||
pm.reputationManager.get().getReputation(peer.peerId)
|
||||
except KeyError:
|
||||
none(bool)
|
||||
debug "Peer with reputation:", peer=peer, reputation=rep
|
||||
peers.filterIt:
|
||||
let rep =
|
||||
try:
|
||||
|
||||
@ -16,7 +16,8 @@ import
|
||||
./rpc,
|
||||
./rpc_codec,
|
||||
./protocol_metrics,
|
||||
../common/rate_limit/request_limiter
|
||||
../common/rate_limit/request_limiter,
|
||||
../incentivization/[eligibility_manager, rpc]
|
||||
|
||||
logScope:
|
||||
topics = "waku lightpush"
|
||||
@ -89,6 +90,48 @@ proc handleRequest*(
|
||||
statusDesc: some(desc),
|
||||
)
|
||||
|
||||
# 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: LightPushErrorCode.PAYMENT_REQUIRED,
|
||||
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: LightPushErrorCode.PAYMENT_REQUIRED,
|
||||
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: LightPushErrorCode.PAYMENT_REQUIRED,
|
||||
statusDesc: some(msg),
|
||||
)
|
||||
else:
|
||||
# the service node doesn't want to check eligibility
|
||||
debug "eligibilityManager is disabled - skipping eligibility check"
|
||||
|
||||
let relayPeerCount = (await handleRequest(wl, peerId, pushRequest)).valueOr:
|
||||
let desc = error.desc
|
||||
waku_lightpush_v3_errors.inc(labelValues = [$error.code])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user