* i2psnark:

- Improved magnet link parsing, use tr parameter if present
This commit is contained in:
zzz
2011-02-10 17:12:15 +00:00
parent 03bc4fc133
commit ae9c160734
6 changed files with 89 additions and 24 deletions

View File

@ -643,11 +643,15 @@ public class SnarkManager implements Snark.CompleteListener {
*
* @param name hex or b32 name from the magnet link
* @param ih 20 byte info hash
* @param trackerURL may be null
* @param udpateStatus should we add this magnet to the config file,
* to save it across restarts, in case we don't get
* the metadata before shutdown?
* @throws RuntimeException via Snark.fatal()
* @since 0.8.4
*/
public void addMagnet(String name, byte[] ih, boolean updateStatus) {
Snark torrent = new Snark(_util, name, ih, this,
public void addMagnet(String name, byte[] ih, String trackerURL, boolean updateStatus) {
Snark torrent = new Snark(_util, name, ih, trackerURL, this,
_peerCoordinatorSet, _connectionAcceptor,
false, getDataDir().getPath());
@ -1151,6 +1155,10 @@ public class SnarkManager implements Snark.CompleteListener {
saveTorrentStatus(meta, storage.getBitField(), null); // no file priorities
String name = (new File(getDataDir(), storage.getBaseName() + ".torrent")).getAbsolutePath();
try {
// put the announce URL in the file
String announce = snark.getTrackerURL();
if (announce != null)
meta = meta.reannounce(announce);
synchronized (_snarks) {
locked_writeMetaInfo(meta, name);
// put it in the list under the new name
@ -1183,9 +1191,9 @@ public class SnarkManager implements Snark.CompleteListener {
String b64 = k.substring(PROP_META_MAGNET_PREFIX.length());
b64 = b64.replace('$', '=');
byte[] ih = Base64.decode(b64);
// ignore value
// ignore value - TODO put tracker URL in value
if (ih != null && ih.length == 20)
addMagnet("Magnet: " + I2PSnarkUtil.toHex(ih), ih, false);
addMagnet("Magnet: " + I2PSnarkUtil.toHex(ih), ih, null, false);
// else remove from config?
}
}