From 1cf7375311352c213da324c8b463011e63121319 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sun, 18 Feb 2024 21:34:25 -0500 Subject: [PATCH] #309 cleanup --- coordinator/coordinator.lua | 2 +- coordinator/session/apisessions.lua | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/coordinator/coordinator.lua b/coordinator/coordinator.lua index 635de90..61ee56f 100644 --- a/coordinator/coordinator.lua +++ b/coordinator/coordinator.lua @@ -225,7 +225,7 @@ function coordinator.comms(version, nic, sv_watchdog) nic.open(config.CRD_Channel) -- pass config to apisessions - apisessions.init(nic, config.CRD_Channel, config.PKT_Channel, config.API_Timeout) + apisessions.init(nic, config) -- PRIVATE FUNCTIONS -- diff --git a/coordinator/session/apisessions.lua b/coordinator/session/apisessions.lua index b4e1a30..516b91b 100644 --- a/coordinator/session/apisessions.lua +++ b/coordinator/session/apisessions.lua @@ -10,10 +10,8 @@ local pocket = require("coordinator.session.pocket") local apisessions = {} local self = { - nic = nil, ---@type nic - crd_channel = nil, ---@type integer - pkt_channel = nil, ---@type integer - api_timeout = nil, ---@type number + nic = nil, ---@type nic + config = nil, ---@type crd_config next_id = 0, sessions = {} } @@ -34,7 +32,7 @@ local function _api_handle_outq(session) if msg ~= nil then if msg.qtype == mqueue.TYPE.PACKET then -- handle a packet to be sent - self.nic.transmit(self.pkt_channel, self.crd_channel, msg.message) + self.nic.transmit(self.config.PKT_Channel, self.config.CRD_Channel, msg.message) elseif msg.qtype == mqueue.TYPE.COMMAND then -- handle instruction/notification elseif msg.qtype == mqueue.TYPE.DATA then @@ -61,7 +59,7 @@ local function _shutdown(session) while session.out_queue.ready() do local msg = session.out_queue.pop() if msg ~= nil and msg.qtype == mqueue.TYPE.PACKET then - self.nic.transmit(self.pkt_channel, self.crd_channel, msg.message) + self.nic.transmit(self.config.PKT_Channel, self.config.CRD_Channel, msg.message) end end @@ -72,14 +70,10 @@ end -- initialize apisessions ---@param nic nic network interface ----@param crd_channel integer coordinator channel ----@param pkt_channel integer pocket channel ----@param api_timeout number api session timeout -function apisessions.init(nic, crd_channel, pkt_channel, api_timeout) +---@param config crd_config coordinator config +function apisessions.init(nic, config) self.nic = nic - self.crd_channel = crd_channel - self.pkt_channel = pkt_channel - self.api_timeout = api_timeout + self.config = config end -- find a session by remote port @@ -111,7 +105,7 @@ function apisessions.establish_session(source_addr, version) local id = self.next_id - pkt_s.instance = pocket.new_session(id, source_addr, pkt_s.in_queue, pkt_s.out_queue, self.api_timeout) + pkt_s.instance = pocket.new_session(id, source_addr, pkt_s.in_queue, pkt_s.out_queue, self.config.API_Timeout) table.insert(self.sessions, pkt_s) local mt = {