use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class OutboundMessageDistributor method distribute.
private void distribute(I2NPMessage msg, RouterInfo target, TunnelId tunnel) {
I2NPMessage m = msg;
if (tunnel != null) {
TunnelGatewayMessage t = new TunnelGatewayMessage(_context);
t.setMessage(msg);
t.setTunnelId(tunnel);
t.setMessageExpiration(m.getMessageExpiration());
m = t;
}
if (_context.routerHash().equals(target.getIdentity().calculateHash())) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("queueing inbound message to ourselves: " + m);
// TODO if UnknownI2NPMessage, convert it.
// See FragmentHandler.receiveComplete()
_context.inNetMessagePool().add(m, null, null);
return;
} else {
OutNetMessage out = new OutNetMessage(_context, m, _context.clock().now() + MAX_DISTRIBUTE_TIME, _priority, target);
if (_log.shouldLog(Log.DEBUG))
_log.debug("queueing outbound message to " + target.getIdentity().calculateHash());
_context.outNetMessagePool().add(out);
}
}
use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class OutboundReceiver method send.
private void send(TunnelDataMessage msg, RouterInfo ri) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("forwarding encrypted data out " + _config + ": " + msg.getUniqueId());
OutNetMessage m = new OutNetMessage(_context, msg, msg.getMessageExpiration(), _priority, ri);
_context.outNetMessagePool().add(m);
_config.incrementProcessedMessages();
}
use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class UDPTransport method noteSend.
private void noteSend(OutboundMessageState msg, boolean successful) {
// bail before we do all the work
if (!_context.messageHistory().getDoLog())
return;
int pushCount = msg.getPushCount();
int sends = msg.getMaxSends();
boolean expired = msg.isExpired();
OutNetMessage m = msg.getMessage();
PeerState p = msg.getPeer();
StringBuilder buf = new StringBuilder(64);
buf.append(" lifetime: ").append(msg.getLifetime());
buf.append(" sends: ").append(sends);
buf.append(" pushes: ").append(pushCount);
buf.append(" expired? ").append(expired);
buf.append(" unacked: ").append(msg.getUnackedSize());
if ((p != null) && (!successful)) {
buf.append(" consec_failed: ").append(p.getConsecutiveFailedSends());
long timeSinceSend = _context.clock().now() - p.getLastSendFullyTime();
buf.append(" lastFullSend: ").append(timeSinceSend);
long timeSinceRecv = _context.clock().now() - p.getLastReceiveTime();
buf.append(" lastRecv: ").append(timeSinceRecv);
buf.append(" xfer: ").append(p.getSendBps()).append("/").append(p.getReceiveBps());
buf.append(" mtu: ").append(p.getMTU());
buf.append(" rto: ").append(p.getRTO());
buf.append(" sent: ").append(p.getMessagesSent()).append("/").append(p.getPacketsTransmitted());
buf.append(" recv: ").append(p.getMessagesReceived()).append("/").append(p.getPacketsReceived());
buf.append(" uptime: ").append(_context.clock().now() - p.getKeyEstablishedTime());
}
if ((m != null) && (p != null)) {
_context.messageHistory().sendMessage(m.getMessageType(), msg.getMessageId(), m.getExpiration(), p.getRemotePeer(), successful, buf.toString());
} else {
_context.messageHistory().sendMessage("establish", msg.getMessageId(), -1, (p != null ? p.getRemotePeer() : null), successful, buf.toString());
}
}
use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class UDPTransport method failed.
void failed(OutboundMessageState msg, boolean allowPeerFailure) {
if (msg == null)
return;
OutNetMessage m = msg.getMessage();
if (allowPeerFailure && (msg.getPeer() != null) && ((msg.getMaxSends() >= OutboundMessageFragments.MAX_VOLLEYS) || (msg.isExpired()))) {
// long recvDelay = _context.clock().now() - msg.getPeer().getLastReceiveTime();
// long sendDelay = _context.clock().now() - msg.getPeer().getLastSendFullyTime();
// if (m != null)
// m.timestamp("message failure - volleys = " + msg.getMaxSends()
// + " lastReceived: " + recvDelay
// + " lastSentFully: " + sendDelay
// + " expired? " + msg.isExpired());
int consecutive = msg.getPeer().incrementConsecutiveFailedSends();
if (_log.shouldLog(Log.INFO))
_log.info("Consecutive failure #" + consecutive + " on " + msg.toString() + " to " + msg.getPeer());
if ((_context.clock().now() - msg.getPeer().getLastSendFullyTime() <= 60 * 1000) || (consecutive < MAX_CONSECUTIVE_FAILED)) {
// ok, a few conseutive failures, but we /are/ getting through to them
} else {
_context.statManager().addRateData("udp.dropPeerConsecutiveFailures", consecutive, msg.getPeer().getInactivityTime());
sendDestroy(msg.getPeer());
dropPeer(msg.getPeer(), false, "too many failures");
}
// if ( (consecutive > MAX_CONSECUTIVE_FAILED) && (msg.getPeer().getInactivityTime() > DROP_INACTIVITY_TIME))
// dropPeer(msg.getPeer(), false);
// else if (consecutive > 2 * MAX_CONSECUTIVE_FAILED) // they're sending us data, but we cant reply?
// dropPeer(msg.getPeer(), false);
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Failed sending " + msg + " to " + msg.getPeer());
}
noteSend(msg, false);
if (m != null)
super.afterSend(m, false);
}
use of net.i2p.router.OutNetMessage in project i2p.i2p by i2p.
the class SendGarlicJob method sendGarlic.
private void sendGarlic() {
// + Router.CLOCK_FUDGE_FACTOR;
long when = _message.getMessageExpiration();
OutNetMessage msg = new OutNetMessage(getContext(), _message, when, _priority, _config.getRecipient());
msg.setOnFailedReplyJob(_onReplyFailed);
msg.setOnFailedSendJob(_onSendFailed);
msg.setOnReplyJob(_onReply);
msg.setOnSendJob(_onSend);
msg.setReplySelector(_replySelector);
// _log.info("Sending garlic message to [" + _config.getRecipient() + "] encrypted with " + _config.getRecipientPublicKey() + " or " + _config.getRecipient().getIdentity().getPublicKey());
// _log.debug("Garlic config data:\n" + _config);
// msg.setTarget(_target);
getContext().outNetMessagePool().add(msg);
_log.debug("Garlic message added to outbound network message pool");
}
Aggregations