Changeset 95b6bd3


Ignore:
Timestamp:
Mar 20, 2017 4:41:04 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e4da3b0
Parents:
05aef9b
Message:

i2psnark: Enhancements to support RPC plugin

Files:
6 edited

Legend:

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

    r05aef9b r95b6bd3  
    7171    private List<String> _openTrackers;
    7272    private DHT _dht;
     73    private long _startedTime;
    7374
    7475    private static final int EEPGET_CONNECT_TIMEOUT = 45*1000;
     
    261262                opts.setProperty(I2PClient.PROP_SIGTYPE, "EdDSA_SHA512_Ed25519");
    262263            _manager = I2PSocketManagerFactory.createManager(_i2cpHost, _i2cpPort, opts);
     264            if (_manager != null)
     265                _startedTime = _context.clock().now();
    263266            _connecting = false;
    264267        }
     
    296299            _dht = null;
    297300        }
     301        _startedTime = 0;
    298302        I2PSocketManager mgr = _manager;
    299303        // FIXME this can cause race NPEs elsewhere
     
    311315    }
    312316   
     317    /**
     318     * When did we connect to the network?
     319     * For RPC
     320     * @return 0 if not connected
     321     * @since 0.9.30
     322     */
     323    public long getStartedTime() {
     324        return _startedTime;
     325    }
     326
    313327    /** connect to the given destination */
    314328    I2PSocket connect(PeerID peer) throws IOException {
  • apps/i2psnark/java/src/org/klomp/snark/Peer.java

    r05aef9b r95b6bd3  
    9090  //private static final long OPTION_AZMP      = 0x1000000000000000l;
    9191  private long options;
     92  private final boolean _isIncoming;
    9293
    9394  /**
     
    104105    this.metainfo = metainfo;
    105106    _id = __id.incrementAndGet();
     107    _isIncoming = false;
    106108    //_log.debug("Creating a new peer with " + peerID.toString(), new Exception("creating"));
    107109  }
     
    131133    if (_log.shouldLog(Log.DEBUG))
    132134        _log.debug("Creating a new peer " + peerID.toString(), new Exception("creating " + _id));
     135    _isIncoming = true;
     136  }
     137
     138  /**
     139   * Is this an incoming connection?
     140   * For RPC
     141   * @since 0.9.30
     142   */
     143  public boolean isIncoming() {
     144      return _isIncoming;
    133145  }
    134146
  • apps/i2psnark/java/src/org/klomp/snark/Snark.java

    r05aef9b r95b6bd3  
    2929import java.util.Properties;
    3030import java.util.StringTokenizer;
     31import java.util.concurrent.atomic.AtomicInteger;
    3132
    3233import net.i2p.I2PAppContext;
     
    239240  private volatile String activity = "Not started";
    240241  private final long savedUploaded;
    241 
     242  private static final AtomicInteger __RPCID = new AtomicInteger();
     243  private final int _rpcID = __RPCID.incrementAndGet();
    242244
    243245  /**
     
    13651367    return total > limit;
    13661368  }
     1369
     1370  /**
     1371   *  A unique ID for this torrent, useful for RPC
     1372   *  @return positive value unless you wrap around
     1373   *  @since 0.9.30
     1374   */
     1375  public int getRPCID() {
     1376    return _rpcID;
     1377  }
    13671378}
  • apps/i2psnark/java/src/org/klomp/snark/SnarkManager.java

    r05aef9b r95b6bd3  
    2828
    2929import net.i2p.I2PAppContext;
     30import net.i2p.app.ClientApp;
    3031import net.i2p.app.ClientAppManager;
     32import net.i2p.app.ClientAppState;
    3133import net.i2p.crypto.SHA1Hash;
    3234import net.i2p.crypto.SigType;
     
    5254 * Manage multiple snarks
    5355 */
    54 public class SnarkManager implements CompleteListener {
     56public class SnarkManager implements CompleteListener, ClientApp {
    5557   
    5658    /**
     
    247249    public void start() {
    248250        _running = true;
     251        if ("i2psnark".equals(_contextName)) {
     252            // Register with the ClientAppManager so the rpc plugin can find us
     253            // only if default instance
     254            ClientAppManager cmgr = _context.clientAppManager();
     255            if (cmgr != null)
     256                cmgr.register(this);
     257        }
    249258        _peerCoordinatorSet = new PeerCoordinatorSet();
    250259        _connectionAcceptor = new ConnectionAcceptor(_util, _peerCoordinatorSet);
     
    316325        _idleChecker.cancel();
    317326        stopAllTorrents(true);
     327        if ("i2psnark".equals(_contextName)) {
     328            // only if default instance
     329            ClientAppManager cmgr = _context.clientAppManager();
     330            if (cmgr != null)
     331                cmgr.unregister(this);
     332        }
    318333        if (_log.shouldWarn())
    319334            _log.warn("Snark stop() end");
     
    322337    /** @since 0.9.1 */
    323338    public boolean isStopping() { return _stopping; }
     339
     340    /**
     341     *  ClientApp method. Does nothing.
     342     *  Doesn't matter, we are only registering.
     343     *  @since 0.9.30
     344     */
     345    public void startup() {}
     346
     347    /**
     348     *  ClientApp method. Does nothing.
     349     *  Doesn't matter, we are only registering.
     350     *  @since 0.9.30
     351     */
     352    public void shutdown(String[] args) {}
     353
     354    /**
     355     *  ClientApp method.
     356     *  Doesn't matter, we are only registering.
     357     *  @return INITIALIZED always.
     358     *  @since 0.9.30
     359     */
     360    public ClientAppState getState() {
     361        return ClientAppState.INITIALIZED;
     362    }
     363
     364    /**
     365     *  ClientApp method.
     366     *  @since 0.9.30
     367     */
     368    public String getName() {
     369        return "i2psnark";
     370    }
     371
     372    /**
     373     *  ClientApp method.
     374     *  @since 0.9.30
     375     */
     376    public String getDisplayName() {
     377        return "i2psnark: " + _contextPath;
     378    }
    324379
    325380    /** hook to I2PSnarkUtil for the servlet */
     
    439494        }
    440495        return f;
     496    }
     497
     498    /**
     499     * For RPC
     500     * @since 0.9.30
     501     */
     502    public File getConfigDir() {
     503        return _configDir;
    441504    }
    442505
     
    15271590     *
    15281591     * @param metainfo the metainfo for the torrent
    1529      * @param bitfield the current completion status of the torrent
     1592     * @param bitfield the current completion status of the torrent, or null
    15301593     * @param filename the absolute path to save the metainfo to, generally ending in ".torrent", which is also the name of the torrent
    1531      *                 Must be a filesystem-safe name.
     1594     *                 Must be a filesystem-safe name. If null, will generate a name from the metainfo.
    15321595     * @param baseFile may be null, if so look in rootDataDir
    15331596     * @throws RuntimeException via Snark.fatal()
     
    15431606                addMessage(_t("Torrent with this info hash is already running: {0}", snark.getBaseName()));
    15441607                return false;
    1545             } else {
     1608            } else if (bitfield != null) {
    15461609                saveTorrentStatus(metainfo, bitfield, null, baseFile, true, 0, true); // no file priorities
    15471610            }
    15481611            // so addTorrent won't recheck           
     1612            if (filename == null) {
     1613                File f = new File(getDataDir(), Storage.filterName(metainfo.getName()) + ".torrent");
     1614                if (f.exists()) {
     1615                    addMessage(_t("Failed to copy torrent file to {0}", f.getAbsolutePath()));
     1616                    _log.error("Torrent file already exists: " + f);
     1617                }
     1618                filename = f.getAbsolutePath();
     1619            }
    15491620            try {
    15501621                locked_writeMetaInfo(metainfo, filename, areFilesPublic());
  • history.txt

    r05aef9b r95b6bd3  
     12017-03-20 zzz
     2 * i2psnark: Enhancements to support RPC plugin
     3
    142017-03-18 zzz
    25 * Addressbook (ticket #1966):
  • router/java/src/net/i2p/router/RouterVersion.java

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