示例#1
0
    def got_response_negotiating(self, stream, request, response):
        m = json.loads(response.body.read())

        PROPERTIES = ("authorization", "queue_pos", "real_address", "unchoked")
        for k in PROPERTIES:
            self.conf["_%s" % k] = m[k]

        if not self.conf["_unchoked"]:
            logging.info("BitTorrent: negotiating ... done (queue_pos %d)",
                         m["queue_pos"])
            STATE.update("negotiate", {"queue_pos": m["queue_pos"]})
            self.connection_ready(stream)
        else:
            logging.info("BitTorrent: negotiating ... done (unchoked)")

            sha1 = hashlib.sha1()
            sha1.update(m["authorization"])
            self.conf["bittorrent.my_id"] = sha1.digest()
            logging.debug("* My ID: %s", sha1.hexdigest())
            self.http_stream = stream
            self.negotiating = False
            peer = PeerNeubot(self.poller)
            peer.version = CONFIG['bittorrent_test_version']
            peer.complete = self.peer_test_complete
            peer.connection_lost = self.peer_connection_lost
            peer.connection_failed = self.peer_connection_failed
            peer.configure(self.conf)
            peer.connect((self.http_stream.peername[0],
                          self.conf["bittorrent.port"]))
示例#2
0
    def connection_ready(self, stream):
        if not stream.id in NEGOTIATE_SERVER_BITTORRENT.peers:
            raise RuntimeError("Unauthorized peer")

        #
        # Override the number of bytes using information passed
        # from the peer and regenerate the schedule so that we
        # actually transfer that number of bytes.
        #
        self.target_bytes = NEGOTIATE_SERVER_BITTORRENT.peers[stream.id]["target_bytes"]
        self.make_sched()

        PeerNeubot.connection_ready(self, stream)
示例#3
0
    def connection_ready(self, stream):
        if not stream.id in AUTH_PEERS:
            raise RuntimeError("Unauthorized peer")

        # Not needed: peer.py already does that
        # stream.watchdog = 30

        #
        # Override the number of bytes using information passed
        # from the peer and regenerate the schedule so that we
        # actually transfer that number of bytes.
        #
        self.target_bytes = AUTH_PEERS[stream.id]["target_bytes"]
        self.make_sched()

        PeerNeubot.connection_ready(self, stream)
示例#4
0
 def configure(self, conf, measurer=None):
     conf["bittorrent.my_id"] = MY_ID
     PeerNeubot.configure(self, conf, measurer)
示例#5
0
 def configure(self, conf):
     conf["bittorrent.my_id"] = MY_ID
     PeerNeubot.configure(self, conf)