Ejemplo n.º 1
0
 def singtest_send_opened(self):
     print >> sys.stderr,"test: test_send_opened"
     self.wanted = True
     self.wanted2 = True
     peer_db = PeerDBHandler.getInstance()
     hispermid = self.peer2.my_permid
     peer_db.addPeer(hispermid,{'ip':"127.0.0.1", 'port':5678})
     msg = GET_METADATA+'12345678901234567890'
     self.peer1.secure_overlay.connect(hispermid,lambda e,d,p,s: self.send_opened_connect_callback(e,d,p,s,msg))
Ejemplo n.º 2
0
 def test_loadSuperPeer(self):
     """ The SuperPeerDBHandler constructor writes the superpeers to the PeerDB """
     
     self.splist.loadSuperPeers(self.config, True)
     assert self.splist.size() == 3, self.splist.size()
     
     self.peer_db = PeerDBHandler.getInstance()
     # Arno: must be 3, as there is a duplicate PermID in the lines list
     assert self.peer_db.size() == 3, self.peer_db.size()
Ejemplo n.º 3
0
 def singtest_send_unopenedB(self):
     print >> sys.stderr,"test: test_send_unopenedB"
     self.wanted = True
     peer_db = PeerDBHandler.getInstance()
     hispermid = self.peer2.my_permid
     peer_db.addPeer(hispermid,{'ip':"127.0.0.1", 'port':5678})
     self.peer1.secure_overlay.send(hispermid,'msg=bla',self.send_unopenedB_send_callback)
     sleep(2) # let rawserver thread close connection, which should succeed
     self.assert_(len(self.peer1.secure_overlay.iplport2oc) == 0)
Ejemplo n.º 4
0
 def singtest_send_unopenedB(self):
     print >> sys.stderr, "test: test_send_unopenedB"
     self.wanted = True
     peer_db = PeerDBHandler.getInstance()
     hispermid = self.peer2.my_permid
     peer_db.addPeer(hispermid, {'ip': "127.0.0.1", 'port': 5678})
     self.peer1.secure_overlay.send(hispermid, 'msg=bla',
                                    self.send_unopenedB_send_callback)
     sleep(2)  # let rawserver thread close connection, which should succeed
     self.assert_(len(self.peer1.secure_overlay.iplport2oc) == 0)
Ejemplo n.º 5
0
 def singtest_send_opened(self):
     print >> sys.stderr, "test: test_send_opened"
     self.wanted = True
     self.wanted2 = True
     peer_db = PeerDBHandler.getInstance()
     hispermid = self.peer2.my_permid
     peer_db.addPeer(hispermid, {'ip': "127.0.0.1", 'port': 5678})
     msg = GET_METADATA + '12345678901234567890'
     self.peer1.secure_overlay.connect(
         hispermid, lambda e, d, p, s: self.send_opened_connect_callback(
             e, d, p, s, msg))
Ejemplo n.º 6
0
    def singtest_got_conn_outgoing(self):
        print >> sys.stderr,"test: test_got_conn_outgoing"
        self.wanted = True
        self.wanted2 = True
        # register handler for connections
        self.peer1.secure_overlay.register_conns_callback(self.got_conn_outgoing_conns_callback)

        peer_db = PeerDBHandler.getInstance()
        hispermid = self.peer2.my_permid
        peer_db.addPeer(hispermid,{'ip':"127.0.0.1", 'port':5678})
        msg = GET_METADATA+'12345678901234567890'
        self.peer1.secure_overlay.connect(hispermid,lambda e,d,p,s:self.got_conn_outgoing_connect_callback(e,d,p,s,msg))
Ejemplo n.º 7
0
    def singtest_connect_to_live_peer(self):
        print >> sys.stderr,"test: test_connect_to_live_peer"
        self.wanted = True

        peer_db = PeerDBHandler.getInstance()
        hispermid = self.peer2.my_permid
        peer_db.addPeer(hispermid,{'ip':"127.0.0.1", 'port':5678})

        self.peer1.secure_overlay.connect(hispermid,self.connect_to_live_peer_callback)
        sleep(2) # let rawserver thread establish connection, which should succeed
        self.assert_(len(self.peer1.secure_overlay.iplport2oc) == 1)
        self.assert_(self.peer1.secure_overlay.iplport2oc.has_key('127.0.0.1:5678'))
Ejemplo n.º 8
0
    def singtest_connect_to_dead_peerB(self):
        print >> sys.stderr,"test: test_connect_to_dead_peerB"
        self.wanted = True

        peer_db = PeerDBHandler.getInstance()
        hispermid = self.peer2.my_permid
        peer_db.addPeer(hispermid, {'ip':"127.0.0.1", 'port':22220})

        self.peer1.secure_overlay.connect(hispermid,self.connect_to_dead_peerB_callback)
        # Arno, 2009-04-23: was 2 secs, somehow the failed event comes in real slow now.
        sleep(4) # let rawserver thread establish connection, which should fail
        self.assert_(len(self.peer1.secure_overlay.iplport2oc) == 0)
