use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class UDPTransport method succeeded.
public void succeeded(OutboundMessageState msg) {
if (msg == null)
return;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Sending message succeeded: " + msg);
noteSend(msg, true);
OutNetMessage m = msg.getMessage();
if (m != null)
super.afterSend(m, true);
}
use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class EstablishmentManager method receiveData.
/**
* A data packet arrived on an outbound connection being established, which
* means its complete (yay!). This is a blocking call, more than I'd like...
*
* @return the new PeerState
*/
PeerState receiveData(OutboundEstablishState state) {
state.dataReceived();
// int active = 0;
// int admitted = 0;
// int remaining = 0;
// active = _outboundStates.size();
_outboundStates.remove(state.getRemoteHostId());
// there shouldn't have been queued messages for this active state, but just in case...
List<OutNetMessage> queued = _queuedOutbound.remove(state.getRemoteHostId());
if (queued != null) {
// see comments above
synchronized (queued) {
for (OutNetMessage m : queued) {
state.addMessage(m);
}
}
}
if (_outboundStates.size() < getMaxConcurrentEstablish() && !_queuedOutbound.isEmpty()) {
locked_admitQueued();
}
if (_log.shouldLog(Log.INFO))
_log.info("Outbound established completely! yay: " + state);
PeerState peer = handleCompletelyEstablished(state);
notifyActivity();
return peer;
}
use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class EstablishmentManager method locked_admitQueued.
/**
* Move pending OB messages from _queuedOutbound to _outboundStates.
* This isn't so great because _queuedOutbound is not a FIFO.
*/
private int locked_admitQueued() {
if (_queuedOutbound.isEmpty())
return 0;
int admitted = 0;
int max = getMaxConcurrentEstablish();
for (Iterator<Map.Entry<RemoteHostId, List<OutNetMessage>>> iter = _queuedOutbound.entrySet().iterator(); iter.hasNext() && _outboundStates.size() < max; ) {
// ok, active shrunk, lets let some queued in.
Map.Entry<RemoteHostId, List<OutNetMessage>> entry = iter.next();
// java 5 IllegalStateException here
try {
iter.remove();
} catch (IllegalStateException ise) {
continue;
}
RemoteHostId to = entry.getKey();
List<OutNetMessage> allQueued = entry.getValue();
List<OutNetMessage> queued = new ArrayList<OutNetMessage>();
long now = _context.clock().now();
synchronized (allQueued) {
for (OutNetMessage msg : allQueued) {
if (now - Router.CLOCK_FUDGE_FACTOR > msg.getExpiration()) {
_transport.failed(msg, "Took too long in est. mgr OB queue");
} else {
queued.add(msg);
}
}
}
if (queued.isEmpty())
continue;
for (OutNetMessage m : queued) {
m.timestamp("no longer deferred... establishing");
establish(m, false);
}
admitted++;
}
return admitted;
}
use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class OutboundRefiller method run.
public void run() {
while (_alive) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Check the fragments to see if we can add more...");
boolean wantMore = _fragments.waitForMoreAllowed();
if (wantMore) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Want more fragments...");
OutNetMessage msg = _messages.getNext(-1);
if (msg != null) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("New message found to fragments: " + msg);
_context.statManager().addRateData("udp.timeToActive", msg.getLifetime(), msg.getLifetime());
_fragments.add(msg);
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("No message found to fragment");
}
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("No more fragments allowed, looping");
}
}
}
use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class PeerState method finishMessages.
/**
* Expire / complete any outbound messages
* High usage -
* OutboundMessageFragments.getNextVolley() calls this 1st.
* TODO combine finishMessages(), allocateSend(), and getNextDelay() so we don't iterate 3 times.
*
* @return number of active outbound messages remaining
*/
public int finishMessages() {
// short circuit, unsynchronized
if (_outboundMessages.isEmpty())
return _outboundQueue.size();
if (_dead) {
dropOutbound();
return 0;
}
int rv = 0;
List<OutboundMessageState> succeeded = null;
List<OutboundMessageState> failed = null;
synchronized (_outboundMessages) {
for (Iterator<OutboundMessageState> iter = _outboundMessages.iterator(); iter.hasNext(); ) {
OutboundMessageState state = iter.next();
if (state.isComplete()) {
iter.remove();
if (_retransmitter == state)
_retransmitter = null;
if (succeeded == null)
succeeded = new ArrayList<OutboundMessageState>(4);
succeeded.add(state);
} else if (state.isExpired()) {
iter.remove();
if (_retransmitter == state)
_retransmitter = null;
_context.statManager().addRateData("udp.sendFailed", state.getPushCount());
if (failed == null)
failed = new ArrayList<OutboundMessageState>(4);
failed.add(state);
} else if (state.getPushCount() > OutboundMessageFragments.MAX_VOLLEYS) {
iter.remove();
if (state == _retransmitter)
_retransmitter = null;
_context.statManager().addRateData("udp.sendAggressiveFailed", state.getPushCount());
if (failed == null)
failed = new ArrayList<OutboundMessageState>(4);
failed.add(state);
}
// end (pushCount > maxVolleys)
}
// end iterating over outbound messages
rv = _outboundMessages.size();
}
for (int i = 0; succeeded != null && i < succeeded.size(); i++) {
OutboundMessageState state = succeeded.get(i);
_transport.succeeded(state);
OutNetMessage msg = state.getMessage();
if (msg != null)
msg.timestamp("sending complete");
}
for (int i = 0; failed != null && i < failed.size(); i++) {
OutboundMessageState state = failed.get(i);
OutNetMessage msg = state.getMessage();
if (msg != null) {
msg.timestamp("expired in the active pool");
_transport.failed(state);
} else {
// final after establishment message
if (_log.shouldLog(Log.WARN))
_log.warn("Unable to send a direct message: " + state);
}
}
return rv + _outboundQueue.size();
}
Aggregations