/** * (correctly) Invalidates stored checksum */ public void setTunnelId(TunnelId id) { _hasChecksum = false; _tunnelIdObj = id; _tunnelId = id.getTunnelId(); }
@Override public int hashCode() { return (int) _end.getTime() ^ DataHelper.hashCode(_gateway) ^ (int) _tunnelId.getTunnelId(); } }
/** * The local router has detected a failure in the given tunnel * * @param tunnel tunnel failed */ public void tunnelFailed(TunnelId tunnel) { if (!_doLog) return; if (tunnel == null) return; StringBuilder buf = new StringBuilder(128); buf.append(getPrefix()); buf.append("failing tunnel [").append(tunnel.getTunnelId()).append("]"); addEntry(buf.toString()); }
public void setReceiveTunnelId(TunnelId id) { _receiveTunnelId = DataHelper.toLong(4, id.getTunnelId()); }
@Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append("Message ").append(_messageId); //.append(" on "); //buf.append(TunnelGateway.this.toString()); if (_toRouter != null) { buf.append(" targetting "); buf.append(_toRouter.toBase64()).append(" "); if (_toTunnel != null) buf.append(_toTunnel.getTunnelId()); } buf.append(" actual lifetime "); buf.append(getLifetime()).append("ms"); buf.append(" potential lifetime "); buf.append(_expiration - _created).append("ms"); buf.append(" size ").append(_remaining.length); buf.append(" offset ").append(_offset); buf.append(" frag ").append(_fragmentNumber); return buf.toString(); } }
/** * The peer did not accept the tunnel join for the given reason (this may be because * of a timeout or an explicit refusal). * */ public void tunnelRequestTimedOut(Hash peer, TunnelId tunnel) { if (!_doLog) return; if ( (tunnel == null) || (peer == null) ) return; StringBuilder buf = new StringBuilder(128); buf.append(getPrefix()); buf.append("tunnel [").append(tunnel.getTunnelId()).append("] timed out on ["); buf.append(getName(peer)).append("]"); addEntry(buf.toString()); }
/** * The peer did not accept the tunnel join for the given reason * */ public void tunnelRejected(Hash peer, TunnelId tunnel, Hash replyThrough, String reason) { if (!_doLog) return; if ( (tunnel == null) || (peer == null) ) return; StringBuilder buf = new StringBuilder(128); buf.append(getPrefix()); buf.append("tunnel [").append(tunnel.getTunnelId()).append("] was rejected by ["); buf.append(getName(peer)).append("] for [").append(reason).append("]"); if (replyThrough != null) buf.append(" with their reply intended to come through [").append(getName(replyThrough)).append("]"); addEntry(buf.toString()); }
/** * We don't know about the given tunnel, so we are dropping a message sent to us by the * given router * * @param id tunnel ID we received a message for * @param from peer that sent us this message (if known) */ public void droppedTunnelMessage(TunnelId id, long msgId, Date expiration, Hash from) { if (!_doLog) return; StringBuilder buf = new StringBuilder(128); buf.append(getPrefix()); buf.append("dropped message ").append(msgId).append(" for unknown tunnel [").append(id.getTunnelId()); buf.append("] from [").append(getName(from)).append("]").append(" expiring on "); buf.append(getTime(expiration.getTime())); addEntry(buf.toString()); }
private static String getName(TunnelCreatorConfig cfg) { if (cfg == null) return "OB??"; if (cfg.getReceiveTunnelId(0) != null) return "OB " + cfg.getReceiveTunnelId(0).getTunnelId(); else if (cfg.getSendTunnelId(0) != null) return "OB " + cfg.getSendTunnelId(0).getTunnelId(); else return "OB??"; }
private static String getName(HopConfig cfg) { if (cfg == null) return "IB??"; if (cfg.getReceiveTunnel() != null) return "IB " + cfg.getReceiveTunnel().getTunnelId(); else if (cfg.getSendTunnel() != null) return "IB " + cfg.getSendTunnel().getTunnelId(); else return "IB??"; }
/** toString */ @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("Fragments for ").append(_messageId).append(": "); for (int i = 0; i <= _highFragmentNum; i++) { ByteArray ba = _fragments[i]; if (ba != null) buf.append(i).append(":").append(ba.getValid()).append(" bytes "); else buf.append(i).append(":missing "); } buf.append(" highest received: ").append(_highFragmentNum); buf.append(" last received? ").append(_lastReceived); buf.append(" lifetime: ").append(DataHelper.formatDuration(_context.clock().now()-_createdOn)); if (_toRouter != null) { buf.append(" targetting ").append(_toRouter.toBase64().substring(0,4)); if (_toTunnel != null) buf.append(":").append(_toTunnel.getTunnelId()); } if (_completed) buf.append(" completed"); if (_releasedAfter > 0) buf.append(" released after " + DataHelper.formatDuration(_releasedAfter)); return buf.toString(); }
@Override public int hashCode() { int rv = 0; if (_gateway != null) rv += _gateway.hashCode(); if (_tunnel != null) rv += 7*_tunnel.getTunnelId(); return rv; }
public void runJob() { RouterInfo info = getContext().netDb().lookupRouterInfoLocally(_target); int stat; if (info != null) { if (_log.shouldLog(Log.DEBUG)) _log.debug("outbound distributor to " + _target + "." + (_tunnel != null ? _tunnel.getTunnelId() + "" : "") + ": found on search"); distribute(_message, info, _tunnel); stat = 1; } else { if (_log.shouldLog(Log.WARN)) _log.warn("outbound distributor to " + _target + "." + (_tunnel != null ? _tunnel.getTunnelId() + "" : "") + ": NOT found on search"); stat = 0; } _context.statManager().addRateData("tunnel.distributeLookupSuccess", stat); } }
long replyTunnel = 0; if (_replyTunnel != null) replyTunnel = _replyTunnel.getTunnelId(); DataHelper.toLong(out, curIndex, 4, replyTunnel); curIndex += 4;
/** write the message body to the output array, starting at the given index */ protected int writeMessageBody(byte out[], int curIndex) throws I2NPMessageException { if ( (_tunnelId == null) || ( (_msg == null) && (_msgData == null) ) ) { _log.log(Log.CRIT, "failing to write out gateway message"); throw new I2NPMessageException("Not enough data to write out (id=" + _tunnelId + " data=" + _msg + ")"); } DataHelper.toLong(out, curIndex, 4, _tunnelId.getTunnelId()); curIndex += 4; synchronized (this) { if (_msgData == null) { _msgData = _msg.toByteArray(); _msg = null; } } DataHelper.toLong(out, curIndex, 2, _msgData.length); curIndex += 2; // where is this coming from? if (curIndex + _msgData.length > out.length) { String txt = "output buffer too small idx: " + curIndex + " len: " + _msgData.length + " outlen: " + out.length; _log.error(txt); throw new I2NPMessageException(txt); } System.arraycopy(_msgData, 0, out, curIndex, _msgData.length); curIndex += _msgData.length; return curIndex; }
/** * Add a message to be sent down the tunnel (immediately forwarding it to the * {@link InboundMessageDistributor} or {@link OutboundMessageDistributor}, as * necessary). * * @param msg message to be sent through the tunnel * @param toRouter router to send to after the endpoint (or null for endpoint processing) * @param toTunnel tunnel to send to after the endpoint (or null for endpoint or router processing) */ @Override public void add(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) { if (_log.shouldLog(Log.DEBUG)) _log.debug("zero hop gateway: distribute " + (_config.isInbound() ? "inbound" : " outbound") + " to " + (toRouter != null ? toRouter.toBase64().substring(0,4) : "" ) + "." + (toTunnel != null ? toTunnel.getTunnelId() + "" : "") + ": " + msg); if (_config.isInbound()) { _inDistributor.distribute(msg, toRouter, toTunnel); } else { _outDistributor.distribute(msg, toRouter, toTunnel); } _config.incrementProcessedMessages(); } }
curIndex += 4; if (_tunnelId.getTunnelId() <= 0) throw new I2NPMessageException("Invalid tunnel Id " + _tunnelId);
(msg.getMessageExpiration() > maxTime) || (msg.getMessage().getMessageExpiration() > maxTime) ) { if (_log.shouldLog(Log.WARN)) _log.warn("Not dispatching a gateway message for tunnel " + msg.getTunnelId().getTunnelId() + " as the wrapper's expiration is in " + DataHelper.formatDuration(msg.getMessageExpiration()-before) + " and/or the content's expiration is in " + DataHelper.formatDuration(msg.getMessage().getMessageExpiration()-before) _context.messageHistory().tunnelDispatched(msg.getUniqueId(), msg.getMessage().getUniqueId(), msg.getTunnelId().getTunnelId(), "inbound gateway"); gw.add(msg); _context.statManager().addRateData("tunnel.dispatchInbound", 1); } else { _context.messageHistory().droppedTunnelGatewayMessageUnknown(msg.getUniqueId(), msg.getTunnelId().getTunnelId()); int level = (_context.router().getUptime() > 10*60*1000 ? Log.WARN : Log.INFO); if (_log.shouldLog(level)) _log.log(level, "no matching tunnel for id=" + msg.getTunnelId().getTunnelId() + ": gateway message expiring in " + DataHelper.formatDuration(msg.getMessageExpiration()-_context.clock().now())
public void receiveComplete(I2NPMessage msg, Hash toRouter, TunnelId toTunnel) { if (toRouter == null) { // Delivery type LOCAL is not supported at the OBEP // We don't have any use for it yet. // Don't send to OutboundMessageDistributor.distribute() which will NPE or fail if (_log.shouldLog(Log.WARN)) _log.warn("Dropping msg at OBEP with unsupported delivery instruction type LOCAL"); return; } if (_log.shouldLog(Log.DEBUG)) _log.debug("outbound tunnel " + _config + " received a full message: " + msg + " to be forwarded on to " + toRouter.toBase64().substring(0,4) + (toTunnel != null ? ":" + toTunnel.getTunnelId() : "")); int size = msg.getMessageSize(); // don't drop it if we are the target boolean toUs = _context.routerHash().equals(toRouter); if ((!toUs) && _context.tunnelDispatcher().shouldDropParticipatingMessage(TunnelDispatcher.Location.OBEP, msg.getType(), size)) return; // this overstates the stat somewhat, but ok for now //int kb = (size + 1023) / 1024; //for (int i = 0; i < kb; i++) // _config.incrementSentMessages(); if (!toUs) _context.bandwidthLimiter().sentParticipatingMessage(size); _outDistributor.distribute(msg, toRouter, toTunnel); } }
public void distribute(I2NPMessage msg, Hash target, TunnelId tunnel) { if (shouldDrop(target)) { _context.statManager().addRateData("tunnel.dropAtOBEP", 1); if (_log.shouldLog(Log.WARN)) _log.warn("Drop msg at OBEP (new conn throttle) to " + target + ' ' + msg); return; } RouterInfo info = _context.netDb().lookupRouterInfoLocally(target); if (info == null) { if (_log.shouldLog(Log.INFO)) _log.info("outbound distributor to " + target + "." + (tunnel != null ? tunnel.getTunnelId() + "" : "") + ": no info locally, searching..."); // TODO - should we set the search timeout based on the message timeout, // or is that a bad idea due to clock skews? _context.netDb().lookupRouterInfo(target, new DistributeJob(_context, msg, target, tunnel), null, MAX_DISTRIBUTE_TIME); return; } else { distribute(msg, info, tunnel); } }