Search in sources :

Example 31 with I2PAppThread

use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.

the class FetchAndAdd method startTorrent.

// Snark overrides so all the buttons and stats on the web page work
@Override
public synchronized void startTorrent() {
    if (_isRunning)
        return;
    // reset counters in case starting a second time
    _remaining = -1;
    // leave the total if we knew it before
    // _total = -1;
    _transferred = 0;
    _failCause = null;
    _started = _util.getContext().clock().now();
    _isRunning = true;
    _active = false;
    _thread = new I2PAppThread(this, "Torrent File EepGet", true);
    _thread.start();
}
Also used : I2PAppThread(net.i2p.util.I2PAppThread)

Example 32 with I2PAppThread

use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.

the class TrackerClient method start.

public synchronized void start() {
    if (!stop) {
        if (_log.shouldLog(Log.WARN))
            _log.warn("Already started: " + _threadName);
        return;
    }
    stop = false;
    consecutiveFails = 0;
    runStarted = false;
    _fastUnannounce = false;
    snark.setTrackerProblems(null);
    _thread = new I2PAppThread(this, _threadName + " #" + (++_runCount), true);
    _thread.start();
    started = true;
}
Also used : I2PAppThread(net.i2p.util.I2PAppThread)

Example 33 with I2PAppThread

use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.

the class PeerCoordinator method addPeer.

/**
 * Add peer (inbound or outbound)
 * @return true if actual attempt to add peer occurs
 */
public boolean addPeer(final Peer peer) {
    if (halted) {
        peer.disconnect(false);
        return false;
    }
    boolean need_more;
    int peersize = 0;
    synchronized (peers) {
        peersize = peers.size();
        // This isn't a strict limit, as we may have several pending connections;
        // thus there is an additional check in connected()
        need_more = (!peer.isConnected()) && peersize < getMaxConnections();
        // Check if we already have this peer before we build the connection
        Peer old = peerIDInList(peer.getPeerID(), peers);
        need_more = need_more && ((old == null) || (old.getInactiveTime() > MAX_INACTIVE));
    }
    if (need_more) {
        if (_log.shouldLog(Log.DEBUG)) {
            // just for logging
            String name;
            if (metainfo == null)
                name = "Magnet";
            else
                name = metainfo.getName();
            _log.debug("Adding a peer " + peer.getPeerID().toString() + " for " + name, new Exception("add/run"));
        }
        // Run the peer with us as listener and the current bitfield.
        final PeerListener listener = this;
        final BitField bitfield;
        if (storage != null)
            bitfield = storage.getBitField();
        else
            bitfield = null;
        // if we aren't a seed but we don't want any more
        final boolean partialComplete = wantedBytes == 0 && bitfield != null && !bitfield.complete();
        Runnable r = new Runnable() {

            public void run() {
                peer.runConnection(_util, listener, bitfield, magnetState, partialComplete);
            }
        };
        String threadName = "Snark peer " + peer.toString();
        new I2PAppThread(r, threadName).start();
        return true;
    }
    if (_log.shouldLog(Log.DEBUG)) {
        if (peer.isConnected())
            _log.info("Add peer already connected: " + peer);
        else
            _log.info("Connections: " + peersize + "/" + getMaxConnections() + " not accepting extra peer: " + peer);
    }
    return false;
}
Also used : IOException(java.io.IOException) InvalidBEncodingException(org.klomp.snark.bencode.InvalidBEncodingException) I2PAppThread(net.i2p.util.I2PAppThread)

Example 34 with I2PAppThread

use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.

the class Reseeder method requestReseed.

/**
 *  Start a reseed from a single zip or su3 URL only.
 *  Threaded, nonblocking.
 *
 *  @throws IllegalArgumentException if it doesn't end with zip or su3
 *  @since 0.9.19
 */
void requestReseed(URI url) throws IllegalArgumentException {
    ReseedRunner reseedRunner = new ReseedRunner(url);
    // set to daemon so it doesn't hang a shutdown
    Thread reseed = new I2PAppThread(reseedRunner, "Reseed", true);
    reseed.start();
}
Also used : I2PAppThread(net.i2p.util.I2PAppThread) I2PAppThread(net.i2p.util.I2PAppThread)

Example 35 with I2PAppThread

use of net.i2p.util.I2PAppThread in project i2p.i2p by i2p.

the class SAMv2StreamSession method connect.

/**
 * Connect the SAM STREAM session to the specified Destination
 *
 * @param id Unique id for the connection
 * @param dest Base64-encoded Destination to connect to
 * @param props Options to be used for connection
 *
 * @throws DataFormatException if the destination is not valid
 * @throws SAMInvalidDirectionException if trying to connect through a
 *                                      receive-only session
 * @return true if the communication with the SAM client is ok
 */
@Override
public boolean connect(int id, String dest, Properties props) throws DataFormatException, SAMInvalidDirectionException {
    if (!canCreate) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Trying to create an outgoing connection using a receive-only session");
        throw new SAMInvalidDirectionException("Trying to create connections through a receive-only session");
    }
    if (checkSocketHandlerId(id)) {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("The specified id (" + id + ") is already in use");
        return false;
    }
    Destination d = SAMUtils.getDest(dest);
    I2PSocketOptions opts = socketMgr.buildOptions(props);
    if (props.getProperty(I2PSocketOptions.PROP_CONNECT_TIMEOUT) == null)
        opts.setConnectTimeout(60 * 1000);
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Connecting new I2PSocket...");
    // non-blocking connection (SAMv2)
    StreamConnector connector = new StreamConnector(id, d, opts);
    I2PAppThread connectThread = new I2PAppThread(connector, "StreamConnector" + id);
    connectThread.start();
    return true;
}
Also used : Destination(net.i2p.data.Destination) I2PSocketOptions(net.i2p.client.streaming.I2PSocketOptions) I2PAppThread(net.i2p.util.I2PAppThread)

Aggregations

I2PAppThread (net.i2p.util.I2PAppThread)52 IOException (java.io.IOException)18 I2PException (net.i2p.I2PException)9 I2PSocket (net.i2p.client.streaming.I2PSocket)7 InterruptedIOException (java.io.InterruptedIOException)6 ConnectException (java.net.ConnectException)5 Socket (java.net.Socket)5 I2PSessionException (net.i2p.client.I2PSessionException)5 Destination (net.i2p.data.Destination)5 File (java.io.File)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ServerSocket (java.net.ServerSocket)3 SocketTimeoutException (java.net.SocketTimeoutException)3 UnknownHostException (java.net.UnknownHostException)3 Properties (java.util.Properties)3 I2PServerSocket (net.i2p.client.streaming.I2PServerSocket)3 DataFormatException (net.i2p.data.DataFormatException)3 FileNotFoundException (java.io.FileNotFoundException)2