From 735f5f95cd85652e6dad11765a73719c6d76bdee Mon Sep 17 00:00:00 2001 From: Fate-JH Date: Mon, 10 Jul 2023 20:01:37 -0400 Subject: [PATCH] missing subslots is now a self message rather than an anonymous callback --- .../actors/net/MiddlewareActor.scala | 84 +++++++++++-------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/src/main/scala/net/psforever/actors/net/MiddlewareActor.scala b/src/main/scala/net/psforever/actors/net/MiddlewareActor.scala index 9ea0b6d6e..1c77da575 100644 --- a/src/main/scala/net/psforever/actors/net/MiddlewareActor.scala +++ b/src/main/scala/net/psforever/actors/net/MiddlewareActor.scala @@ -108,7 +108,10 @@ object MiddlewareActor { final case class Close() extends Command /** ... */ - private case class ProcessQueue() extends Command + private case object ProcessQueue extends Command + + /** ... */ + private case object ProcessMissingSubslots extends Command /** Log inbound packets that are yet to be in proper order by sequence number */ private case class InReorderEntry(packet: PlanetSidePacket, sequence: Int, time: Long) @@ -426,7 +429,7 @@ class MiddlewareActor( packetProcessorDelay, packetProcessorDelay )(() => { - context.self ! ProcessQueue() + context.self ! ProcessQueue }) active() @@ -480,10 +483,14 @@ class MiddlewareActor( } Behaviors.same - case ProcessQueue() => + case ProcessQueue => processQueue() Behaviors.same + case ProcessMissingSubslots => + processRequestsForMissingSubslots() + Behaviors.same + case Teardown() => send(TeardownConnection(clientNonce)) context.self ! Close() @@ -843,6 +850,24 @@ class MiddlewareActor( */ private var activeSubslotsFunc: (Int, Int, ByteVector) => Unit = inSubslotNotMissing + /** + * Start making requests for missing `SlottedMetaPackets` + * if no prior requests were prepared. + * Start the scheduled task and handle the dispatched requests. + * @see `processRequestsForMissingSubslots` + */ + def askForMissingSubslots(): Unit = { + if (subslotMissingProcessor.isCancelled) { + subslotMissingProcessor = context.system.scheduler.scheduleWithFixedDelay( + inSubslotMissingDelay, + inSubslotMissingDelay + )(() => { + context.self ! ProcessMissingSubslots + }) + processRequestsForMissingSubslots() //perform immediately + } + } + /** * What to do with a `SlottedMetaPacket` control packet normally. * The typical approach, when the subslot is the expected next number, is to merely receive the packet @@ -875,6 +900,27 @@ class MiddlewareActor( } } + /** + * Make requests for missing `SlottedMetaPackets`. + * @see `inSubslotsMissingRequestFuncs` + * @see `inSubslotsMissingRequestsFinished` + * @see `RelatedA` + */ + def processRequestsForMissingSubslots(): Unit = { + timesSubslotMissing += inSubslotsMissing.size + inSubslotsMissing.foreach { + case (subslot, attempt) => + val value = attempt - 1 + if (value > 0) { + inSubslotsMissing(subslot) = value + } else { + inSubslotsMissing.remove(subslot) + } + send(RelatedA(0, subslot)) + } + inSubslotsMissingRequestsFinished() + } + /** * What to do with an inbound `SlottedMetaPacket` control packet when the subslots are in disarray. * Whenever a subslot arrives prior to the current highest, removing that subslot from the request list is possible. @@ -918,38 +964,6 @@ class MiddlewareActor( } } - /** - * Start making requests for missing `SlotedMetaPackets` - * if no prior requests were prepared. - * Start the scheduled task and handle the dispatched requests. - * @see `inSubslotsMissingRequestFuncs` - * @see `inSubslotsMissingRequestsFinished` - * @see `RelatedA` - */ - def askForMissingSubslots(): Unit = { - if (subslotMissingProcessor.isCancelled) { - subslotMissingProcessor = context.system.scheduler.scheduleWithFixedDelay( - initialDelay = 0.milliseconds, - inSubslotMissingDelay - )(() => { - inSubslotsMissing.synchronized { - timesSubslotMissing += inSubslotsMissing.size - inSubslotsMissing.foreach { - case (subslot, attempt) => - val value = attempt - 1 - if (value > 0) { - inSubslotsMissing(subslot) = value - } else { - inSubslotsMissing.remove(subslot) - } - send(RelatedA(0, subslot)) - } - inSubslotsMissingRequestsFinished() - } - }) - } - } - /** * Split packet into multiple chunks (if necessary). * Split packets are wrapped in a `HandleGamePacket` and sent as `SlottedMetaPacket4`.