示例#1
0
 def buildProtocol(self, addr):
     if self.accept_list != None and addr.host not in self.accept_list:
         return None
     p = Factory.buildProtocol(self, addr)
     p.command_cb = self.command_cb
     p.raddr = addr
     return p
    def test_connectionCancelledBeforeSecure(self):
        """
        If the connection is cancelled before the SSH transport layer has
        finished key exchange (ie, gotten to the point where we may attempt to
        authenticate), the L{Deferred} returned by
        L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
        L{CancelledError} and the connection is aborted.
        """
        endpoint = SSHCommandClientEndpoint.newConnection(
            self.reactor,
            b"/bin/ls -l",
            b"dummy user",
            self.hostname,
            self.port,
            knownHosts=self.knownHosts,
            ui=FixedResponseUI(False))

        factory = Factory()
        factory.protocol = Protocol
        d = endpoint.connect(factory)

        transport = AbortableFakeTransport(None, isServer=False)
        factory = self.reactor.tcpClients[0][2]
        client = factory.buildProtocol(None)
        client.makeConnection(transport)
        d.cancel()

        self.failureResultOf(d).trap(CancelledError)
        self.assertTrue(transport.aborted)
        # Make sure the connection closing doesn't result in unexpected
        # behavior when due to cancellation:
        client.connectionLost(Failure(ConnectionDone()))
示例#3
0
文件: shell.py 项目: hagna/simplebb
 def buildProtocol(self, addr):
     """
     Builds the protocol
     """
     p = Factory.buildProtocol(self, addr)
     p.hub = self.hub
     return p
示例#4
0
 def buildProtocol(self, addr):
     if self.status in ("starting up", "generating GUID"
                        ) and self.only_ip != ["127.0.0.1"]:
         return
     if addr.host not in self.only_ip and "0.0.0.0" not in self.only_ip:
         return
     return Factory.buildProtocol(self, addr)
示例#5
0
 def workerListenerFactory(self):
     """
     Factory that listens for connections from workers.
     """
     f = Factory()
     f.buildProtocol = lambda addr: ConnectionFromWorker(self)
     return f
示例#6
0
    def test_connectionCancelledBeforeSecure(self):
        """
        If the connection is cancelled before the SSH transport layer has
        finished key exchange (ie, gotten to the point where we may attempt to
        authenticate), the L{Deferred} returned by
        L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
        L{CancelledError} and the connection is aborted.
        """
        endpoint = SSHCommandClientEndpoint.newConnection(
            self.reactor, b"/bin/ls -l", b"dummy user",
            self.hostname, self.port, knownHosts=self.knownHosts,
            ui=FixedResponseUI(False))

        factory = Factory()
        factory.protocol = Protocol
        d = endpoint.connect(factory)

        transport = AbortableFakeTransport(None, isServer=False)
        factory = self.reactor.tcpClients[0][2]
        client = factory.buildProtocol(None)
        client.makeConnection(transport)
        d.cancel()

        self.failureResultOf(d).trap(CancelledError)
        self.assertTrue(transport.aborted)
        # Make sure the connection closing doesn't result in unexpected
        # behavior when due to cancellation:
        client.connectionLost(Failure(ConnectionDone()))
    def test_connectionClosedBeforeSecure(self):
        """
        If the connection closes at any point before the SSH transport layer
        has finished key exchange (ie, gotten to the point where we may attempt
        to authenticate), the L{Deferred} returned by
        L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
        the reason for the lost connection.
        """
        endpoint = SSHCommandClientEndpoint.newConnection(
            self.reactor,
            b"/bin/ls -l",
            b"dummy user",
            self.hostname,
            self.port,
            knownHosts=self.knownHosts,
            ui=FixedResponseUI(False))

        factory = Factory()
        factory.protocol = Protocol
        d = endpoint.connect(factory)

        transport = StringTransport()
        factory = self.reactor.tcpClients[0][2]
        client = factory.buildProtocol(None)
        client.makeConnection(transport)

        client.connectionLost(Failure(ConnectionDone()))
        self.failureResultOf(d).trap(ConnectionDone)
