Search in sources :

Example 21 with TunnelId

use of net.i2p.data.TunnelId in project i2p.i2p by i2p.

the class TunnelDispatcher method joinParticipant.

/**
 * We are a participant in this tunnel, but not as the endpoint or gateway
 *
 *  @return success; false if Tunnel ID is a duplicate
 */
public boolean joinParticipant(HopConfig cfg) {
    if (_log.shouldLog(Log.INFO))
        _log.info("Joining as participant: " + cfg);
    TunnelId recvId = cfg.getReceiveTunnel();
    TunnelParticipant participant = new TunnelParticipant(_context, cfg, new HopProcessor(_context, cfg, _validator));
    synchronized (_joinParticipantLock) {
        if (_participatingConfig.putIfAbsent(recvId, cfg) != null)
            return false;
        if (_participants.putIfAbsent(recvId, participant) != null) {
            _participatingConfig.remove(recvId);
            return false;
        }
    }
    _context.messageHistory().tunnelJoined("participant", cfg);
    _context.statManager().addRateData("tunnel.joinParticipant", 1);
    if (cfg.getExpiration() > _lastParticipatingExpiration)
        _lastParticipatingExpiration = cfg.getExpiration();
    _leaveJob.add(cfg);
    return true;
}
Also used : TunnelId(net.i2p.data.TunnelId)

Example 22 with TunnelId

use of net.i2p.data.TunnelId in project i2p.i2p by i2p.

the class TunnelDispatcher method joinInboundGateway.

/**
 * We are the inbound gateway in this tunnel, and did not create it
 *
 *  @return success; false if Tunnel ID is a duplicate
 */
public boolean joinInboundGateway(HopConfig cfg) {
    if (_log.shouldLog(Log.INFO))
        _log.info("Joining as IBGW: " + cfg);
    TunnelGateway.QueuePreprocessor preproc = createPreprocessor(cfg);
    TunnelGateway.Sender sender = new InboundSender(_context, cfg);
    TunnelGateway.Receiver receiver = new InboundGatewayReceiver(_context, cfg);
    // TunnelGateway gw = new TunnelGateway(_context, preproc, sender, receiver);
    TunnelGateway gw = new ThrottledPumpedTunnelGateway(_context, preproc, sender, receiver, _pumper, cfg);
    TunnelId recvId = cfg.getReceiveTunnel();
    synchronized (_joinParticipantLock) {
        if (_participatingConfig.putIfAbsent(recvId, cfg) != null)
            return false;
        if (_inboundGateways.putIfAbsent(recvId, gw) != null) {
            _participatingConfig.remove(recvId);
            return false;
        }
    }
    _context.messageHistory().tunnelJoined("inboundGateway", cfg);
    _context.statManager().addRateData("tunnel.joinInboundGateway", 1);
    if (cfg.getExpiration() > _lastParticipatingExpiration)
        _lastParticipatingExpiration = cfg.getExpiration();
    _leaveJob.add(cfg);
    return true;
}
Also used : TunnelId(net.i2p.data.TunnelId)

Example 23 with TunnelId

use of net.i2p.data.TunnelId in project i2p.i2p by i2p.

the class TunnelDispatcher method remove.

/**
 * We no longer want to participate in this tunnel that we created
 */
public void remove(TunnelCreatorConfig cfg) {
    if (cfg.isInbound()) {
        TunnelId recvId = cfg.getConfig(cfg.getLength() - 1).getReceiveTunnel();
        if (_log.shouldLog(Log.INFO))
            _log.info("removing our own inbound " + cfg);
        TunnelParticipant participant = _participants.remove(recvId);
        if (participant == null) {
            _inboundGateways.remove(recvId);
        } else {
            // skip last hop (us)
            for (int i = 0; i < cfg.getLength() - 1; i++) {
                Hash peer = cfg.getPeer(i);
                PeerProfile profile = _context.profileOrganizer().getProfile(peer);
                if (profile != null) {
                    int ok = participant.getCompleteCount();
                    int fail = participant.getFailedCount();
                    profile.getTunnelHistory().incrementProcessed(ok, fail);
                }
            }
        }
    } else {
        if (_log.shouldLog(Log.INFO))
            _log.info("removing our own outbound " + cfg);
        TunnelId outId = cfg.getConfig(0).getSendTunnel();
        TunnelGateway gw = _outboundGateways.remove(outId);
        if (gw != null) {
        // update stats based on gw.getMessagesSent()
        }
    }
    long msgs = cfg.getProcessedMessagesCount();
    int failures = cfg.getTunnelFailures();
    boolean failed = cfg.getTunnelFailed();
    _context.statManager().addRateData("tunnel.ownedMessageCount", msgs, failures);
    if (failed) {
        _context.statManager().addRateData("tunnel.failedCompletelyMessages", msgs, failures);
    } else if (failures > 0) {
        _context.statManager().addRateData("tunnel.failedPartiallyMessages", msgs, failures);
    }
}
Also used : PeerProfile(net.i2p.router.peermanager.PeerProfile) Hash(net.i2p.data.Hash) TunnelId(net.i2p.data.TunnelId)

Example 24 with TunnelId

use of net.i2p.data.TunnelId in project i2p.i2p by i2p.

the class TunnelDispatcher method remove.

/**
 * No longer participate in the tunnel that someone asked us to be a member of
 */
public void remove(HopConfig cfg) {
    TunnelId recvId = cfg.getReceiveTunnel();
    boolean removed = (null != _participatingConfig.remove(recvId));
    if (removed) {
        if (_log.shouldLog(Log.INFO))
            _log.info("removing " + cfg);
    } else {
        // this is normal, this can get called twice
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Participating tunnel, but no longer listed in participatingConfig? " + cfg);
    }
    removed = (null != _participants.remove(recvId));
    if (removed)
        return;
    removed = (null != _inboundGateways.remove(recvId));
    if (removed)
        return;
    _outboundEndpoints.remove(recvId);
}
Also used : TunnelId(net.i2p.data.TunnelId)

Example 25 with TunnelId

use of net.i2p.data.TunnelId in project i2p.i2p by i2p.

the class TunnelDispatcher method getNewIBZeroHopID.

/**
 *  Get a new random receive tunnel ID that isn't a dup.
 *  For zero hop tunnels only.
 *  Note that we do not keep track of IDs for pending builds so this
 *  does not fully prevent joinInbound() from failing later.
 *  @since 0.9.5
 */
public long getNewIBZeroHopID() {
    long rv;
    TunnelId tid;
    do {
        rv = 1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE);
        tid = new TunnelId(rv);
    } while (_inboundGateways.containsKey(tid));
    return rv;
}
Also used : TunnelId(net.i2p.data.TunnelId)

Aggregations

TunnelId (net.i2p.data.TunnelId)33 Hash (net.i2p.data.Hash)20 TunnelInfo (net.i2p.router.TunnelInfo)8 RouterInfo (net.i2p.data.router.RouterInfo)5 DataFormatException (net.i2p.data.DataFormatException)3 LeaseSet (net.i2p.data.LeaseSet)3 DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)3 I2NPMessage (net.i2p.data.i2np.I2NPMessage)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Lease (net.i2p.data.Lease)2 DataMessage (net.i2p.data.i2np.DataMessage)2 DeliveryStatusMessage (net.i2p.data.i2np.DeliveryStatusMessage)2 TunnelGatewayMessage (net.i2p.data.i2np.TunnelGatewayMessage)2 Job (net.i2p.router.Job)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 TreeSet (java.util.TreeSet)1 SessionKey (net.i2p.data.SessionKey)1