Ejemplo n.º 1
0
def announce_completed(request, user, connectable, params, torrent, peer_id, peer_self):
    if not peer_self:
        raise AnnounceError("Broken client. Never started")

    torrent.seeders += 1
    torrent.leechers += 1
    torrent.times_completed += 1
    torrent.last_action = datetime.now()
    torrent.save()

    stats = UserTorrentStats.get(user=user, torrent=torrent)
    stats.when_completed = datetime.now()
    stats.save()

    return announce_poll(request, user, connectable, params, torrent, peer_id, peer_self)
Ejemplo n.º 2
0
def announce_poll(request, user, connectable, params, torrent, peer_id, peer_self):
    if not peer_self:
        raise AnnounceError("Broken client. Never started")

    left = long(params["left"][0])
    uploaded = long(params["uploaded"][0])
    downloaded = long(params["downloaded"][0])

    uploaded_delta = uploaded - peer_self.uploaded
    downloaded_delta = downloaded - peer_self.downloaded

    stats = UserTorrentStats.get_or_create(user=user, torrent=torrent)[0]
    stats.uploaded += uploaded_delta
    stats.downloaded += downloaded_delta
    stats.left = left

    if left == 0:
        stats.finished = True

    stats.save()

    userstats = UserStats.get_or_create(user=user)[0]
    userstats.uploaded += uploaded_delta
    userstats.downloaded += downloaded_delta
    userstats.save()

    peer_self.left = long(params["left"][0])
    peer_self.downloaded = long(params["downloaded"][0])
    peer_self.uploaded = long(params["uploaded"][0])
    peer_self.ip = get_ip(request, params)
    peer_self.port = int(params["port"][0])
    peer_self.peer_id = peer_id
    peer_self.client = request.META["HTTP_USER_AGENT"]
    peer_self.connectable = connectable
    peer_self.save()

    torrent.last_action = datetime.now()
    torrent.save()

    return HttpResponsePeers(torrent, Peer.objects.filter(torrent=torrent).exclude(user=user).order_by("?"), params)
Ejemplo n.º 3
0
def announce_stopped(request, user, connectable, params, torrent, peer_id, peer_self):
    if not peer_self:
        raise AnnounceError("Broken client. Never started")

    if peer_self.left == 0:
        torrent.seeders = torrent.seeders - 1
    else:
        torrent.leechers = torrent.leechers - 1

    torrent.last_action = datetime.now()
    torrent.save()

    left = long(params["left"][0])
    uploaded = long(params["uploaded"][0])
    downloaded = long(params["downloaded"][0])

    uploaded_delta = uploaded - peer_self.uploaded
    downloaded_delta = downloaded - peer_self.downloaded

    userstats = UserStats.get_or_create(user=user)[0]
    userstats.uploaded += uploaded_delta
    userstats.downloaded += downloaded_delta
    userstats.save()

    stats = UserTorrentStats.get_or_create(user=user, torrent=torrent)[0]
    stats.uploaded += uploaded_delta
    stats.downloaded += downloaded_delta
    stats.left = left

    if left == 0:
        stats.finished = True

    stats.save()

    peer_self.delete()

    # return a list of peers on STOPPED?? stupid
    return HttpResponsePeers(torrent, Peer.objects.filter(torrent=torrent).order_by("?"), params)
Ejemplo n.º 4
0
def announce_started(request, user, connectable, params, torrent, peer_id, peer_self):
    if peer_self:
        raise AnnounceError("Already started.")

    p = Peer()
    p.user = user
    p.torrent = torrent
    p.ip = get_ip(request, params)
    p.port = int(params["port"][0])
    p.peer_id = peer_id
    p.left = int(params["left"][0])
    p.downloaded = 0
    p.uploaded = 0
    p.client = request.META["HTTP_USER_AGENT"]
    p.connectable = connectable
    p.save()

    left = long(params["left"][0])

    stats = UserTorrentStats.get_or_create(user=user, torrent=torrent)[0]
    stats.left = left

    if left == 0:
        stats.finished = True

    stats.save()

    if p.left == 0:
        torrent.seeders = torrent.seeders + 1
    else:
        torrent.leechers = torrent.leechers + 1

    torrent.last_action = datetime.now()
    torrent.save()

    return HttpResponsePeers(torrent, Peer.objects.filter(torrent=torrent).order_by("?"), params)