示例#8
0
 def buildProtocol(self, addr):
     if self.accept_list != None and addr.host not in self.accept_list:
         return None
     p = Factory.buildProtocol(self, addr)
     p.command_cb = self.command_cb
     p.raddr = addr
     return p
 def buildProtocol(self, addr):
     p = Factory.buildProtocol(self, addr)
     
     p.player = {}
     p.player_uuid = self.player_uuid
     p.username = self.username
     
     return p
示例#10
0
 def buildProtocol(self, addr):
     """
     Only accepting connections from local machine!
     """
     if addr.host != '127.0.0.1':
         lg.err('refused connection from remote host: %r' % addr.host)
         return None
     proto = Factory.buildProtocol(self, addr)
     return proto
示例#11
0
 def buildProtocol(self, addr):
     if self.dead:
         return None
     ip = addr.host
     connections = self.peerConnections.get(ip, 0)
     maxConnections = self.servconfig["client_peer_exempt"][ip] if ip in self.servconfig["client_peer_exempt"] else self.servconfig["client_peer_connections"]
     if maxConnections and connections >= maxConnections:
         log.msg("A client at IP address {} has exceeded the session limit".format(ip))
         return None
     self.peerConnections[ip] = connections + 1
     return Factory.buildProtocol(self, addr)
示例#12
0
 def buildProtocol(self, addr):
     """
     Building protocol. Add the current service to the observer list for the
     protocol
     """
     proto = Factory.buildProtocol(self, addr)
     if self.service is not None:
         proto.addObserver(self.service)
     else:
         if logger.isEnabledFor(logging.CRITICAL):
             logger.critical("Proto built without any srv : won't do much")
     return proto
示例#13
0
    def start(self):
        """
        Start the socks5 server by listening on the specified TCP ports.
        """
        def build_protocol(_):
            socks5connection = Socks5Connection(self)
            self.sessions.append(socks5connection)
            return socks5connection

        factory = Factory()
        factory.buildProtocol = build_protocol
        self.twisted_port = reactor.listenTCP(self.port, factory)
示例#14
0
文件: server.py 项目: Tribler/tribler
    def start(self):
        """
        Start the socks5 server by listening on the specified TCP ports.
        """
        def build_protocol(_):
            socks5connection = Socks5Connection(self)
            self.sessions.append(socks5connection)
            return socks5connection

        factory = Factory()
        factory.buildProtocol = build_protocol
        self.twisted_port = reactor.listenTCP(self.port, factory)
示例#15
0
 def test_defaultBuildProtocol(self):
     """
     L{Factory.buildProtocol} by default constructs a protocol by calling
     its C{protocol} attribute, and attaches the factory to the result.
     """
     class SomeProtocol(Protocol):
         pass
     f = Factory()
     f.protocol = SomeProtocol
     protocol = f.buildProtocol(None)
     self.assertIsInstance(protocol, SomeProtocol)
     self.assertIdentical(protocol.factory, f)
示例#16
0
 def test_defaultBuildProtocol(self):
     """
     L{Factory.buildProtocol} by default constructs a protocol by calling
     its C{protocol} attribute, and attaches the factory to the result.
     """
     class SomeProtocol(Protocol):
         pass
     f = Factory()
     f.protocol = SomeProtocol
     protocol = f.buildProtocol(None)
     self.assertIsInstance(protocol, SomeProtocol)
     self.assertIs(protocol.factory, f)
示例#17
0
 def buildProtocol(self, addr):
     """
     Only accepting connections from local machine!
     """
     global _WebSocketTransport
     if _WebSocketTransport:
         lg.warn('refused connection to web socket - another connection already made')
         return None
     if addr.host != '127.0.0.1':
         lg.err('refused connection from remote host: %r' % addr.host)
         return None
     proto = Factory.buildProtocol(self, addr)
     return proto
