diff --git a/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java b/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java index 60e43d80553b9e9e5fb9be7825bcf04f40f5a394..14988c2d1aa4a5fe79c00304cf9f55bd0b846cc0 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java +++ b/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java @@ -426,35 +426,6 @@ class EventPumper implements Runnable { } } - /** - * Called by the connection when it has data ready to write. - * If we have bandwidth, calls con.Write() which calls wantsWrite(con). - * If no bandwidth, calls con.queuedWrite(). - */ - public void wantsWrite(NTCPConnection con, byte data[]) { - wantsWrite(con, data, 0, data.length); - } - - /** - * Called by the connection when it has data ready to write. - * If we have bandwidth, calls con.Write() which calls wantsWrite(con). - * If no bandwidth, calls con.queuedWrite(). - * - * @since 0.9.35 off/len version - */ - public void wantsWrite(NTCPConnection con, byte data[], int off, int len) { - ByteBuffer buf = ByteBuffer.wrap(data, off, len); - FIFOBandwidthLimiter.Request req = _context.bandwidthLimiter().requestOutbound(len, 0, "NTCP write");//con, buf); - if (req.getPendingRequested() > 0) { - if (_log.shouldLog(Log.INFO)) - _log.info("queued write on " + con + " for " + len); - _context.statManager().addRateData("ntcp.wantsQueuedWrite", 1); - con.queuedWrite(buf, req); - } else { - con.write(buf); - } - } - /** * Called by the connection when it has data ready to write (after bw allocation). * Only wakeup if new. diff --git a/router/java/src/net/i2p/router/transport/ntcp/InboundEstablishState.java b/router/java/src/net/i2p/router/transport/ntcp/InboundEstablishState.java index ba6dccc97eb3f4d7434848fcb091010e965e41a9..c5fba8f0423152036fc250b5acac5063c1623388 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/InboundEstablishState.java +++ b/router/java/src/net/i2p/router/transport/ntcp/InboundEstablishState.java @@ -537,7 +537,7 @@ class InboundEstablishState extends EstablishBase implements NTCP2Payload.Payloa changeState(State.IB_NTCP2_SENT_Y); // send it all at once - _transport.getPumper().wantsWrite(_con, tmp); + _con.wantsWrite(tmp); } /** diff --git a/router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java b/router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java index 80ad3cc0e9e3d45252ebe7d2381cf772facda098..fe70004ed92cf8556b3fcb47e30766c34d3f1e3e 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java +++ b/router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java @@ -919,7 +919,7 @@ public class NTCPConnection implements Closeable { } _log.debug(buf.toString()); } - _transport.getPumper().wantsWrite(this, enc); + wantsWrite(enc); toLong8LE(_sendSipIV, 0, sipIV); } @@ -990,7 +990,38 @@ public class NTCPConnection implements Closeable { private void addOBRequest(FIFOBandwidthLimiter.Request req) { _bwOutRequests.add(req); } - + + /** + * Call when there is data ready to write. + * If we have bandwidth, calls write() which calls EventPumnper.wantsWrite(con). + * If no bandwidth, calls queuedWrite(). + * + * @since moved from EventPumper in 0.9.52 + */ + void wantsWrite(byte data[]) { + wantsWrite(data, 0, data.length); + } + + /** + * Call when there is data ready to write. + * If we have bandwidth, calls write() which calls EventPumnper.wantsWrite(con). + * If no bandwidth, calls queuedWrite(). + * + * @since 0.9.35 off/len version, moved from EventPumper in 0.9.52 + */ + void wantsWrite(byte data[], int off, int len) { + ByteBuffer buf = ByteBuffer.wrap(data, off, len); + FIFOBandwidthLimiter.Request req = _context.bandwidthLimiter().requestOutbound(len, 0, "NTCP write"); + if (req.getPendingRequested() > 0) { + if (_log.shouldInfo()) + _log.info("queued write on " + toString() + " for " + len); + _context.statManager().addRateData("ntcp.wantsQueuedWrite", 1); + queuedWrite(buf, req); + } else { + write(buf); + } + } + /** * We have read the data in the buffer, but we can't process it locally yet, * because we're choked by the bandwidth limiter. Cache the contents of @@ -1004,7 +1035,7 @@ public class NTCPConnection implements Closeable { } /** ditto for writes */ - void queuedWrite(ByteBuffer buf, FIFOBandwidthLimiter.Request req) { + private void queuedWrite(ByteBuffer buf, FIFOBandwidthLimiter.Request req) { req.attach(buf); req.setCompleteListener(_outboundListener); addOBRequest(req); @@ -1034,7 +1065,7 @@ public class NTCPConnection implements Closeable { * The contents of the buffer have been encrypted / padded / etc and have * been fully allocated for the bandwidth limiter. */ - void write(ByteBuffer buf) { + private void write(ByteBuffer buf) { _writeBufs.offer(buf); _transport.getPumper().wantsWrite(this); } diff --git a/router/java/src/net/i2p/router/transport/ntcp/OutboundNTCP2State.java b/router/java/src/net/i2p/router/transport/ntcp/OutboundNTCP2State.java index 7ecc42a0d7b3eac5650b4457a8c11bab022eef4f..4e53146c1169a006c3997709069593e1d1a76a53 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/OutboundNTCP2State.java +++ b/router/java/src/net/i2p/router/transport/ntcp/OutboundNTCP2State.java @@ -254,7 +254,7 @@ class OutboundNTCP2State implements EstablishState { changeState(State.OB_SENT_X); // send it all at once - _transport.getPumper().wantsWrite(_con, _tmp, 0, MSG1_SIZE + padlen1); + _con.wantsWrite(_tmp, 0, MSG1_SIZE + padlen1); } /** @@ -392,7 +392,7 @@ class OutboundNTCP2State implements EstablishState { // send it all at once if (_log.shouldDebug()) _log.debug("Sending msg3, part 1 is:\n" + net.i2p.util.HexDump.dump(tmp, 0, MSG3P1_SIZE)); - _transport.getPumper().wantsWrite(_con, tmp); + _con.wantsWrite(tmp); if (_log.shouldDebug()) _log.debug("After msg 3: " + _handshakeState.toString()); setDataPhase();