def dccSend(self, user, file): if type(file) == types.StringType: file = open(file, 'r') size = fileSize(file) name = getattr(file, "name", "file@%s" % (id(file), )) factory = DccSendFactory(file) port = tcp.Port(0, factory, 1) raise NotImplementedError, ( "XXX!!! Help! I need to bind a socket, have it listen, and tell me its address. " "(and stop accepting once we've made a single connection.)") my_address = struct.pack("!I", my_address) args = ['SEND', name, my_address, str(portNum)] if not (size is None): args.append(size) args = string.join(args, ' ') self.ctcpMakeQuery(user, [('DCC', args)])
def createPassiveServer(self): if self.dtp is not None: if self.dtp.transport is not None: self.dtp.transport.loseConnection() self.dtp = None # giving 0 will generate a free port self.dtpPort = tcp.Port(0, self) self.dtpPort.startListening()
def test_allocate(self): port = util.allocate_port() # and it should be possible to claim this port right away p2 = tcp.Port(port, protocol.Factory()) p2.startListening() port2 = p2.getHost().port d = p2.stopListening() def _stopped(res): self.failUnlessEqual(port, port2) return res d.addBoth(_stopped) return d
def action_JAP_REMOTE_WS_START(self, request): port = self.port_JAP_REMOTE_WS if port == None: configuration = JAP_LOCAL.getConfiguration( "./JAP_REMOTE_WS.json", JAP_REMOTE_WS.getDefaultConfiguration) if configuration["REMOTE_PROXY_SERVER"]["TYPE"] == "HTTPS": factory = JAP_REMOTE_WS.WSInputProtocolFactory( configuration, "wss://" + str(configuration["REMOTE_PROXY_SERVER"]["ADDRESS"]) + ":" + str(configuration["REMOTE_PROXY_SERVER"]["PORT"]), debug=False) factory.protocol = JAP_REMOTE_WS.WSInputProtocol contextFactory = ssl.DefaultOpenSSLContextFactory( configuration["REMOTE_PROXY_SERVER"]["CERTIFICATE"]["KEY"] ["FILE"], configuration["REMOTE_PROXY_SERVER"] ["CERTIFICATE"]["FILE"]) port = ssl.Port( configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, contextFactory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor) port.startListening() self.port_JAP_REMOTE_WS = port else: factory = JAP_REMOTE_WS.WSInputProtocolFactory( configuration, "ws://" + str(configuration["REMOTE_PROXY_SERVER"]["ADDRESS"]) + ":" + str(configuration["REMOTE_PROXY_SERVER"]["PORT"]), debug=False) factory.protocol = JAP_REMOTE_WS.WSInputProtocol port = tcp.Port( configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor) port.startListening() self.port_JAP_REMOTE_WS = port return ""
def startService(self): # use socket creation from twisted to use the same options as before if hasattr(self.protocol, 'datagramReceived'): tmp_port = udp.Port(None, None, interface=self.interface) else: tmp_port = tcp.Port(None, None, interface=self.interface) carbon_sock = tmp_port.createInternetSocket() if hasattr(socket, 'SO_REUSEPORT'): carbon_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) carbon_sock.bind((self.interface, self.port)) if hasattr(self.protocol, 'datagramReceived'): self._port = reactor.adoptDatagramPort( carbon_sock.fileno(), socket.AF_INET, self.protocol()) else: carbon_sock.listen(tmp_port.backlog) self._port = reactor.adoptStreamPort( carbon_sock.fileno(), socket.AF_INET, self.factory) carbon_sock.close()
def action_JAP_REMOTE_SSH_START(self, request): port = self.port_JAP_REMOTE_SSH if port == None: configuration = JAP_LOCAL.getConfiguration( "./JAP_REMOTE_SSH.json", JAP_REMOTE_SSH.getDefaultConfiguration) factory = JAP_REMOTE_SSH.SSHFactory(configuration) port = tcp.Port(configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor) port.startListening() self.port_JAP_REMOTE_SSH = port return ""
def action_JAP_LOCAL_WS_START(self, request): port = self.port_JAP_LOCAL_WS if port == None: configuration = JAP_LOCAL.getConfiguration( "./JAP_LOCAL_WS.json", JAP_LOCAL_WS.getDefaultConfiguration) factory = JAP_LOCAL_WS.WSInputProtocolFactory(configuration) factory.protocol = JAP_LOCAL_WS.WSInputProtocol port = tcp.Port(configuration["LOCAL_PROXY_SERVER"]["PORT"], factory, 50, configuration["LOCAL_PROXY_SERVER"]["ADDRESS"], reactor) port.startListening() self.port_JAP_LOCAL_WS = port return ""
def test_POST(self): request = requesthelper.DummyRequest(['']) request.method = 'POST' request.uri = '/robot/hash' request.content = StringIO.StringIO(json.dumps(dict(requirements=''))) request.getHost = lambda: tcp.Port(1555, None) d = _render(self.resource, request) @d.addCallback def handle(res): self.assertEquals(res, None) resp = json.loads(''.join(request.written)) url = resp.pop('url') url, slug = url.rsplit('/', 1) self.assertEquals(resp, {}) self.assertEquals(url, 'http://testing.org:123/robot/hash') self.assertNotEquals(slug, '') return d
def test_POST_without_baseurl(self): def locate(*args): return defer.maybeDeferred(operator.getitem, self.locations, args) self.resource = rrhash.Hash(self.store, locate, baseurl=None) request = requesthelper.DummyRequest(['']) request.method = 'POST' request.uri = '/robot/hash' request.content = StringIO.StringIO(json.dumps(dict(requirements=''))) request.getHost = lambda: tcp.Port(1555, None) d = _render(self.resource, request) @d.addCallback def handle(res): self.assertEquals(res, None) resp = json.loads(''.join(request.written)) url = resp.pop('url') url, slug = url.rsplit('/', 1) self.assertEquals(resp, {}) self.assertEquals(url, 'http://dummy:1555/robot/hash') self.assertNotEquals(slug, '') return d
def createWSPort(configuration): if configuration["REMOTE_PROXY_SERVER"]["TYPE"] == "WS": factory = WSInputProtocolFactory( configuration, "ws://" + str(configuration["REMOTE_PROXY_SERVER"]["ADDRESS"]) + ":" + str(configuration["REMOTE_PROXY_SERVER"]["PORT"])) return tcp.Port(configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor) else: factory = WSInputProtocolFactory( configuration, "wss://" + str(configuration["REMOTE_PROXY_SERVER"]["ADDRESS"]) + ":" + str(configuration["REMOTE_PROXY_SERVER"]["PORT"])) contextFactory = twunnel.remote_proxy_server__ssl.SSLServerContextFactory( configuration["REMOTE_PROXY_SERVER"]["CERTIFICATE"]["FILE"], configuration["REMOTE_PROXY_SERVER"]["CERTIFICATE"]["KEY"]["FILE"]) return ssl.Port(configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, contextFactory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor)
def listenTCP(self, port, factory, backlog=50, interface=''): """@see: twisted.internet.interfaces.IReactorTCP.listenTCP """ p = tcp.Port(port, factory, backlog, interface, self) p.startListening() return p
def listenTCP(self, port, factory, backlog=50, interface=""): p = tcp.Port(port, factory, backlog, interface, self) p.startListening() return p
def createHTTPSPort(configuration, outputProtocolConnectionManager): factory = HTTPSInputProtocolFactory(configuration, outputProtocolConnectionManager) return tcp.Port(configuration["LOCAL_PROXY_SERVER"]["PORT"], factory, 50, configuration["LOCAL_PROXY_SERVER"]["ADDRESS"], reactor)
def createSSHPort(configuration): factory = SSHInputProtocolFactory(configuration) return tcp.Port(configuration["REMOTE_PROXY_SERVER"]["PORT"], factory, 50, configuration["REMOTE_PROXY_SERVER"]["ADDRESS"], reactor)
def listenTCP(self, port, factory, backlog=5): """ Connects a given protocol factory to the given numeric TCP/IP port. """ from twisted.internet import tcp self.addPort(tcp.Port(port, factory, backlog))