示例#18
0
    def buildProtocol(self, addr):
        proto = Factory.buildProtocol(self, addr)
        for prev_proto in self.already_proto:
            assert isinstance(prev_proto.locator, CoordinatorLocatorDecorator), 'Каждый локатор должен быть ' \
                                                                                'декорирован для задания своего ' \
                                                                                'списка incoming_connections'
            assert prev_proto.locator.decorated_locator is self.coordinator_locator, 'координирующий ' \
                                                                                     'локатор должен быть один'
            prev_proto.locator.add_incoming_connection(proto)
            proto.locator.add_incoming_connection(prev_proto)

        # add for the next protos
        self.already_proto.append(proto)
        return proto
示例#19
0
文件: ircd.py 项目: ojii/txircd
 def buildProtocol(self, addr):
     if self.dead:
         return None
     ip = addr.host
     # self.unique_ips.add(ip)
     # self.stats_data["total_connections"] = len(self.unique_ips)
     # if self.app_ip_log:
     #    with open(self.app_ip_log,"w") as f:
     #        f.write(json.dumps(list(self.unique_ips), separators=(',',':')))
     conn = self.peerConnections.get(ip, 0)
     max = self.client_peer_exempt[ip] if ip in self.client_peer_exempt else self.client_peer_connections
     if max and conn >= max:
         return None
     # self.stats_data["connections"] += 1
     self.peerConnections[ip] = conn + 1
     return Factory.buildProtocol(self, addr)
示例#20
0
    def test_connectionClosedBeforeSecure(self):
        """
        If the connection closes at any point before the SSH transport layer
        has finished key exchange (ie, gotten to the point where we may attempt
        to authenticate), the L{Deferred} returned by
        L{SSHCommandClientEndpoint.connect} fires with a L{Failure} wrapping
        the reason for the lost connection.
        """
        endpoint = SSHCommandClientEndpoint.newConnection(
            self.reactor, b"/bin/ls -l", b"dummy user",
            self.hostname, self.port, knownHosts=self.knownHosts,
            ui=FixedResponseUI(False))

        factory = Factory()
        factory.protocol = Protocol
        d = endpoint.connect(factory)

        transport = StringTransport()
        factory = self.reactor.tcpClients[0][2]
        client = factory.buildProtocol(None)
        client.makeConnection(transport)

        client.connectionLost(Failure(ConnectionDone()))
        self.failureResultOf(d).trap(ConnectionDone)
示例#21
0
 def buildProtocol(self, address):
     self.address = address
     return Factory.buildProtocol(self, address)
示例#22
0
 def buildProtocol(self, addr):
     self.lastClient = Factory.buildProtocol(self, addr)
     self.lastClient.submitRecords = []
     return self.lastClient
示例#23
0
 def buildProtocol(self, addr):
     if addr.host not in self.only_ip and "0.0.0.0" not in self.only_ip:
         return
     return Factory.buildProtocol(self, addr)
示例#24
0
文件: server.py 项目: brussee/tribler
 def start(self):
     for i, port in enumerate(self.socks5_ports):
         factory = Factory()
         factory.buildProtocol = lambda addr, hops=i + 1: self.buildProtocol(
             addr, hops)
         self.twisted_ports.append(reactor.listenTCP(port, factory))
示例#25
0
    def buildProtocol(self, addr):
        log.msg("Starting connection to %s" % addr)

        return Factory.buildProtocol(self, addr)
示例#26
0
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     protocol.verbose = self.verbose
     return protocol
示例#27
0
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     self.protocols.append(protocol)
     return protocol
 def buildProtocol(self, addr):
     p = Factory.buildProtocol(self, addr)
     p.username = self.username
     return p
示例#29
0
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     protocol.verbose = self.verbose
     return protocol
示例#30
0
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     self.register_client((addr.host, addr.port), protocol)
     return protocol
示例#31
0
 def buildProtocol(self, addr):
     p = Factory.buildProtocol(self, addr)
     p.control_session = self.control_session
     return p
示例#32
0
 def buildProtocol(self, addr):
     ip = addr.host
     log.debug("Connection from relay at %s" % ip)
     prot = Factory.buildProtocol(self, addr)
     prot.ip = ip
     return prot
