daemon: moved SetQeueue into utils to be leveraged by others, updated MoveNodesStreamer to leverage SetQueue, this will allow a means to stream node movements, but if position changes happen faster than processing, the latest position will override prior pushes and the latest position will be pulled off the queue

This commit is contained in:
Blake Harnden 2022-04-28 16:12:31 -07:00
parent fe0bc2b405
commit aa8ea40ce6
4 changed files with 36 additions and 23 deletions

View file

@ -4,9 +4,7 @@ Defines network nodes used within core.
import logging
import threading
from collections import OrderedDict
from pathlib import Path
from queue import Queue
from typing import TYPE_CHECKING, Dict, List, Optional, Type
import netaddr
@ -32,22 +30,6 @@ if TYPE_CHECKING:
LEARNING_DISABLED: int = 0
class SetQueue(Queue):
"""
Set backed queue to avoid duplicate submissions.
"""
def _init(self, maxsize):
self.queue: OrderedDict = OrderedDict()
def _put(self, item):
self.queue[item] = None
def _get(self):
key, _ = self.queue.popitem(last=False)
return key
class NftablesQueue:
"""
Helper class for queuing up nftables commands into rate-limited
@ -72,7 +54,7 @@ class NftablesQueue:
# list of pending nftables commands
self.cmds: List[str] = []
# list of WLANs requiring update
self.updates: SetQueue = SetQueue()
self.updates: utils.SetQueue = utils.SetQueue()
def start(self) -> None:
"""