Пример #1
0
    def test_udpnoop(self):
        """Start up and shutdown without doing anything
        """

        conf=Config(Config.empty)
        conf.addrs=[('127.0.0.1', 1)] # will not be used
        
        resolv=Resolver(conf=conf)
        
        d1=resolv.lookup('junkname')
        @d1.addCallback
        def abort(name):
            self.assertTrue(name is None)
        
        d2=resolv.close()
        
        return gatherResults([d1,d2])
Пример #2
0
    def test_udplookup(self):
        name=padString('test1')

        serv=CAExpectDatagramProtocol(self, [], halt=False)

        up=self.up=reactor.listenUDP(0, serv, interface='127.0.0.1')

        addr=up.getHost()
        addr=addr.host, addr.port

        conf=Config(Config.empty)
        conf.addrs=[addr]
        
        resolv=self.resolv=Resolver(conf=conf)

        serv.dest='127.0.0.1', resolv._udp.getHost().port

        # name search
        # respond after second request
        serv.program= \
            [('recv',CAmessage(dtype=0, count=CA_VERSION)),
             ('recv',CAmessage(cmd=6, size=len(name),
                               dtype=5, count=CA_VERSION,
                               p1=0, p2=0, body=name)),
             ('recv',CAmessage(dtype=0, count=CA_VERSION)),
             ('recv',CAmessage(cmd=6, size=len(name),
                               dtype=5, count=CA_VERSION,
                               p1=0, p2=0, body=name)),
             ('send',CAmessage(cmd=6, size=8, dtype=addr[1],
                               p1=0xffffffff, p2=0,
                               body=searchbody.pack(11))),
            ]
        

        d=resolv.lookup('test1')

        @d.addCallback
        def result(srv):
            self.assertEqual(srv, addr)
            
            self.assertEqual(len(serv.program),0)


        return d
Пример #3
0
    def test_opencircuit(self):
        name = padString('testpv')
        user = padString('testuser')
        host = padString('testhost')

        namelookup = CAExpectDatagramProtocol(self, [], halt=False)

        udp = self.udp = reactor.listenUDP(0,
                                           namelookup,
                                           interface='127.0.0.1')

        sfact = self.sfact = CAExpectFactory()
        sfact.tst = self

        tcp = self.tcp = reactor.listenTCP(0, sfact, interface='127.0.0.1')

        udptarget = '127.0.0.1', udp.getHost().port
        tcptarget = '127.0.0.1', tcp.getHost().port

        # name search
        # respond after second request
        namelookup.program= \
            [('recv',CAmessage(dtype=0, count=CA_VERSION)),
             ('recv',CAmessage(cmd=6, size=len(name),
                               dtype=5, count=CA_VERSION,
                               p1=0, p2=0, body=name)),
             ('recv',CAmessage(dtype=0, count=CA_VERSION)),
             ('recv',CAmessage(cmd=6, size=len(name),
                               dtype=5, count=CA_VERSION,
                               p1=0, p2=0, body=name)),
             ('send',CAmessage(cmd=6, size=8, dtype=tcptarget[1],
                               p1=0xffffffff, p2=0,
                               body=searchbody.pack(11))),
            ]
        #namelookup.debug=True

        sfact.program= \
            [('send',CAmessage(dtype=0, count=12)),
             ('recv',CAmessage(dtype=0, count=CA_VERSION)),
             ('recv',CAmessage(cmd=20, size=len(user), body=user)),
             ('recv',CAmessage(cmd=21, size=len(host), body=host)),
             ('recv',CAmessage(cmd=100)),
            ]

        conf = Config(Config.empty)
        conf.addrs = [udptarget]

        cli = self.cli = CAClient(conf, user='******', host='testhost')

        namelookup.dest = '127.0.0.1', cli.resolv._udp.getHost().port

        d = cli.lookup('testpv')

        @d.addCallback
        @inlineCallbacks
        def findAndConnect(srv):
            self.assertEqual(srv, tcptarget)

            circ = yield cli.openCircuit(srv)

            self.assertTrue(circ is not None)

            self.assertEqual(circ.version, 12)

        return d