mirror of
https://github.com/liamcottle/reticulum-meshchat.git
synced 2026-04-27 16:10:32 +00:00
fix tx rx stats for web socket server and don't tx and rx when offline or detached
This commit is contained in:
parent
b6e41b3027
commit
c0bb0763a1
2 changed files with 23 additions and 10 deletions
|
|
@ -22,6 +22,7 @@ class WebsocketClientInterface(Interface):
|
|||
super().__init__()
|
||||
|
||||
self.owner = owner
|
||||
self.parent_interface = None
|
||||
|
||||
self.IN = True
|
||||
self.OUT = False
|
||||
|
|
@ -57,25 +58,42 @@ class WebsocketClientInterface(Interface):
|
|||
# called when a full packet has been received over the websocket
|
||||
def process_incoming(self, data):
|
||||
|
||||
# do nothing if offline or detached
|
||||
if not self.online or self.detached:
|
||||
return
|
||||
|
||||
# update received bytes counter
|
||||
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
|
||||
self.owner.inbound(data, self)
|
||||
|
||||
# the running reticulum transport instance will call this method whenever the interface must transmit a packet
|
||||
def process_outgoing(self, data):
|
||||
|
||||
# do nothing if not online
|
||||
if not self.online:
|
||||
# do nothing if offline or detached
|
||||
if not self.online or self.detached:
|
||||
return
|
||||
|
||||
# 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
|
||||
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
|
||||
def connect(self):
|
||||
|
||||
|
|
|
|||
|
|
@ -71,14 +71,9 @@ class WebsocketServerInterface(Interface):
|
|||
if from_spawned:
|
||||
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):
|
||||
|
||||
# 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)
|
||||
pass
|
||||
|
||||
# do nothing as the spawned child interface will take care of rx/tx
|
||||
def process_outgoing(self, data):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue