fix tx rx stats for web socket server and don't tx and rx when offline or detached
This commit is contained in:
@@ -22,6 +22,7 @@ class WebsocketClientInterface(Interface):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.owner = owner
|
self.owner = owner
|
||||||
|
self.parent_interface = None
|
||||||
|
|
||||||
self.IN = True
|
self.IN = True
|
||||||
self.OUT = False
|
self.OUT = False
|
||||||
@@ -57,25 +58,42 @@ class WebsocketClientInterface(Interface):
|
|||||||
# called when a full packet has been received over the websocket
|
# called when a full packet has been received over the websocket
|
||||||
def process_incoming(self, data):
|
def process_incoming(self, data):
|
||||||
|
|
||||||
|
# do nothing if offline or detached
|
||||||
|
if not self.online or self.detached:
|
||||||
|
return
|
||||||
|
|
||||||
# update received bytes counter
|
# update received bytes counter
|
||||||
self.rxb += len(data)
|
self.rxb += len(data)
|
||||||
|
|
||||||
|
# update received bytes counter for parent interface
|
||||||
|
if self.parent_interface is not None:
|
||||||
|
self.parent_interface.rxb += len(data)
|
||||||
|
|
||||||
# send received data to transport instance
|
# send received data to transport instance
|
||||||
self.owner.inbound(data, self)
|
self.owner.inbound(data, self)
|
||||||
|
|
||||||
# the running reticulum transport instance will call this method whenever the interface must transmit a packet
|
# the running reticulum transport instance will call this method whenever the interface must transmit a packet
|
||||||
def process_outgoing(self, data):
|
def process_outgoing(self, data):
|
||||||
|
|
||||||
# do nothing if not online
|
# do nothing if offline or detached
|
||||||
if not self.online:
|
if not self.online or self.detached:
|
||||||
return
|
return
|
||||||
|
|
||||||
# send to websocket server
|
# send to websocket server
|
||||||
self.websocket.send(data)
|
try:
|
||||||
|
self.websocket.send(data)
|
||||||
|
except Exception as e:
|
||||||
|
RNS.log(f"Exception occurred while transmitting via {str(self)}", RNS.LOG_ERROR)
|
||||||
|
RNS.log(f"The contained exception was: {str(e)}", RNS.LOG_ERROR)
|
||||||
|
return
|
||||||
|
|
||||||
# update sent bytes counter
|
# update sent bytes counter
|
||||||
self.txb += len(data)
|
self.txb += len(data)
|
||||||
|
|
||||||
|
# update received bytes counter for parent interface
|
||||||
|
if self.parent_interface is not None:
|
||||||
|
self.parent_interface.txb += len(data)
|
||||||
|
|
||||||
# connect to the configured websocket server
|
# connect to the configured websocket server
|
||||||
def connect(self):
|
def connect(self):
|
||||||
|
|
||||||
|
|||||||
@@ -71,14 +71,9 @@ class WebsocketServerInterface(Interface):
|
|||||||
if from_spawned:
|
if from_spawned:
|
||||||
self.oa_freq_deque.append(time.time())
|
self.oa_freq_deque.append(time.time())
|
||||||
|
|
||||||
# called when a full packet has been received from a websocket client
|
# do nothing as the spawned child interface will take care of rx/tx
|
||||||
def process_incoming(self, data):
|
def process_incoming(self, data):
|
||||||
|
pass
|
||||||
# Update our received bytes counter
|
|
||||||
self.rxb += len(data)
|
|
||||||
|
|
||||||
# And send the data packet to the Transport instance for processing.
|
|
||||||
self.owner.inbound(data, self)
|
|
||||||
|
|
||||||
# do nothing as the spawned child interface will take care of rx/tx
|
# do nothing as the spawned child interface will take care of rx/tx
|
||||||
def process_outgoing(self, data):
|
def process_outgoing(self, data):
|
||||||
|
|||||||
Reference in New Issue
Block a user