def send_new(self, address, *args, **kwargs): with self.lock: link = my_clients.TCPClient(ip=self.ip, port=0) rip, rport = address.split(":") link.connect(rip, int(rport)) self.sip_endpoint.use_link(link) return self.sip_endpoint.send_new(*args, **kwargs)
def make_client(self, sock, addr): local_ip, local_port = sock.getsockname() client = None if self.protocol in ("tcp", "TCP"): client = my_clients.TCPClient(local_ip, local_port) elif self.protocol in ("udp", "UDP"): client = my_clients.UDPClient(local_ip, local_port) elif self.protocol in ("tls", "TLS"): client = my_clients.TLSClient(local_ip, local_port, None) client.rip = addr[0] client.rport = addr[1] self.csta_endpoint.link = client self.csta_endpoint.link.socket = sock # self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.csta_endpoint.link.sockfile = sock.makefile(mode='rb') return client
def make_client(self, sock, addr): local_ip, local_port = sock.getsockname() client = None if self.protocol in ("tcp", "TCP"): client = my_clients.TCPClient(local_ip, local_port) elif self.protocol in ("udp", "UDP"): client = my_clients.UDPClient(local_ip, local_port) elif self.protocol in ("tls", "TLS"): client = my_clients.TLSClient(local_ip, local_port, None) client.rip = addr[0] client.rport = addr[1] self.sip_endpoint.use_link(client) self.sip_endpoint.link.socket = sock # self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.sip_endpoint.link.sockfile = sock.makefile(mode='rb') self.links.append((None, client)) # self.links.append(("{}:{}".format(*addr), client)) return client
def connect(self, local_address, destination_address, protocol="tcp"): """ Connect to the SIP Server """ local_ip, local_port = local_address dest_ip, dest_port = destination_address if protocol in ("tcp", "TCP"): self.link = client.TCPClient(local_ip, local_port) elif protocol in ("udp", "UDP"): self.link = client.UDPClient(local_ip, local_port) else: raise NotImplementedError( "{} client not implemented".format(protocol)) self.link.connect(dest_ip, dest_port) self.ip = local_ip self.port = local_port self.parameters["source_ip"] = local_ip self.parameters["source_port"] = local_port self.parameters["dest_ip"] = dest_ip self.parameters["dest_port"] = dest_port self.parameters["transport"] = protocol
def connect(self, local_address, destination_address, protocol="tcp", certificate=None, subject_name="localhost"): """ Connect to the SIP Server """ local_ip, local_port = local_address dest_ip, dest_port = destination_address self.parameters["dest_ip"] = dest_ip self.parameters["dest_port"] = dest_port self.parameters["transport"] = protocol if protocol in ("tcp", "TCP"): self.link = client.TCPClient(local_ip, local_port) elif protocol in ("udp", "UDP"): self.link = client.UDPClient(local_ip, local_port) elif protocol in ("tls", "TLS"): # for MTLS this might be needed # context.load_cert_chain('/path/to/certchain.pem', '/path/to/private.key') self.link = client.TLSClient(local_ip, local_port, certificate) else: raise NotImplementedError("{} client not implemented".format(protocol)) self.link.connect(dest_ip, dest_port) self.set_address((local_ip, self.link.port))