def update_dispatchers(self, dispatchers): dispatchers = set(dispatchers) for new_dispatcher in dispatchers.difference(self.dispatchers): if new_dispatcher in self.old_connectors.iterkeys(): log.debug('Restoring old dispatcher at %s:%d' % new_dispatcher) self.dispatcher_connectors[new_dispatcher] = self.old_connectors.pop(new_dispatcher) else: log.debug('Adding new dispatcher at %s:%d' % new_dispatcher) dispatcher_addr, dispatcher_port = new_dispatcher factory = DispatcherConnectingFactory(self, dispatcher_addr, dispatcher_port) self.dispatcher_connectors[new_dispatcher] = reactor.connectTLS(dispatcher_addr, dispatcher_port, factory, self.tls_context) for old_dispatcher in self.dispatchers.difference(dispatchers): log.debug('Removing old dispatcher at %s:%d' % old_dispatcher) self.old_connectors[old_dispatcher] = self.dispatcher_connectors.pop(old_dispatcher) self._check_disconnect(old_dispatcher) self.dispatchers = dispatchers
def update_dispatchers(self, dispatchers): dispatchers = set(dispatchers) for new_dispatcher in dispatchers.difference(self.dispatchers): if new_dispatcher in self.old_connectors.iterkeys(): log.debug('Restoring old dispatcher at %s:%d' % new_dispatcher) self.dispatcher_connectors[new_dispatcher] = self.old_connectors.pop(new_dispatcher) else: log.debug('Adding new dispatcher at %s:%d' % new_dispatcher) dispatcher_addr, dispatcher_port = new_dispatcher factory = DispatcherConnectingFactory(self, dispatcher_addr, dispatcher_port) self.dispatcher_connectors[new_dispatcher] = reactor.connectTLS(dispatcher_addr, dispatcher_port, factory, self.cred) for old_dispatcher in self.dispatchers.difference(dispatchers): log.debug('Removing old dispatcher at %s:%d' % old_dispatcher) self.old_connectors[old_dispatcher] = self.dispatcher_connectors.pop(old_dispatcher) self._check_disconnect(old_dispatcher) self.dispatchers = dispatchers
def lineReceived(self, line): print 'received: %s' % line self.transport.loseConnection() def connectionLost(self, reason): if reason.type != ConnectionDone: print "connection was lost: %s" % reason.value reactor.stop() class EchoFactory(ClientFactory): protocol = EchoProtocol def clientConnectionFailed(self, connector, err): print "connection failed: %s" % err.value reactor.stop() script_path = os.path.realpath(os.path.dirname(sys.argv[0])) certs_path = os.path.join(script_path, 'certs') cert = X509Certificate(open(certs_path + '/valid.crt').read()) key = X509PrivateKey(open(certs_path + '/valid.key').read()) ca = X509Certificate(open(certs_path + '/ca.pem').read()) crl = X509CRL(open(certs_path + '/crl.pem').read()) cred = X509Credentials(cert, key, [ca]) cred.verify_peer = True reactor.connectTLS('localhost', 10000, EchoFactory(), cred) reactor.run()
port = str(port) i = port h = hashlib.md5(i) return h.hexdigest() options = {'server': 'localhost', 'size': 20, 'seconds': 10, 'local': 50000, 'encryption': True} for i in sys.argv[1:]: k, v = i.split('=') options[k] = v print options identity = identity_md5(options['local']) log.msg('identity: %s' % identity) if options['encryption']: log.msg('TLS client has been started') c = TLSCertificates() reactor.connectTLS(options['server'], 5000, ITTestFactory(options['size'], options['seconds']), c.credentials, bindAddress=('127.0.0.1', int(options['local']))) else: log.msg('TCP client has been started') reactor.connectTCP(options['server'], 5000, ITTestFactory(options['size'], options['seconds']), bindAddress=('127.0.0.1', int(options['local']))) reactor.run()
cert = X509Certificate(open(certs_path + '/valid.crt').read()) key = X509PrivateKey(open(certs_path + '/valid.key').read()) ca = X509Certificate(open(certs_path + '/ca.pem').read()) crl = X509CRL(open(certs_path + '/crl.pem').read()) if options.send_certs: cred = X509Credentials(cert, key, [ca]) else: cred = X509Credentials(trusted=[ca]) cred.verify_peer = options.verify context = TLSContext(cred) echo_factory = EchoFactory() start_time = time() for x in range(count): reactor.connectTLS(host, port, echo_factory, context) reactor.run() duration = time() - start_time rate = count / duration print "time={:.2f} sec; rate={} requests/sec with {}:{}".format( duration, int(rate), host, port) if failed > 0: print "{} out of {} connections have failed".format(failed, count) if options.memory: memory_dump()
cert = X509Certificate(open(certs_path + '/valid.crt').read()) key = X509PrivateKey(open(certs_path + '/valid.key').read()) ca = X509Certificate(open(certs_path + '/ca.pem').read()) crl = X509CRL(open(certs_path + '/crl.pem').read()) if options.send_certs: cred = X509Credentials(cert, key, [ca]) else: cred = X509Credentials(trusted=[ca]) cred.verify_peer = options.verify context = TLSContext(cred) echo_factory = EchoFactory() start_time = time() for x in range(count): reactor.connectTLS(host, port, echo_factory, context) reactor.run() duration = time() - start_time rate = count / duration print "time={:.2f} sec; rate={} requests/sec with {}:{}".format(duration, int(rate), host, port) if failed > 0: print "{} out of {} connections have failed".format(failed, count) if options.memory: memory_dump()
succesful = 0 failed = 0 certs_path = os.path.join(gnutls_path, 'examples/certs') cert = X509Certificate(open(certs_path + '/valid.crt').read()) key = X509PrivateKey(open(certs_path + '/valid.key').read()) ca = X509Certificate(open(certs_path + '/ca.pem').read()) crl = X509CRL(open(certs_path + '/crl.pem').read()) if options.send_certs: cred = X509Credentials(cert, key, [ca]) else: cred = X509Credentials(trusted=[ca]) cred.verify_peer = options.verify echo_factory = EchoFactory() t = timer(count) for x in range(count): reactor.connectTLS(host, port, echo_factory, cred) reactor.run() t.end(rate=True, msg="with %s:%d" % (host, port)) if failed > 0: print "%d out of %d connections have failed" % (failed, count) if options.memory: memory_dump()
def clientConnectionLost(self, connector, err): print "Connection lost" print err.value reactor.callLater(0, reactor.stop) if __name__ == "__main__": if len(sys.argv) < 2 or len(sys.argv) > 4: print "Usage: %s user@domain [relay-hostname [relay-port]]" % sys.argv[0] print "If the hostname and port are not specified, the MSRP relay will be discovered" print "through the the _msrps._tcp.domain SRV record. If a hostname is specified but" print "no port, the default port of 2855 will be used." else: username, domain = sys.argv[1].split("@", 1) cred = X509Credentials(None, None) cred.verify_peer = False ctx = TLSContext(cred) password = getpass() if len(sys.argv) == 2: factory = MSRPFileReceiverFactory(username, password, URI(domain, use_tls=True)) connector = SRVConnector(reactor, "msrps", domain, factory, connectFuncName="connectTLS", connectFuncArgs=[ctx]) connector.connect() else: relay_host = sys.argv[2] if len(sys.argv) == 4: relay_port = int(sys.argv[3]) else: relay_port = 2855 factory = MSRPFileReceiverFactory(username, password, URI(relay_host, port=relay_port, use_tls=True)) reactor.connectTLS(relay_host, relay_port, factory, ctx) reactor.run()
print 'received: %s' % line self.transport.loseConnection() def connectionLost(self, reason): if reason.type != ConnectionDone: print "connection was lost: %s" % reason.value reactor.stop() class EchoFactory(ClientFactory): protocol = EchoProtocol def clientConnectionFailed(self, connector, err): print "connection failed: %s" % err.value reactor.stop() script_path = os.path.realpath(os.path.dirname(sys.argv[0])) certs_path = os.path.join(script_path, 'certs') cert = X509Certificate(open(certs_path + '/valid.crt').read()) key = X509PrivateKey(open(certs_path + '/valid.key').read()) ca = X509Certificate(open(certs_path + '/ca.pem').read()) crl = X509CRL(open(certs_path + '/crl.pem').read()) cred = X509Credentials(cert, key, [ca]) cred.verify_peer = True context = TLSContext(cred, session_parameters="NORMAL:-COMP-ALL:+COMP-DEFLATE:+COMP-NULL") reactor.connectTLS('localhost', 10000, EchoFactory(), context) reactor.run()
print "If the hostname and port are not specified, the MSRP relay will be discovered" print "through the the _msrps._tcp.domain SRV record. If a hostname is specified but" print "no port, the default port of 2855 will be used." else: username, domain = sys.argv[1].split("@", 1) cred = X509Credentials(None, None) cred.verify_peer = False ctx = TLSContext(cred) password = getpass() if len(sys.argv) == 2: factory = MSRPFileReceiverFactory(username, password, URI(domain, use_tls=True)) connector = SRVConnector(reactor, "msrps", domain, factory, connectFuncName="connectTLS", connectFuncArgs=[ctx]) connector.connect() else: relay_host = sys.argv[2] if len(sys.argv) == 4: relay_port = int(sys.argv[3]) else: relay_port = 2855 factory = MSRPFileReceiverFactory( username, password, URI(relay_host, port=relay_port, use_tls=True)) reactor.connectTLS(relay_host, relay_port, factory, ctx) reactor.run()
self.transport.loseConnection() def connectionLost(self, reason): if reason.type != ConnectionDone: print "connection was lost: %s" % reason.value reactor.stop() class EchoFactory(ClientFactory): protocol = EchoProtocol def clientConnectionFailed(self, connector, err): print "connection failed: %s" % err.value reactor.stop() script_path = os.path.realpath(os.path.dirname(sys.argv[0])) certs_path = os.path.join(script_path, 'certs') cert = X509Certificate(open(certs_path + '/valid.crt').read()) key = X509PrivateKey(open(certs_path + '/valid.key').read()) ca = X509Certificate(open(certs_path + '/ca.pem').read()) crl = X509CRL(open(certs_path + '/crl.pem').read()) cred = X509Credentials(cert, key, [ca]) cred.verify_peer = True context = TLSContext( cred, session_parameters="NORMAL:-COMP-ALL:+COMP-DEFLATE:+COMP-NULL") reactor.connectTLS('localhost', 10000, EchoFactory(), context) reactor.run()
class EchoProtocol(LineOnlyReceiver): def connectionMade(self): self.sendLine('echo') def lineReceived(self, line): print 'received: ', line self.transport.loseConnection() def connectionLost(self, reason): reactor.stop() class EchoFactory(ClientFactory): protocol = EchoProtocol def clientConnectionFailed(self, connector, err): print err.value reactor.stop() cred = X509Credentials() cred.session_params.protocols = (PROTO_TLS1_2,) cred.session_params.ciphers = (GNUTLS_CIPHER_AES_256_CBC,) cred.session_params.compressions = (COMP_DEFLATE, COMP_NULL) reactor.connectTLS('localhost', 10000, EchoFactory(), cred) reactor.run()