def __init__(self, client, settings, sock=None): self.settings = settings self.transport_type = settings.get("prudp.transport") self.resend_timeout = settings.get("prudp.resend_timeout") self.resend_limit = settings.get("prudp.resend_limit") self.substreams = settings.get("prudp.substreams") self.failure = signal.Signal() self.sock = sock if not self.sock: if self.transport_type == settings.TRANSPORT_UDP: self.sock = socket.UDPClient() elif self.transport_type == settings.TRANSPORT_TCP: self.sock = socket.TCPClient() else: self.sock = websocket.WebSocketClient(True) if self.transport_type == settings.TRANSPORT_UDP: if settings.get("prudp.version") == 0: self.packet_encoder = PRUDPMessageV0(client, settings) else: self.packet_encoder = PRUDPMessageV1(client, settings) else: self.packet_encoder = PRUDPLiteMessage(client, settings) self.sequence_mgr = SequenceMgr(settings) self.message_encoder = PacketEncoder(settings) self.ack_events = {} self.ack_packets = {} self.socket_event = None self.packets = []
def create_socket(self, req, tls): if tls: sock = ssl.SSLClient(ssl.VERSION_TLS12) cert = req.certificate if cert: sock.set_certificate(cert[0], cert[1]) else: sock = socket.TCPClient() return sock
def connect(self, host, port, timeout=3): sock = self.context.wrap(self.s.fd(), host) wrapper = socket.SocketWrapper(sock) self.s = socket.TCPClient(wrapper) return self.s.connect(host, port, timeout)
def __init__(self, version=VERSION_TLS12, sock=None): self.s = sock if not self.s: self.s = socket.TCPClient() self.context = SSLContext(version)