Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions logos_delivery/api/conf/modes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ type EntryLayer* {.pure.} = enum
channels # kernel + messaging + reliable channels

type AnonymityLevel* {.pure.} = enum
None
Preferred
Required
None ## Never use Mix. Send over the plain path, relay then lightpush.
Preferred ## Try Mix first. Use the plain path after the Mix window expires.
Required ## Use Mix only. Never use the plain path.
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ proc mixWindowElapsed(self: MixSendProcessor, task: DeliveryTask): bool =

method sendImpl*(self: MixSendProcessor, task: DeliveryTask): Future[void] {.async.} =
if self.mixWindowElapsed(task):
trace "Mix window elapsed, handing the task to the plain send path",
debug "Mix window elapsed",
requestId = task.requestId,
msgHash = task.msgHash.to0xHex(),
admissionAge = task.admissionAge()
task.state = DeliveryState.FallbackRetry
return

if not self.waku.mixReady():
trace "Mix cannot publish yet (not enough nodes for a path), retrying next round",
requestId = task.requestId, msgHash = task.msgHash.to0xHex()
debug "Mix not ready", requestId = task.requestId, msgHash = task.msgHash.to0xHex()
task.state = DeliveryState.NextRoundRetry
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,22 @@ proc setupSendProcessorChain(
let isRelayAvail = waku.hasRelay()
let isLightPushAvail = waku.hasLightpush()

if anonymityLevel != AnonymityLevel.None and not isLightPushAvail:
return err("Mix sending needs a lightpush client, which is not mounted")

if anonymityLevel != AnonymityLevel.Required and not isRelayAvail and
not isLightPushAvail:
return err("No valid send processor found for the delivery task")

var processors = newSeq[BaseSendProcessor]()

if anonymityLevel != AnonymityLevel.None:
case anonymityLevel
of AnonymityLevel.None:
discard
of AnonymityLevel.Preferred, AnonymityLevel.Required:
if not isLightPushAvail:
return err("Mix sending needs a lightpush client, which is not mounted")

let mixProcessor: BaseSendProcessor =
MixSendProcessor.new(waku, brokerCtx, anonymityLevel, MaxTimeInCache)
processors.add(mixProcessor)

if anonymityLevel == AnonymityLevel.Required:
return ok(mixProcessor)

processors.add(mixProcessor)

if isRelayAvail:
let publishProc = waku.relayPushHandler()
processors.add(
Expand All @@ -99,6 +98,9 @@ proc setupSendProcessorChain(
if isLightPushAvail:
processors.add(LightpushSendProcessor.new(waku, brokerCtx))

if processors.len == 0:
return err("No valid send processor found for the delivery task")

var currentProcessor: BaseSendProcessor = processors[0]
for i in 1 ..< processors.len:
currentProcessor.chain(processors[i])
Expand Down
Loading