def map_upnp(self): upnp = upnpsock.connect() if upnp is None: return None router, location = upnp try: result = upnpsock.open_port( router, self.source_port, ) except socket.error as e: if e.errno == errno.EADDRINUSE: raise RaidenServicePortInUseError() raise if result is not None: self.storage['router'] = router self.storage['external_port'] = result[1] return PortMappedSocket( sock=self.socket, method='UPnP', external_ip=result[0], external_port=result[1], router_location=location, ) return None
def map_upnp(self): upnp = upnpsock.connect() if upnp is not None: router, location = upnp result = upnpsock.open_port( router, self.source_port, ) if result is not None: self.storage['router'] = router return PortMappedSocket(self.socket, 'UPnP', result[0], result[1], router_location=location)
def map_upnp(self): upnp = upnpsock.connect() if upnp is None: return try: router, location = upnp result = upnpsock.open_port( router, self.source_port, ) if result is not None: self.storage['router'] = router self.storage['external_port'] = result[1] return PortMappedSocket(self.socket, 'UPnP', result[0], result[1], router_location=location) except socket.error as e: if e.errno == errno.EADDRINUSE: raise RaidenServicePortInUseError() raise
def map_upnp(self): upnp = upnpsock.connect() if upnp is None: return try: router, location = upnp result = upnpsock.open_port( router, self.source_port, ) if result is not None: self.storage['router'] = router return PortMappedSocket(self.socket, 'UPnP', result[0], result[1], router_location=location) except socket.error as e: if e.errno == errno.EADDRINUSE: raise RaidenServicePortInUseError() raise
def socket_factory(source_ip, source_port, *args, **kwargs): """ Create a port mapped socket via uPnP or STUN. Args: source_ip (ip string): the network interface/ip to bind source_port (int): the local port to bind *args: generic args that are passed to the below implementations **kargs: generic kwargs that are passed to the below implementations Return: PortMappedSocket """ # prefer uPnP over STUN upnp = upnpsock.connect() if upnp is not None: router, location = upnp result = upnpsock.open_port( router, source_port, ) if result is not None: with stunsock.open_bare_socket(source_ip, source_port, *args, **kwargs) as sock: try: yield PortMappedSocket(sock, 'uPnP', result[0], result[1], **dict( router_location=location )) finally: upnpsock.release_port(router, source_port) else: with stunsock.stun_socket(source_ip, source_port, *args, **kwargs) as ( sock, external_ip, external_port, nat ): if external_port is not None: yield PortMappedSocket(sock, 'STUN', external_ip, external_port, **nat)