Generate .torrent and start seeding immediately
See original GitHub issueI want to transfer file with magnetLink in c#. Through googling found monotorrent is best. I made a public bittorrent tracker server with https://github.com/webtorrent/bittorrent-tracker. I tried to generate .torrent file and get magnet link from media file in my pc. I used this sample. https://smuxi.im/wiki/monotorrent/Creating_Torrents. Open my .torrent file in mine and uTorrent program, but cannot download. I tried using uTorrent and generate a .torrent from same media file, and it works well in both uTorrent and monoTorrent. I found that the torrent’s info hash value is different in monotorrent and uTorrent. I have also tried to get magnet link from webtorrent. The infohash values in magnet url are same from uTorrent and webtorrent. The only my info hash differs. What’s the reason? Please help me. Here is my code to generate .torrent file and get magnet link. DevEnv : Windows10 / Visual studio 2017 / .Net framework 4.6.1
public async void CreateAndLoadTorrent(string path)
{
ClientEngine engine = new ClientEngine(new EngineSettings());
TorrentCreator creator = new TorrentCreator();
creator.Announces.Add(new RawTrackerTier(new[] { "http://192.168.5.151:8000/announce", "udp://192.168.5.151:8000"}));
ITorrentFileSource files = new TorrentFileSource(path);
BEncodedDictionary dict = await creator.CreateAsync(files);
Torrent torrent = Torrent.Load(dict);
BitField bitfield = new BitField(torrent.Pieces.Count).Not();
FastResume fastResumeData = new FastResume(torrent.InfoHash, bitfield);
TorrentManager manager = new TorrentManager(torrent, downloadPath, new TorrentSettings());
manager.LoadFastResume(fastResumeData);
engine.Register(manager);
engine.StartAll();
//MagnetLink magnet = new MagnetLink(manager.Torrent.InfoHash, manager.Torrent.Name, new[] { "http://192.168.5.151:8000/announce", "udp://192.168.5.151:8000" });
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
uTorrent will, by default, not allow connections from the same computer it is running on. i.e. if you run MonoTorrent and uTorrent on the same computer they will never connect to each other. You will need to go to the advanced settings and enable the
bt.allow_same_ip
option.Apart from that uTorrent does have a great logger. I would recommend enabling the ‘Logging’ pane, turning on every option it allows, and then seeing if anything interesting shows up which might explain what’s going wrong.
That’s not necessarily a bug or issue. The infohash is dependent on the ordering of the keys in the torrent file, and those aren’t always identical between programs which create a torrent. If you want to check if the .torrent file is valid then load the same .torrent into both MonoTorrent and uTorrent, point it at the same set of original files, then run a hash check. If both say that the torrent is 100% complete then great!
If you are still having issues then would it be possible to share the original files and the two .torrents with me (privately if necessary) so I can reproduce the issue and figure out what’s going on?
The downloadpath, i.e. 2nd parameter of new TorrentManager() function must be the directory of file to seed.
TorrentManager manager = new TorrentManager(torrent, downloadPath, new TorrentSettings());
changed to
TorrentManager manager = new TorrentManager(torrent, Path.GetDirectoryName(path), new TorrentSettings());
It works well soon.