def _test_bad(self,gen_drequest_func):
        s = OLConnection(self.my_keypair,'localhost',self.hisport)
        print >> sys.stderr,"\ntest: ",gen_drequest_func
        msg = gen_drequest_func()
        s.send(msg)
        time.sleep(5)
        # the other side should not like this and close the connection
        resp = s.recv()
        self.assert_(len(resp)==0)
        s.close()

        # However, closing the connection is the specified behaviour, check
        # that he doesn't connect back
        try:
            self.myss.settimeout(10.0)
            print >> sys.stderr,"test: See if peer connects back (would be bad)"
            conn, addr = self.myss.accept()
            s = BTConnection('',0,conn,mylistenport=self.mylistenport,user_infohash=dialback_infohash)
            s.read_handshake_medium_rare()
            resp = s.recv()
            print >> sys.stderr,"test: Got reply back, len",len(resp),"see if expected"
            self.assert_(len(resp) > 0)
            self.assert_(resp[0] != DIALBACK_REPLY)
            print >> sys.stderr,"test: Reply was acceptable",getMessageName(resp[0])
        except socket.timeout:
            self.assert_(True)
            print >> sys.stderr,"test: Good, accept() timed out"
    def _test_bad(self, gen_drequest_func):
        s = OLConnection(self.my_keypair, 'localhost', self.hisport)
        print >> sys.stderr, "\ntest: ", gen_drequest_func
        msg = gen_drequest_func()
        s.send(msg)
        time.sleep(5)
        # the other side should not like this and close the connection
        resp = s.recv()
        self.assert_(len(resp) == 0)
        s.close()

        # However, closing the connection is the specified behaviour, check
        # that he doesn't connect back
        try:
            self.myss.settimeout(10.0)
            print >> sys.stderr, "test: See if peer connects back (would be bad)"
            conn, addr = self.myss.accept()
            s = BTConnection('',
                             0,
                             conn,
                             mylistenport=self.mylistenport,
                             user_infohash=dialback_infohash)
            s.read_handshake_medium_rare()
            resp = s.recv()
            print >> sys.stderr, "test: Got reply back, len", len(
                resp), "see if expected"
            self.assert_(len(resp) > 0)
            self.assert_(resp[0] != DIALBACK_REPLY)
            print >> sys.stderr, "test: Reply was acceptable", getMessageName(
                resp[0])
        except socket.timeout:
            self.assert_(True)
            print >> sys.stderr, "test: Good, accept() timed out"