forked from I2P_Developers/i2p.i2p
transport cleanups: final, init, pkg private
This commit is contained in:
@@ -36,15 +36,14 @@ import net.i2p.util.SimpleTimer;
|
|||||||
import net.i2p.util.Translate;
|
import net.i2p.util.Translate;
|
||||||
|
|
||||||
public class CommSystemFacadeImpl extends CommSystemFacade {
|
public class CommSystemFacadeImpl extends CommSystemFacade {
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private RouterContext _context;
|
private final RouterContext _context;
|
||||||
private TransportManager _manager;
|
private TransportManager _manager;
|
||||||
private GeoIP _geoIP;
|
private GeoIP _geoIP;
|
||||||
|
|
||||||
public CommSystemFacadeImpl(RouterContext context) {
|
public CommSystemFacadeImpl(RouterContext context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
_log = _context.logManager().getLog(CommSystemFacadeImpl.class);
|
_log = _context.logManager().getLog(CommSystemFacadeImpl.class);
|
||||||
_manager = null;
|
|
||||||
_context.statManager().createRateStat("transport.getBidsJobTime", "How long does it take?", "Transport", new long[] { 10*60*1000l });
|
_context.statManager().createRateStat("transport.getBidsJobTime", "How long does it take?", "Transport", new long[] { 10*60*1000l });
|
||||||
startGeoIP();
|
startGeoIP();
|
||||||
}
|
}
|
||||||
|
@@ -31,18 +31,18 @@ import net.i2p.util.Log;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class FIFOBandwidthLimiter {
|
public class FIFOBandwidthLimiter {
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private I2PAppContext _context;
|
private final I2PAppContext _context;
|
||||||
private final List<Request> _pendingInboundRequests;
|
private final List<Request> _pendingInboundRequests;
|
||||||
private final List<Request> _pendingOutboundRequests;
|
private final List<Request> _pendingOutboundRequests;
|
||||||
/** how many bytes we can consume for inbound transmission immediately */
|
/** how many bytes we can consume for inbound transmission immediately */
|
||||||
private AtomicInteger _availableInbound = new AtomicInteger();
|
private final AtomicInteger _availableInbound = new AtomicInteger();
|
||||||
/** how many bytes we can consume for outbound transmission immediately */
|
/** how many bytes we can consume for outbound transmission immediately */
|
||||||
private AtomicInteger _availableOutbound = new AtomicInteger();
|
private final AtomicInteger _availableOutbound = new AtomicInteger();
|
||||||
/** how many bytes we can queue up for bursting */
|
/** how many bytes we can queue up for bursting */
|
||||||
private AtomicInteger _unavailableInboundBurst = new AtomicInteger();
|
private final AtomicInteger _unavailableInboundBurst = new AtomicInteger();
|
||||||
/** how many bytes we can queue up for bursting */
|
/** how many bytes we can queue up for bursting */
|
||||||
private AtomicInteger _unavailableOutboundBurst = new AtomicInteger();
|
private final AtomicInteger _unavailableOutboundBurst = new AtomicInteger();
|
||||||
/** how large _unavailableInbound can get */
|
/** how large _unavailableInbound can get */
|
||||||
private int _maxInboundBurst;
|
private int _maxInboundBurst;
|
||||||
/** how large _unavailableInbound can get */
|
/** how large _unavailableInbound can get */
|
||||||
@@ -56,14 +56,14 @@ public class FIFOBandwidthLimiter {
|
|||||||
/** shortcut of whether our inbound rate is unlimited */
|
/** shortcut of whether our inbound rate is unlimited */
|
||||||
private boolean _inboundUnlimited;
|
private boolean _inboundUnlimited;
|
||||||
/** lifetime counter of bytes received */
|
/** lifetime counter of bytes received */
|
||||||
private AtomicLong _totalAllocatedInboundBytes = new AtomicLong();
|
private final AtomicLong _totalAllocatedInboundBytes = new AtomicLong();
|
||||||
/** lifetime counter of bytes sent */
|
/** lifetime counter of bytes sent */
|
||||||
private AtomicLong _totalAllocatedOutboundBytes = new AtomicLong();
|
private final AtomicLong _totalAllocatedOutboundBytes = new AtomicLong();
|
||||||
/** lifetime counter of tokens available for use but exceeded our maxInboundBurst size */
|
/** lifetime counter of tokens available for use but exceeded our maxInboundBurst size */
|
||||||
private AtomicLong _totalWastedInboundBytes = new AtomicLong();
|
private final AtomicLong _totalWastedInboundBytes = new AtomicLong();
|
||||||
/** lifetime counter of tokens available for use but exceeded our maxOutboundBurst size */
|
/** lifetime counter of tokens available for use but exceeded our maxOutboundBurst size */
|
||||||
private AtomicLong _totalWastedOutboundBytes = new AtomicLong();
|
private final AtomicLong _totalWastedOutboundBytes = new AtomicLong();
|
||||||
private FIFOBandwidthRefiller _refiller;
|
private final FIFOBandwidthRefiller _refiller;
|
||||||
|
|
||||||
private long _lastTotalSent;
|
private long _lastTotalSent;
|
||||||
private long _lastTotalReceived;
|
private long _lastTotalReceived;
|
||||||
@@ -73,8 +73,6 @@ public class FIFOBandwidthLimiter {
|
|||||||
private float _sendBps15s;
|
private float _sendBps15s;
|
||||||
private float _recvBps15s;
|
private float _recvBps15s;
|
||||||
|
|
||||||
private static int __id = 0;
|
|
||||||
|
|
||||||
public /* static */ long now() {
|
public /* static */ long now() {
|
||||||
// dont use the clock().now(), since that may jump
|
// dont use the clock().now(), since that may jump
|
||||||
return System.currentTimeMillis();
|
return System.currentTimeMillis();
|
||||||
@@ -98,13 +96,9 @@ public class FIFOBandwidthLimiter {
|
|||||||
_pendingOutboundRequests = new ArrayList(16);
|
_pendingOutboundRequests = new ArrayList(16);
|
||||||
_lastTotalSent = _totalAllocatedOutboundBytes.get();
|
_lastTotalSent = _totalAllocatedOutboundBytes.get();
|
||||||
_lastTotalReceived = _totalAllocatedInboundBytes.get();
|
_lastTotalReceived = _totalAllocatedInboundBytes.get();
|
||||||
_sendBps = 0;
|
|
||||||
_recvBps = 0;
|
|
||||||
_lastStatsUpdated = now();
|
_lastStatsUpdated = now();
|
||||||
_refiller = new FIFOBandwidthRefiller(_context, this);
|
_refiller = new FIFOBandwidthRefiller(_context, this);
|
||||||
I2PThread t = new I2PThread(_refiller);
|
I2PThread t = new I2PThread(_refiller, "BWRefiller", true);
|
||||||
t.setName("BWRefiller" + (++__id));
|
|
||||||
t.setDaemon(true);
|
|
||||||
t.setPriority(I2PThread.NORM_PRIORITY-1);
|
t.setPriority(I2PThread.NORM_PRIORITY-1);
|
||||||
t.start();
|
t.start();
|
||||||
}
|
}
|
||||||
@@ -753,7 +747,7 @@ public class FIFOBandwidthLimiter {
|
|||||||
private int _allocationsSinceWait;
|
private int _allocationsSinceWait;
|
||||||
private boolean _aborted;
|
private boolean _aborted;
|
||||||
private boolean _waited;
|
private boolean _waited;
|
||||||
List<Request> satisfiedBuffer;
|
final List<Request> satisfiedBuffer;
|
||||||
private CompleteListener _lsnr;
|
private CompleteListener _lsnr;
|
||||||
private Object _attachment;
|
private Object _attachment;
|
||||||
|
|
||||||
|
@@ -7,9 +7,9 @@ import net.i2p.I2PAppContext;
|
|||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
public class FIFOBandwidthRefiller implements Runnable {
|
public class FIFOBandwidthRefiller implements Runnable {
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private I2PAppContext _context;
|
private final I2PAppContext _context;
|
||||||
private FIFOBandwidthLimiter _limiter;
|
private final FIFOBandwidthLimiter _limiter;
|
||||||
/** how many KBps do we want to allow? */
|
/** how many KBps do we want to allow? */
|
||||||
private int _inboundKBytesPerSecond;
|
private int _inboundKBytesPerSecond;
|
||||||
/** how many KBps do we want to allow? */
|
/** how many KBps do we want to allow? */
|
||||||
|
@@ -35,7 +35,7 @@ import net.i2p.util.Log;
|
|||||||
*
|
*
|
||||||
* @author zzz
|
* @author zzz
|
||||||
*/
|
*/
|
||||||
public class GeoIP {
|
class GeoIP {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private RouterContext _context;
|
private RouterContext _context;
|
||||||
private final Map<String, String> _codeToName;
|
private final Map<String, String> _codeToName;
|
||||||
|
@@ -21,10 +21,10 @@ import net.i2p.util.Log;
|
|||||||
* pass it on to the transport for processing
|
* pass it on to the transport for processing
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GetBidsJob extends JobImpl {
|
class GetBidsJob extends JobImpl {
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
private CommSystemFacadeImpl _facade;
|
private final CommSystemFacadeImpl _facade;
|
||||||
private OutNetMessage _msg;
|
private final OutNetMessage _msg;
|
||||||
|
|
||||||
public GetBidsJob(RouterContext ctx, CommSystemFacadeImpl facade, OutNetMessage msg) {
|
public GetBidsJob(RouterContext ctx, CommSystemFacadeImpl facade, OutNetMessage msg) {
|
||||||
super(ctx);
|
super(ctx);
|
||||||
|
@@ -37,14 +37,14 @@ import net.i2p.util.Log;
|
|||||||
import net.i2p.util.Translate;
|
import net.i2p.util.Translate;
|
||||||
|
|
||||||
public class TransportManager implements TransportEventListener {
|
public class TransportManager implements TransportEventListener {
|
||||||
private Log _log;
|
private final Log _log;
|
||||||
/**
|
/**
|
||||||
* Converted from List to prevent concurrent modification exceptions.
|
* Converted from List to prevent concurrent modification exceptions.
|
||||||
* If we want more than one transport with the same style we will have to change this.
|
* If we want more than one transport with the same style we will have to change this.
|
||||||
*/
|
*/
|
||||||
private Map<String, Transport> _transports;
|
private final Map<String, Transport> _transports;
|
||||||
private RouterContext _context;
|
private final RouterContext _context;
|
||||||
private UPnPManager _upnpManager;
|
private final UPnPManager _upnpManager;
|
||||||
|
|
||||||
/** default true */
|
/** default true */
|
||||||
public final static String PROP_ENABLE_UDP = "i2np.udp.enable";
|
public final static String PROP_ENABLE_UDP = "i2np.udp.enable";
|
||||||
@@ -63,8 +63,10 @@ public class TransportManager implements TransportEventListener {
|
|||||||
_context.statManager().createRateStat("transport.bidFailNoTransports", "Could not attempt to bid on message, as none of the transports could attempt it", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
|
_context.statManager().createRateStat("transport.bidFailNoTransports", "Could not attempt to bid on message, as none of the transports could attempt it", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
|
||||||
_context.statManager().createRateStat("transport.bidFailAllTransports", "Could not attempt to bid on message, as all of the transports had failed", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
|
_context.statManager().createRateStat("transport.bidFailAllTransports", "Could not attempt to bid on message, as all of the transports had failed", "Transport", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
|
||||||
_transports = new ConcurrentHashMap(2);
|
_transports = new ConcurrentHashMap(2);
|
||||||
if (Boolean.valueOf(_context.getProperty(PROP_ENABLE_UPNP, "true")).booleanValue())
|
if (_context.getBooleanPropertyDefaultTrue(PROP_ENABLE_UPNP))
|
||||||
_upnpManager = new UPnPManager(context, this);
|
_upnpManager = new UPnPManager(context, this);
|
||||||
|
else
|
||||||
|
_upnpManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTransport(Transport transport) {
|
public void addTransport(Transport transport) {
|
||||||
|
@@ -52,7 +52,7 @@ import org.freenetproject.ForwardPortStatus;
|
|||||||
* TODO: Advertise the node like the MDNS plugin does
|
* TODO: Advertise the node like the MDNS plugin does
|
||||||
* TODO: Implement EventListener and react on ip-change
|
* TODO: Implement EventListener and react on ip-change
|
||||||
*/
|
*/
|
||||||
public class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private I2PAppContext _context;
|
private I2PAppContext _context;
|
||||||
|
|
||||||
|
@@ -24,7 +24,7 @@ import org.freenetproject.ForwardPortStatus;
|
|||||||
*
|
*
|
||||||
* @author zzz
|
* @author zzz
|
||||||
*/
|
*/
|
||||||
public class UPnPManager {
|
class UPnPManager {
|
||||||
private Log _log;
|
private Log _log;
|
||||||
private RouterContext _context;
|
private RouterContext _context;
|
||||||
private UPnP _upnp;
|
private UPnP _upnp;
|
||||||
|
Reference in New Issue
Block a user