示例#33
0
 def buildProtocol(self, addr):
     prot = Factory.buildProtocol(self, addr)
     self.protocols.append(prot)
     return prot
示例#34
0
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     self.register_client((addr.host, addr.port), protocol)
     return protocol
示例#35
0
 def buildProtocol(self, addr):
     '''Override this to store active clients'''
     # you might want to store the addr object for record keeping
     p = Factory.buildProtocol(self, addr)
     self.active_clients.append(p)
     return p
示例#36
0
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     return protocol
示例#37
0
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     self.protocols.add(protocol)
     return protocol
示例#38
0
 def setUp(self):
     factory = Factory()
     factory.protocol = DummyProtocol
     self.proto = factory.buildProtocol(('127.0.0.1', 0))
     self.tr = proto_helpers.StringTransport()
     self.proto.makeConnection(self.tr)
示例#39
0
 def buildProtocol(self, addr):
     ip = addr.host
     log.debug("Connection from relay at %s" % ip)
     prot = Factory.buildProtocol(self, addr)
     prot.ip = ip
     return prot
示例#40
0
文件: factory.py 项目: Krenair/bravo
    def buildProtocol(self, addr):
        log.msg("Starting connection to %s" % addr)

        return Factory.buildProtocol(self, addr)
示例#41
0
 def buildProtocol(self, addr):
     if self.status in ("starting up", "generating GUID") and self.only_ip != ["127.0.0.1"]:
         return
     if addr.host not in self.only_ip and "0.0.0.0" not in self.only_ip:
         return
     return Factory.buildProtocol(self, addr)
示例#42
0
 def buildProtocol(self, addr):
     self.resetDelay()   # Reset the delay
     self.p = Factory.buildProtocol(self, addr)
     return self.p
示例#43
0
 def buildProtocol(self, addr):
     p = Factory.buildProtocol(self, addr)
     p.control_session = self.control_session
     return p
示例#44
0
 def buildProtocol(self, addr):
     d = Factory.buildProtocol(self, addr)
     d.factory = self
     return d
示例#45
0
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     protocol.ip = addr.host
     protocol.logger = ProtocolLogger(name='relay {}'.format(addr.host))
     protocol.logger.info('Connection established')
     return protocol
示例#46
0
 def buildProtocol(self, addr):
     if addr.host not in self.only_ip and "0.0.0.0" not in self.only_ip:
         return
     return Factory.buildProtocol(self, addr)
示例#47
0
 def buildProtocol(self, addr):
     p = Factory.buildProtocol(self, addr)
     p.command_cb = self.command_cb
     return p
示例#48
0
 def buildProtocol(self, addr):
     log.msg("Client connected from:", (addr,))
     protocol = Factory.buildProtocol(self, addr)
     protocol.register(self.map)
     protocol.addr = addr
     return protocol
示例#49
0
 def buildProtocol(self, addr):
     if addr.host != self.only_ip and self.only_ip != "0.0.0.0":
         return
     return Factory.buildProtocol(self, addr)
示例#50
0
 def buildProtocol(self, addr):
     if addr.host != self.only_ip and self.only_ip != "0.0.0.0":
         return
     return Factory.buildProtocol(self, addr)
示例#51
0
 def buildProtocol(self, addr):
     redis = Factory.buildProtocol(self, addr)
     redis.factory = self
     redis.delayedCalls = {}
     self.protocols.append(redis)
     return redis
