示例#1
0
def main(reactor, listen="tcp:4321", connect="tcp:localhost:6543"):
    clientEndpoint = clientFromString(reactor, connect)
    serverEndpoint = serverFromString(reactor, listen)

    def incomingTubeFactory(listeningFount, listeningDrain):
        def outgoingTubeFactory(connectingFount, connectingDrain):
            listeningFount.flowTo(connectingDrain)
            connectingFount.flowTo(listeningDrain)
        clientEndpoint.connect(factoryFromFlow(outgoingTubeFactory))

    serverEndpoint.listen(factoryFromFlow(incomingTubeFactory))
    return Deferred()
示例#2
0
def main(reactor, listen="tcp:4321", connect="tcp:localhost:6543"):
    clientEndpoint = clientFromString(reactor, connect)
    serverEndpoint = serverFromString(reactor, listen)

    def incomingTubeFactory(listeningFount, listeningDrain):
        def outgoingTubeFactory(connectingFount, connectingDrain):
            listeningFount.flowTo(connectingDrain)
            connectingFount.flowTo(listeningDrain)

        clientEndpoint.connect(factoryFromFlow(outgoingTubeFactory))

    serverEndpoint.listen(factoryFromFlow(incomingTubeFactory))
    return Deferred()
示例#3
0
    def new_proxy_flow(self, listening_fount, listening_drain):
        """
        here's a summarized graph that does not include framing:

                                       /--> sieve_fount --> filter tube --------> connecting_drain
                                      /
        listening_fount ---> fan out <----> err_fount --> !filter tube
                                                                      \
                                                             replace with error tube
                                                            /
        listening_drain <-------------------- fan in <-----/
                                                           \
                                                            \---< filter tube <-- connecting_fount
        """
        def outgoing_tube_factory(connecting_fount, connecting_drain):
            client_filter = or_command_filter(self.client_allowed, self.client_allowed_prefixes)
            client_sieve = tubeFilter(client_filter.is_allowed)
            client_replace = replacerTubeFactory(self.client_replacements)
            proxy_client_sieve = series(bytesToLines(), client_replace, client_sieve, linesToBytes())

            client_fanout = Out()
            client_err_fount = client_fanout.newFount()
            client_sieve_fount = client_fanout.newFount()
            client_sieve_fount.flowTo(proxy_client_sieve).flowTo(connecting_drain)

            server_fanin = In()
            server_fanin.fount.flowTo(display_received("server")).flowTo(listening_drain)
            #server_fanin.fount.flowTo(listening_drain)
            server_fanin_proxy_drain = server_fanin.newDrain()
            server_fanin_err_drain = server_fanin.newDrain()

            error_sieve = tubeFilter(lambda item: not client_filter.is_allowed(item))
            replace_with_error_tube = lambda err_message: tubeMap(lambda item: err_message)
            proxy_error_sieve = series(bytesToLines(), error_sieve, replace_with_error_tube(self.filtered_msg), linesToBytes())
            client_err_fount.flowTo(series(proxy_error_sieve, server_fanin_err_drain))

            server_filter = or_command_filter(self.server_allowed, self.server_allowed_prefixes)
            server_sieve = tubeFilter(server_filter.is_allowed)
            proxy_server_sieve = series(bytesToLines(), server_sieve, linesToBytes())

            connecting_fount.flowTo(proxy_server_sieve).flowTo(server_fanin_proxy_drain)
            listening_fount.flowTo(series(display_received("client"), client_fanout.drain))
            #listening_fount.flowTo(client_fanout.drain)

        self.proxyEndpoint.connect(factoryFromFlow(outgoing_tube_factory))
示例#4
0
def main(reactor, listenOn="stdio:"):
    endpoint = serverFromString(reactor, listenOn)
    endpoint.listen(factoryFromFlow(echoFlow))
    return Deferred()
示例#5
0
def main(reactor, port="stdio:"):
    endpoint = serverFromString(reactor, port)
    endpoint.listen(factoryFromFlow(mathFlow))
    return Deferred()
示例#6
0
def main(reactor, listenOn="stdio:"):
    endpoint = serverFromString(reactor, listenOn)
    endpoint.listen(factoryFromFlow(echoFlow))
    return Deferred()
示例#7
0
def main(reactor):
    endpoint = TCP4ServerEndpoint(reactor, 4321)
    endpoint.listen(factoryFromFlow(echoTubeFactory))
    return Deferred()
示例#8
0
 def incomingTubeFactory(listeningFount, listeningDrain):
     def outgoingTubeFactory(connectingFount, connectingDrain):
         listeningFount.flowTo(connectingDrain)
         connectingFount.flowTo(listeningDrain)
     clientEndpoint.connect(factoryFromFlow(outgoingTubeFactory))
示例#9
0
文件: rpn.py 项目: david415/tubes
def main(reactor, port="stdio:"):
    endpoint = serverFromString(reactor, port)
    endpoint.listen(factoryFromFlow(mathFlow))
    return Deferred()
示例#10
0
    def incomingTubeFactory(listeningFount, listeningDrain):
        def outgoingTubeFactory(connectingFount, connectingDrain):
            listeningFount.flowTo(connectingDrain)
            connectingFount.flowTo(listeningDrain)

        clientEndpoint.connect(factoryFromFlow(outgoingTubeFactory))