Python Libtorrent doesn't seed

对着背影说爱祢 提交于 2019-12-23 01:44:20

问题


I'm trying to generate a torrent and seed it with python libtorrent, it generates the torrent, but doesn't seed it.

I am using libtorrent-0.16.18 with Python3.4 on Ubuntu 14.04

import sys
import time
import libtorrent as lt

fs = lt.file_storage()
lt.add_files(fs, "./test.txt")
t = lt.create_torrent(fs)
t.add_tracker("udp://tracker.publicbt.com:80")
t.set_creator("My Torrent")
t.set_comment("Test")
lt.set_piece_hashes(t, ".")
torrent = t.generate()

f = open("mytorrent.torrent", "wb")
f.write(lt.bencode(torrent))
f.close()

ses = lt.session()
ses.listen_on(6881, 6891)
h = ses.add_torrent({'ti': lt.torrent_info(torrent), 'save_path': '/tmp', 'seed_mode': True})

while h.is_seed():
    s = h.status()
    state_str = ['queued', 'checking', 'downloading metadata', \
      'downloading', 'finished', 'seeding', 'allocating', 'checking fastresume']

    print('\r%.2f%% complete (down: %.1f kb/s up: %.1f kB/s peers: %d) %s' % \
      (s.progress * 100, s.download_rate / 1000, s.upload_rate / 1000, s.num_peers, state_str[s.state]))
    sys.stdout.flush()

    time.sleep(1)

回答1:


Probably because you create the torrent from a file in current working directory ("."), but when you add the torrent to the session, you specify /tmp as the download directory. Presumably test.txt doesn't exist in /tmp. If you set the save_path to "." instead, it might seed.



来源:https://stackoverflow.com/questions/27090466/python-libtorrent-doesnt-seed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!