示例#52
0
class SSLServerTestCase(unittest.TestCase):
    def clean_up_old_data(self, ):
        global _clean_up_db  # pylint: disable=global-statement
        if not _clean_up_db:
            _clean_up_db = True
            # init database
            db_path = join_with_rc(config.proxy.dbpath)
            if os.path.isfile(db_path):
                os.remove(db_path)

            # clean server_root
            server_root = join_with_rc(config.proxy.server_root)
            for root, dirs, files in os.walk(server_root, topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))

    def setUp(self):
        self.factory = Factory()
        self.factory.protocol = SSLServerProtocol
        self.clean_up_old_data()

        self.proto = self.factory.buildProtocol(("localhost", 0))

        self.proto.proxy_db = ProxyDB()
        self.proto.port_conf = {
            'file': config.proxy.server_file_port,
            'stream_ws': config.proxy.server_stream_ws_port,
            'stream_restful': config.proxy.server_stream_restful_port
        }

        self.transport = proto_helpers.StringTransport()
        self.proto.makeConnection(self.transport)

    def check_response_later(self, reply_error, wait=1):
        d = Deferred()
        reactor.callLater(wait, d.callback, reply_error)
        d.addCallback(self.check_response)

        return d

    def check_response(self, reply_error):
        string = self.transport.value()
        _, string = string.split(b':', 1)

        message = Message()
        message.ParseFromString(string)

        assert message.type == Message.PROXY_REPLY

        proxy_reply = message.proxy_reply

        if not proxy_reply.error:
            self.assertEqual(proxy_reply.AES_key, b'AES_key')
        else:
            self.assertEqual(reply_error, proxy_reply.error)

    def test_1_buyer_request(self):
        message = fake_buyer_message()
        sign_message = sign_buyer_message(message)
        string = sign_message.SerializeToString()
        self.proto.stringReceived(string)
        return self.check_response_later('trade record not found in database')

    def test_2_seller_request(self):
        message = fake_seller_message()
        sign_message = sign_seller_message(message)
        string = sign_message.SerializeToString()
        self.proto.stringReceived(string)
        return self.check_response_later('')

    def test_3_seller_request(self):
        message = fake_seller_message()
        sign_message = sign_seller_message(message)
        string = sign_message.SerializeToString()
        self.proto.stringReceived(string)
        return self.check_response_later('trade record already in database')

    def test_3_sold_to_another_buyer(self):
        message = fake_seller_message()
        message.seller_data.order_id = 2
        message.seller_data.buyer_addr = b'fake addr'
        sign_message = sign_seller_message(message)
        string = sign_message.SerializeToString()
        self.proto.stringReceived(string)
        return self.check_response_later('')

    def test_4_buyer_request(self):
        message = fake_buyer_message()
        sign_message = sign_buyer_message(message)
        string = sign_message.SerializeToString()
        self.proto.stringReceived(string)
        return self.check_response_later('')

    def test_invalid_signature(self):
        message = fake_buyer_message()
        sign_message = sign_buyer_message(message)
        sign_message.public_key = 'invalid key'
        string = sign_message.SerializeToString()
        self.proto.stringReceived(string)
        return self.check_response_later('wrong signature')

    def test_key_not_match_address(self):
        message = fake_buyer_message()
        message.buyer_data.buyer_addr = 'fake addr'
        sign_message = sign_buyer_message(message)
        string = sign_message.SerializeToString()
        self.proto.stringReceived(string)
        return self.check_response_later(
            'public key does not match with address')

    def test_invalid_request(self):
        message = fake_buyer_message()
        message.type = 3  # any value large than 2 is invalid
        sign_message = sign_buyer_message(message)
        string = sign_message.SerializeToString()
        self.proto.stringReceived(string)
        return self.check_response_later('wrong client request')
示例#53
0
 def buildProtocol(self, addr):
     p = Factory.buildProtocol(self, addr)
     p.testcase = self.testcase
     return p
 def buildProtocol(self, addr):
     protocol = Factory.buildProtocol(self, addr)
     return protocol
 def setUp(self):
     factory = Factory()
     factory.protocol = DummyProtocol
     self.proto = factory.buildProtocol(("127.0.0.1", 0))
     self.tr = proto_helpers.StringTransport()
     self.proto.makeConnection(self.tr)
示例#56
0
 def buildProtocol(self, addr):
     p = Factory.buildProtocol(self, addr)
     p.command_cb = self.command_cb
     return p
示例#57
0
 def buildProtocol(self, address):
     self.address = address
     return Factory.buildProtocol(self, address)