def app(env, start_response): path = env.get("PATH_INFO") query = parse_qs(env.get("QUERY_STRING")) # Extract what we need from env and query string. We'll # use this to populate/clobber existing peer data about # this torrent. ip = env["REMOTE_ADDR"] port = query.get("port")[0] peer = query.get("peer_id")[0] torrent = query.get("info_hash")[0] if torrent not in torrents: torrents[torrent] = {} torrents[torrent][peer] = {"ip": ip, "port": int(port)} peers = [] for peer, address in torrents[torrent].items(): peers.append({"peer id": peer, "ip": address.get("ip"), "port": address.get("port")}) start_response("200 OK", [("Content-Type", "text/plain")]) return encode({"interval": 1, "complete": 0, "incomplete": 0, "peers": peers})
def app(env, start_response): path = env.get("PATH_INFO") query = parse_qs(env.get("QUERY_STRING")) # Extract what we need from env and query string. We'll # use this to populate/clobber existing peer data about # this torrent. ip = env["REMOTE_ADDR"] port = query.get("port")[0] peer = query.get("peer_id")[0] torrent = query.get("info_hash")[0] if torrent not in torrents: torrents[torrent] = {} torrents[torrent][peer] = {"ip": ip, "port": int(port)} peers = [] for peer, address in torrents[torrent].items(): peers.append({ "peer id": peer, "ip": address.get("ip"), "port": address.get("port") }) start_response("200 OK", [("Content-Type", "text/plain")]) return encode({ "interval": 1, "complete": 0, "incomplete": 0, "peers": peers })
def create(source, torrent, step, announce): with open(torrent, 'wb') as torrent: torrent.write(encode({ "announce": announce, "info": { "name": get_name(source), "length": get_length(source), "pieces": get_pieces(source, step), "piece length": step } }))
def create(source, torrent, step, announce): with open(torrent, 'wb') as torrent: torrent.write( encode({ "announce": announce, "info": { "name": get_name(source), "length": get_length(source), "pieces": get_pieces(source, step), "piece length": step } }))