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;
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations