def create_socket(ip: str, port: int, context: ssl.SSLContext = None, timeout: int = 10): """ Creates a new SSL-wrapped socket. :param ip: The IP to connect to. :param port: The port to connect to. :param context: The SSL context to use, or None for a default one to be created. :param timeout: The timeout for recv(). :return: A new SSLSocket. """ return gutsama.create_socket(ip, port, context, False, timeout)
from solebaga.tasks import connection # --> Init app logger.info("All --> Loading application...") init.core_init(app) # --> Load language logger.info("All --> Loading language files...") language.load_all() # --> Check status of Gutsama logger.info("All --> Synchronising with Gutsama...") for server in app.config.get("SERVERS", []): logger.info("Pinging server {}".format(server["name"])) try: sock = create_socket(server["ip"], server["port"], verify_hostname=app.config.get("SERVER_LOGIN_ON_CLIENT_VERIFY", True)) except ConnectionRefusedError: logger.error("Failed to connect to Gutsama server --> Connection refused") continue # -> Authenticate auth = pack_sendrecv(sock, {"password": server["pw"]}, 0) if auth is None: # Authentication failed logger.error("Authentication failed for server {}".format(server["name"])) exit(22) ping = pack_sendrecv(sock, {"cmd": "ping"}, 1) if ping["data"].get("response", None) != "pong": logger.error("Failed to connect to Gutsama server {}".format(server)) else: logger.info("ping --> {}".format(ping["data"])) sock.close()