Beispiel #1
0
def rest_announce():
    try:
        log.debug("Enter announce")
        ACTIVE_INTERVAL = current_app.config['ACTIVE_INTERVAL']
        PASSIVE_INTERVAL = current_app.config['PASSIVE_INTERVAL']
        ihash = utils.get_hash_hex(request.args.get('info_hash'))
        log.debug("ihash: %s" % ihash)
        if request.args.get('ip'):
            ipaddress = request.args.get('ip')
        else:
            ipaddress = request.remote_addr
        port = request.args.get('port')
        thispeer = "%s:%s" % (ipaddress, port)
        log.debug("peerpair: %s" % thispeer)
        seeder = int(request.args.get('left')) == 0
        active = utils.is_active(ihash)
        if active:
            interval = ACTIVE_INTERVAL
            if peer_first_announce(ihash, thispeer):
                store_peer_data(request.args, ihash, thispeer)
            else:
                update_peer_data(request.args, ihash, thispeer)
            warning = ""
        else:
            interval = PASSIVE_INTERVAL
            warning = "No active transfer for that info_hash: %s" % ihash
        peers = get_peers_for_peer(ihash, thispeer, seeder, active)
        if thispeer in peers:
            peers.remove(thispeer)
        log.debug("Will send thispeer: %s these peers: %s" % (thispeer, peers))
        if request.args.get('compact') == '1':
            peerlist = ""
            for peer in peers:
                peerlist += convert_peerpair_to_pack(peer)
        else:
            peerlist = []
            for peer in peers:
                peerlist.append(convert_peerpair_to_rec(ihash, peer))
        response = {
            "interval": interval,
            "warning": warning,
            "peers": peerlist
        }
        log.debug("resp: %s " % response)
        return bencode.bencode(response)
    except Exception, e:
        log.critical("Caught unhandled exception in announce")
        log.exception(e)
        raise e
def get_global_stats(ihash):
    peers = list(p.split(":")[0] for p in get_peers_redis(ihash))
    return {
        "active": utils.is_active(ihash),
        "peers": get_peer_count(ihash),
        "started": get_transfer_start(ihash),
        "seeders": get_seeder_count(ihash),
        "leechers": get_leecher_count(ihash),
        "first_start": get_first_started(ihash),
        "last_start": get_last_started(ihash),
        "complete": transfer_done(ihash),
        "first_complete": get_first_completed(ihash),
        "last_complete": get_last_completed(ihash),
        "size": get_size(ihash),
        "progress": estimate_progress(ihash, peers),
    }
Beispiel #3
0
def rest_announce():
    try:
        log.debug("Enter announce")
        ACTIVE_INTERVAL = current_app.config["ACTIVE_INTERVAL"]
        PASSIVE_INTERVAL = current_app.config["PASSIVE_INTERVAL"]
        ihash = utils.get_hash_hex(request.args.get("info_hash"))
        log.debug("ihash: %s" % ihash)
        if request.args.get("ip"):
            ipaddress = request.args.get("ip")
        else:
            ipaddress = request.remote_addr
        port = request.args.get("port")
        thispeer = "%s:%s" % (ipaddress, port)
        log.debug("peerpair: %s" % thispeer)
        seeder = int(request.args.get("left")) == 0
        active = utils.is_active(ihash)
        if active:
            interval = ACTIVE_INTERVAL
            if peer_first_announce(ihash, thispeer):
                store_peer_data(request.args, ihash, thispeer)
            else:
                update_peer_data(request.args, ihash, thispeer)
            warning = ""
        else:
            interval = PASSIVE_INTERVAL
            warning = "No active transfer for that info_hash: %s" % ihash
        peers = get_peers_for_peer(ihash, thispeer, seeder, active)
        if thispeer in peers:
            peers.remove(thispeer)
        log.debug("Will send thispeer: %s these peers: %s" % (thispeer, peers))
        if request.args.get("compact") == "1":
            peerlist = ""
            for peer in peers:
                peerlist += convert_peerpair_to_pack(peer)
        else:
            peerlist = []
            for peer in peers:
                peerlist.append(convert_peerpair_to_rec(ihash, peer))
        response = {"interval": interval, "warning": warning, "peers": peerlist}
        log.debug("resp: %s " % response)
        return bencode.bencode(response)
    except Exception, e:
        log.critical("Caught unhandled exception in announce")
        log.exception(e)
        raise e