Changeset ae9c160


Ignore:
Timestamp:
Feb 10, 2011 5:12:15 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d8cff6c3
Parents:
03bc4fc
Message:
  • i2psnark:
    • Improved magnet link parsing, use tr parameter if present
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/Snark.java

    r03bc4fc rae9c160  
    255255  private byte[] id;
    256256  private byte[] infoHash;
     257  private String additionalTrackerURL;
    257258  private final I2PSnarkUtil _util;
    258259  private final PeerCoordinatorSet _peerCoordinatorSet;
     
    454455   *  @param torrent a fake name for now (not a file name)
    455456   *  @param ih 20-byte info hash
     457   *  @param trackerURL may be null
    456458   *  @since 0.8.4
    457459   */
    458   public Snark(I2PSnarkUtil util, String torrent, byte[] ih,
     460  public Snark(I2PSnarkUtil util, String torrent, byte[] ih, String trackerURL,
    459461        CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet,
    460462        ConnectionAcceptor connectionAcceptor, boolean start, String rootDir)
     
    466468    this.torrent = torrent;
    467469    this.infoHash = ih;
     470    this.additionalTrackerURL = trackerURL;
    468471    this.rootDataDir = rootDir;
    469472    stopped = true;
     
    536539        }
    537540        // TODO pass saved closest DHT nodes to the tracker? or direct to the coordinator?
    538         trackerclient = new TrackerClient(_util, meta, coordinator, this);
     541        trackerclient = new TrackerClient(_util, meta, additionalTrackerURL, coordinator, this);
    539542    }
    540543
     
    565568             }
    566569        }
    567         TrackerClient newClient = new TrackerClient(_util, meta, coordinator, this);
     570        TrackerClient newClient = new TrackerClient(_util, meta, additionalTrackerURL, coordinator, this);
    568571        if (!trackerclient.halted())
    569572            trackerclient.halt();
    570573        trackerclient = newClient;
    571574        trackerclient.start();
     575    } else {
     576        debug("NOT starting TrackerClient???", NOTICE);
    572577    }
    573578  }
     
    824829        acceptor.restart();
    825830        return true;
     831    }
     832
     833    /**
     834     *  @return trackerURL string from magnet-mode constructor, may be null
     835     *  @since 0.8.4
     836     */
     837    public String getTrackerURL() {
     838        return additionalTrackerURL;
    826839    }
    827840
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r03bc4fc rae9c160  
    644644     * @param name hex or b32 name from the magnet link
    645645     * @param ih 20 byte info hash
     646     * @param trackerURL may be null
     647     * @param udpateStatus should we add this magnet to the config file,
     648     *                     to save it across restarts, in case we don't get
     649     *                     the metadata before shutdown?
    646650     * @throws RuntimeException via Snark.fatal()
    647651     * @since 0.8.4
    648652     */
    649     public void addMagnet(String name, byte[] ih, boolean updateStatus) {
    650         Snark torrent = new Snark(_util, name, ih, this,
     653    public void addMagnet(String name, byte[] ih, String trackerURL, boolean updateStatus) {
     654        Snark torrent = new Snark(_util, name, ih, trackerURL, this,
    651655                                  _peerCoordinatorSet, _connectionAcceptor,
    652656                                  false, getDataDir().getPath());
     
    11521156            String name = (new File(getDataDir(), storage.getBaseName() + ".torrent")).getAbsolutePath();
    11531157            try {
     1158                // put the announce URL in the file
     1159                String announce = snark.getTrackerURL();
     1160                if (announce != null)
     1161                    meta = meta.reannounce(announce);
    11541162                synchronized (_snarks) {
    11551163                    locked_writeMetaInfo(meta, name);
     
    11841192                b64 = b64.replace('$', '=');
    11851193                byte[] ih = Base64.decode(b64);
    1186                 // ignore value
     1194                // ignore value - TODO put tracker URL in value
    11871195                if (ih != null && ih.length == 20)
    1188                     addMagnet("Magnet: " + I2PSnarkUtil.toHex(ih), ih, false);
     1196                    addMagnet("Magnet: " + I2PSnarkUtil.toHex(ih), ih, null, false);
    11891197                // else remove from config?
    11901198            }
  • apps/i2psnark/java/src/org/klomp/snark/TrackerClient.java

    r03bc4fc rae9c160  
    6666  private I2PSnarkUtil _util;
    6767  private final MetaInfo meta;
     68  private final String additionalTrackerURL;
    6869  private final PeerCoordinator coordinator;
    6970  private final Snark snark;
     
    7778  /**
    7879   * @param meta null if in magnet mode
     80   * @param additionalTrackerURL may be null, from the ?tr= param in magnet mode, otherwise ignored
    7981   */
    80   public TrackerClient(I2PSnarkUtil util, MetaInfo meta, PeerCoordinator coordinator, Snark snark)
     82  public TrackerClient(I2PSnarkUtil util, MetaInfo meta, String additionalTrackerURL,
     83                       PeerCoordinator coordinator, Snark snark)
    8184  {
    8285    super();
     
    8689    _util = util;
    8790    this.meta = meta;
     91    this.additionalTrackerURL = additionalTrackerURL;
    8892    this.coordinator = coordinator;
    8993    this.snark = snark;
    9094
    9195    this.port = 6881; //(port == -1) ? 9 : port;
    92 
    93     stop = false;
    94     started = false;
    9596  }
    9697
     
    139140    trackers = new ArrayList(2);
    140141    String primary = null;
    141     if (meta != null) {
     142    if (meta != null)
    142143        primary = meta.getAnnounce();
     144    else if (additionalTrackerURL != null)
     145        primary = additionalTrackerURL;
     146    if (primary != null) {
    143147        if (isValidAnnounce(primary)) {
    144             trackers.add(new Tracker(meta.getAnnounce(), true));
     148            trackers.add(new Tracker(primary, true));
    145149            _log.debug("Announce: [" + primary + "] infoHash: " + infoHash);
    146150        } else {
    147151            _log.warn("Skipping invalid or non-i2p announce: " + primary);
    148152        }
    149     }
    150     if (primary == null)
     153    } else {
     154        _log.warn("No primary announce");
    151155        primary = "";
     156    }
    152157    List tlist = _util.getOpenTrackers();
    153158    if (tlist != null) {
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    r03bc4fc rae9c160  
    6666    public static final String PROP_CONFIG_FILE = "i2psnark.configFile";
    6767    /** BEP 9 */
    68     private static final String MAGNET = "magnet:?xt=urn:btih:";
     68    private static final String MAGNET = "magnet:";
     69    private static final String MAGNET_FULL = MAGNET + "?xt=urn:btih:";
    6970    /** http://sponge.i2p/files/maggotspec.txt */
    7071    private static final String MAGGOT = "maggot://";
     
    14071408        String ihash;
    14081409        String name;
     1410        String trackerURL = null;
    14091411        if (url.startsWith(MAGNET)) {
    1410             ihash = url.substring(MAGNET.length()).trim();
    1411             int amp = ihash.indexOf('&');
    1412             if (amp >= 0)
    1413                 ihash = ihash.substring(0, amp);
     1412            // magnet:?xt=urn:btih:0691e40aae02e552cfcb57af1dca56214680c0c5&tr=http://tracker2.postman.i2p/announce.php
     1413            String xt = getParam("xt", url);
     1414            if (xt == null || !xt.startsWith("urn:btih:")) {
     1415                _manager.addMessage(_("Invalid magnet URL {0}", url));
     1416                return;
     1417            }
     1418            ihash = xt.substring("urn:btih:".length());
     1419            trackerURL = getParam("tr", url);
    14141420            name = "Magnet " + ihash;
     1421            String dn = getParam("dn", url);
     1422            if (dn != null)
     1423                name += " (" + Storage.filterName(dn) + ')';
    14151424        } else if (url.startsWith(MAGGOT)) {
     1425            // maggot://0691e40aae02e552cfcb57af1dca56214680c0c5:0b557bbdf8718e95d352fbe994dec3a383e2ede7
    14161426            ihash = url.substring(MAGGOT.length()).trim();
    14171427            int col = ihash.indexOf(':');
     
    14401450            return;
    14411451        }
    1442         _manager.addMagnet(name, ih, true);
     1452        _manager.addMagnet(name, ih, trackerURL, true);
     1453    }
     1454
     1455    private static String getParam(String key, String uri) {
     1456        int idx = uri.indexOf('?' + key + '=');
     1457        if (idx >= 0) {
     1458            idx += key.length() + 2;
     1459        } else {
     1460            idx = uri.indexOf('&' + key + '=');
     1461            if (idx >= 0)
     1462                idx += key.length() + 2;
     1463        }
     1464        if (idx < 0 || idx > uri.length())
     1465            return null;
     1466        String rv = uri.substring(idx);
     1467        idx = rv.indexOf('&');
     1468        if (idx >= 0)
     1469            rv = rv.substring(0, idx);
     1470        else
     1471            rv = rv.trim();
     1472        return rv;
    14431473    }
    14441474
     
    16451675            String hex = I2PSnarkUtil.toHex(snark.getInfoHash());
    16461676            buf.append("<br>").append(toImg("magnet", _("Magnet link"))).append(" <a href=\"")
    1647                .append(MAGNET).append(hex).append("\">")
    1648                .append(MAGNET).append(hex).append("</a>");
     1677               .append(MAGNET_FULL).append(hex).append("\">")
     1678               .append(MAGNET_FULL).append(hex).append("</a>");
    16491679            // We don't have the hash of the torrent file
    16501680            //buf.append("<br>").append(_("Maggot link")).append(": <a href=\"").append(MAGGOT).append(hex).append(':').append(hex).append("\">")
  • history.txt

    r03bc4fc rae9c160  
     12011-02-10 zzz
     2    * I2CP: Correctly close internal connections on the router side
     3            when closed by the client, was causing massive memory leak
     4            for internal clients using lots of sessions (thanks sponge)
     5    * i2psnark:
     6      - Improved magnet link parsing, use tr parameter if present
     7    * i2ptunnel: Change shared clients default for new clients to false
     8    * Streaming: Don't use iter.remove() on a COWAS
     9
    1102011-02-09 sponge
    211    * BOB: fixup delivery in config, adds config file versioning.
  • router/java/src/net/i2p/router/RouterVersion.java

    r03bc4fc rae9c160  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 5;
     21    public final static long BUILD = 6;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.