Harden network
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import requests_unixsocket as req
|
||||
|
||||
import config
|
||||
from time import sleep
|
||||
import socket
|
||||
import json
|
||||
|
||||
import logging
|
||||
|
||||
class Networking:
|
||||
def __init__(self, output_server_address, input_socket_address):
|
||||
self.retries = 0
|
||||
self.server_address = ""
|
||||
self.input_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.output_session = req.Session()
|
||||
@@ -16,7 +18,16 @@ class Networking:
|
||||
print("Connected to " + input_socket_address + " and started server " + self.server_address)
|
||||
|
||||
def get(self, path):
|
||||
response = self.output_session.get(self.server_address + path)
|
||||
if self.retries < config.MAX_NETWORK_RETRIES:
|
||||
logging.error("Network exception. Could not get " + path)
|
||||
|
||||
try:
|
||||
response = self.output_session.get(self.server_address + path)
|
||||
except Exception:
|
||||
self.retries += 1
|
||||
sleep(config.NETWORK_SLEEP_TIME)
|
||||
return self.get(path)
|
||||
|
||||
assert response.status_code == 200
|
||||
return response.content
|
||||
|
||||
|
||||
Reference in New Issue
Block a user