5

我正在使用以下代码创建一个新的 torret 并共享,但由于从未播种,因此出现了问题。

import sys
import time
import libtorrent as lt

#Create torrent
fs = lt.file_storage()
lt.add_files(fs, "./test.txt")
t = lt.create_torrent(fs)
t.add_tracker("udp://tracker.openbittorrent.com:80/announce", 0)
t.set_creator('libtorrent %s' % lt.version)
t.set_comment("Test")
lt.set_piece_hashes(t, ".")
torrent = t.generate()    
f = open("mytorrent.torrent", "wb")
f.write(lt.bencode(torrent))
f.close()

#Seed torrent
ses = lt.session()
ses.listen_on(6881, 6891)
h = ses.add_torrent({'ti': lt.torrent_info('mytorrent.torrent'), 'save_path': '.', 'seed_mode': True}) 
print "Total size: " + str(h.status().total_wanted)
print "Name: " + h.name()   
while True:
    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)

按顺序测试:

  • 我运行脚本
  • mytorrent.torrent 已正确创建
  • 打印“总大小:”并打印“名称:”就可以了
  • 按顺序循环打印:

100.00% 完成(向下:0.0 kb/s 向上:0.0 kB/s 对等点:0)播种(8 次)

100.00% 完成(向下:0.0 kb/s 向上:0.0 kB/s 对等点:1)播种(11 次)(即使不运行 torrent 客户端,这种情况总是会发生。)

100.00% 完成(向下:0.0 kb/s 向上:0.0 kB/s 对等点:0)播种(无限次)

  • 我用 torrent 客户端运行 torrent 文件,但没有任何反应。

在此处输入图像描述

  • 除了尝试使用上述商业软件下载 torrent 外,我还尝试使用 libtorrent 库下载。始终显示 0 个对等点。

测试结果相同的变化:

  • 我尝试使用不同的跟踪器:

           trackerList = ['udp://tracker.istole.it:80/announce',
               'udp://tracker.ccc.de:80/announce',
               'http://tracker.torrentbay.to:6969/announce',
               'udp://fr33domtracker.h33t.com:3310/announce',
               'udp://tracker.publicbt.com:80/announce',
               'udp://tracker.openbittorrent.com:80/announce',
               'udp://11.rarbg.com/announce'
               'udp://tracker.istole.it:80/announce']
    
           for tracker in trackerList:        
                t.add_tracker(tracker, 0)
    
  • 我在执行脚本后立即在客户端运行了 torrent 文件,之后也运行了。

  • lt.torrent_info('mytorrent.torrent') 替换为 lt.torrent_info(torrent)

附加信息:

  • 为了进行测试,我使用了两台 Windows 计算机,每台计算机都连接到不同的网络。在每个网络中,所需的端口都是开放的。
  • 运行每个测试的时间至少为 1:20 小时。

其他测试:

  • 在我曾经共享的计算机中,我尝试共享别人创建的种子。我已经运行了标有“#Seed torrent”的代码,它起作用了:

    100.00% 完成(下行:2.0 kb/s 上行:45.0 kB/s 对等点:13)播种

  • 在我用来下载 torrent 的计算机中,我下载了一个已经由其他人创建的 torrent(带有 libtorrent),并且它工作正常。

因此我只能认为“#create torrent”这段代码有问题。好像跟踪器不会保存信息集。

4

1 回答 1

5

该问题已使用不同的跟踪器解决,而不是在“trackerList”中列出。代码是正确的。

于 2015-02-26T10:36:14.233 回答