Ejemplo n.º 9
0
    def singtest_receive(self):
        print >> sys.stderr, time.asctime(), "-", "test: test_receive"
        self.wanted = True
        self.wanted2 = True
        # register handler for messages
        self.peer2.secure_overlay.register_recv_callback(self.receive_msg_callback)

        peer_db = PeerDBHandler.getInstance()
        hispermid = self.peer2.my_permid
        peer_db.addPeer(hispermid, {"ip": "127.0.0.1", "port": 5678})
        msg = GET_METADATA + "12345678901234567890"
        self.peer1.secure_overlay.connect(hispermid, lambda e, d, p, s: self.receive_connect_callback(e, d, p, s, msg))
Ejemplo n.º 10
0
    def singtest_connect_to_dead_peerB(self):
        print >> sys.stderr, "test: test_connect_to_dead_peerB"
        self.wanted = True

        peer_db = PeerDBHandler.getInstance()
        hispermid = self.peer2.my_permid
        peer_db.addPeer(hispermid, {'ip': "127.0.0.1", 'port': 22220})

        self.peer1.secure_overlay.connect(hispermid,
                                          self.connect_to_dead_peerB_callback)
        # Arno, 2009-04-23: was 2 secs, somehow the failed event comes in real slow now.
        sleep(
            4)  # let rawserver thread establish connection, which should fail
        self.assert_(len(self.peer1.secure_overlay.iplport2oc) == 0)
Ejemplo n.º 11
0
    def singtest_receive(self):
        print >> sys.stderr, "test: test_receive"
        self.wanted = True
        self.wanted2 = True
        # register handler for messages
        self.peer2.secure_overlay.register_recv_callback(
            self.receive_msg_callback)

        peer_db = PeerDBHandler.getInstance()
        hispermid = self.peer2.my_permid
        peer_db.addPeer(hispermid, {'ip': "127.0.0.1", 'port': 5678})
        msg = GET_METADATA + '12345678901234567890'
        self.peer1.secure_overlay.connect(
            hispermid,
            lambda e, d, p, s: self.receive_connect_callback(e, d, p, s, msg))
Ejemplo n.º 12
0
    def singtest_connect_to_live_peer(self):
        print >> sys.stderr, "test: test_connect_to_live_peer"
        self.wanted = True

        peer_db = PeerDBHandler.getInstance()
        hispermid = self.peer2.my_permid
        peer_db.addPeer(hispermid, {'ip': "127.0.0.1", 'port': 5678})

        self.peer1.secure_overlay.connect(hispermid,
                                          self.connect_to_live_peer_callback)
        sleep(
            2
        )  # let rawserver thread establish connection, which should succeed
        self.assert_(len(self.peer1.secure_overlay.iplport2oc) == 1)
        self.assert_(
            self.peer1.secure_overlay.iplport2oc.has_key('127.0.0.1:5678'))
Ejemplo n.º 13
0
class Peer(Thread):
    def __init__(self, testcase, port, secover):
        Thread.__init__(self)
        self.setDaemon(True)

        self.testcase = testcase

        self.doneflag = Event()
        config = {}
        config['timeout_check_interval'] = 100000
        config['timeout'] = 100000
        config['ipv6_enabled'] = 0
        config['minport'] = port
        config['maxport'] = port + 5
        config['random_port'] = 0
        config['bind'] = ''
        config['ipv6_binds_v4'] = 0
        config['max_message_length'] = 2**23
        config['state_dir'] = config['install_dir'] = tempfile.mkdtemp()
        config['peer_icon_path'] = 'icons'

        self.rawserver = RawServer(self.doneflag,
                                   config['timeout_check_interval'],
                                   config['timeout'],
                                   ipv6_enable=config['ipv6_enabled'],
                                   failfunc=self.report_failure,
                                   errorfunc=self.report_error)
        while 1:
            try:
                self.listen_port = self.rawserver.find_and_bind(
                    0,
                    config['minport'],
                    config['maxport'],
                    config['bind'],
                    reuse=True,
                    ipv6_socket_style=config['ipv6_binds_v4'],
                    randomizer=config['random_port'])
                print >> sys.stderr, "test: Got listen port", self.listen_port
                break
            except socketerror, e:
                self.report_failure(str(e))
                msg = "Couldn't not bind to listen port - " + str(e)
                self.report_failure(msg)
                return

        self.multihandler = MultiHandler(self.rawserver, self.doneflag)
        # Note: We don't want a singleton, we want
        # two different instances for peer1 and peer2
        self.secure_overlay = secover

        self.my_keypair = EC.gen_params(EC.NID_sect233k1)
        self.my_keypair.gen_key()
        self.my_permid = str(self.my_keypair.pub().get_der())

        self.session = FakeSession(self, self.my_keypair, self.my_permid,
                                   self.listen_port)
        self.peer_db = PeerDBHandler.getInstance()

        self.secure_overlay.register(self, config['max_message_length'])
        print >> sys.stderr, "Peer: Setting", self.secure_overlay.get_handler(
        ), "as handler at SocketHandler"
        self.rawserver.sockethandler.set_handler(
            self.secure_overlay.get_handler())
        self.secure_overlay.start_listening()

        # Stupid rawserver goes into very long wait if there are no short
        # term tasks. Emulate this
        self.rawserver.add_task(self.dummy_task, 0)