* Transport: Adjust bids based on address cost

- More finals
This commit is contained in:
zzz
2010-02-13 15:16:12 +00:00
parent 4f70a7d0fe
commit 2700028da7
3 changed files with 65 additions and 54 deletions

View File

@ -39,7 +39,7 @@ public class RouterAddress extends DataStructureImpl {
* contacting this router. The value 0 means free and 255 means really expensive. * contacting this router. The value 0 means free and 255 means really expensive.
* No value above 255 is allowed. * No value above 255 is allowed.
* *
* @deprecated unused for now * Unused before 0.7.12
*/ */
public int getCost() { public int getCost() {
return _cost; return _cost;
@ -49,7 +49,7 @@ public class RouterAddress extends DataStructureImpl {
* Configure the weighted cost of using the address. * Configure the weighted cost of using the address.
* No value above 255 is allowed. * No value above 255 is allowed.
* *
* NTCP is set to 10 and SSU to 5, but it's unused. * NTCP is set to 10 and SSU to 5 by default, unused before 0.7.12
*/ */
public void setCost(int cost) { public void setCost(int cost) {
_cost = cost; _cost = cost;

View File

@ -33,26 +33,27 @@ import net.i2p.util.Log;
* *
*/ */
public class NTCPTransport extends TransportImpl { public class NTCPTransport extends TransportImpl {
private Log _log; private final Log _log;
private SharedBid _fastBid; private final SharedBid _fastBid;
private SharedBid _slowBid; private final SharedBid _slowBid;
private final SharedBid _slowCostBid;
/** save some conns for inbound */ /** save some conns for inbound */
private SharedBid _nearCapacityBid; private final SharedBid _nearCapacityBid;
private SharedBid _transientFail; private final SharedBid _nearCapacityCostBid;
private final SharedBid _transientFail;
private final Object _conLock; private final Object _conLock;
private Map<Hash, NTCPConnection> _conByIdent; private final Map<Hash, NTCPConnection> _conByIdent;
private NTCPAddress _myAddress; private NTCPAddress _myAddress;
private EventPumper _pumper; private final EventPumper _pumper;
private Reader _reader; private final Reader _reader;
private net.i2p.router.transport.ntcp.Writer _writer; private net.i2p.router.transport.ntcp.Writer _writer;
/** /**
* list of NTCPConnection of connections not yet established that we * list of NTCPConnection of connections not yet established that we
* want to remove on establishment or close on timeout * want to remove on establishment or close on timeout
*/ */
private final List _establishing; private final List<NTCPConnection> _establishing;
private List _sent; private final NTCPSendFinisher _finisher;
private NTCPSendFinisher _finisher;
private long _lastBadSkew; private long _lastBadSkew;
private static final long[] RATES = { 10*60*1000 }; private static final long[] RATES = { 10*60*1000 };
@ -128,7 +129,6 @@ public class NTCPTransport extends TransportImpl {
_conLock = new Object(); _conLock = new Object();
_conByIdent = new HashMap(64); _conByIdent = new HashMap(64);
_sent = new ArrayList(4);
_finisher = new NTCPSendFinisher(ctx, this); _finisher = new NTCPSendFinisher(ctx, this);
_pumper = new EventPumper(ctx, this); _pumper = new EventPumper(ctx, this);
@ -137,7 +137,9 @@ public class NTCPTransport extends TransportImpl {
_fastBid = new SharedBid(25); // best _fastBid = new SharedBid(25); // best
_slowBid = new SharedBid(70); // better than ssu unestablished, but not better than ssu established _slowBid = new SharedBid(70); // better than ssu unestablished, but not better than ssu established
_slowCostBid = new SharedBid(85);
_nearCapacityBid = new SharedBid(90); // not better than ssu - save our conns for inbound _nearCapacityBid = new SharedBid(90); // not better than ssu - save our conns for inbound
_nearCapacityCostBid = new SharedBid(105);
_transientFail = new SharedBid(TransportBid.TRANSIENT_FAIL); _transientFail = new SharedBid(TransportBid.TRANSIENT_FAIL);
} }
@ -313,11 +315,18 @@ public class NTCPTransport extends TransportImpl {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("slow bid when trying to send to " + peer.toBase64()); _log.debug("slow bid when trying to send to " + peer.toBase64());
if (haveCapacity()) if (haveCapacity()) {
if (addr.getCost() > NTCPAddress.DEFAULT_COST)
return _slowCostBid;
else
return _slowBid; return _slowBid;
} else {
if (addr.getCost() > NTCPAddress.DEFAULT_COST)
return _nearCapacityCostBid;
else else
return _nearCapacityBid; return _nearCapacityBid;
} }
}
public boolean allowConnection() { public boolean allowConnection() {
return countActivePeers() < getMaxConnections(); return countActivePeers() < getMaxConnections();

View File

@ -39,7 +39,7 @@ import net.i2p.util.SimpleTimer;
* *
*/ */
public class UDPTransport extends TransportImpl implements TimedWeightedPriorityMessageQueue.FailedListener { public class UDPTransport extends TransportImpl implements TimedWeightedPriorityMessageQueue.FailedListener {
private Log _log; private final Log _log;
private UDPEndpoint _endpoint; private UDPEndpoint _endpoint;
/** Peer (Hash) to PeerState */ /** Peer (Hash) to PeerState */
private final Map<Hash, PeerState> _peersByIdent; private final Map<Hash, PeerState> _peersByIdent;
@ -47,15 +47,15 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
private final Map<RemoteHostId, PeerState> _peersByRemoteHost; private final Map<RemoteHostId, PeerState> _peersByRemoteHost;
private PacketHandler _handler; private PacketHandler _handler;
private EstablishmentManager _establisher; private EstablishmentManager _establisher;
private MessageQueue _outboundMessages; private final MessageQueue _outboundMessages;
private OutboundMessageFragments _fragments; private OutboundMessageFragments _fragments;
private OutboundMessageFragments.ActiveThrottle _activeThrottle; private final OutboundMessageFragments.ActiveThrottle _activeThrottle;
private OutboundRefiller _refiller; private OutboundRefiller _refiller;
private PacketPusher _pusher; private PacketPusher _pusher;
private InboundMessageFragments _inboundFragments; private InboundMessageFragments _inboundFragments;
private UDPFlooder _flooder; private UDPFlooder _flooder;
private PeerTestManager _testManager; private PeerTestManager _testManager;
private IntroductionManager _introManager; private final IntroductionManager _introManager;
private ExpirePeerEvent _expireEvent; private ExpirePeerEvent _expireEvent;
private PeerTestEvent _testEvent; private PeerTestEvent _testEvent;
private short _reachabilityStatus; private short _reachabilityStatus;
@ -75,22 +75,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
/** introduction key */ /** introduction key */
private SessionKey _introKey; private SessionKey _introKey;
/** shared fast bid for connected peers */
private TransportBid _fastBid;
/** shared slow bid for unconnected peers when we want to prefer UDP */
private TransportBid _slowBid;
/** save some conns for inbound */
private TransportBid _nearCapacityBid;
/** shared slow bid for unconnected peers */
private TransportBid _slowestBid;
/** shared fast bid for unconnected peers when we want to prefer UDP */
private TransportBid _fastPreferredBid;
/** shared slow bid for unconnected peers when we want to always prefer UDP */
private TransportBid _slowPreferredBid;
private TransportBid _transientFail;
/** list of RemoteHostId for peers whose packets we want to drop outright */ /** list of RemoteHostId for peers whose packets we want to drop outright */
private final List _dropList; private final List<RemoteHostId> _dropList;
private int _expireTimeout; private int _expireTimeout;
@ -158,6 +144,18 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
private static final int TEST_FREQUENCY = 13*60*1000; private static final int TEST_FREQUENCY = 13*60*1000;
public static final long[] RATES = { 10*60*1000 }; public static final long[] RATES = { 10*60*1000 };
private static final int[] BID_VALUES = { 15, 20, 50, 65, 80, 95, 100, 115, TransportBid.TRANSIENT_FAIL };
private static final int FAST_PREFERRED_BID = 0;
private static final int SLOW_PREFERRED_BID = 1;
private static final int FAST_BID = 2;
private static final int SLOW_BID = 3;
private static final int SLOWEST_BID = 4;
private static final int SLOWEST_COST_BID = 5;
private static final int NEAR_CAPACITY_BID = 6;
private static final int NEAR_CAPACITY_COST_BID = 7;
private static final int TRANSIENT_FAIL_BID = 8;
private final TransportBid[] _cachedBid;
public UDPTransport(RouterContext ctx) { public UDPTransport(RouterContext ctx) {
super(ctx); super(ctx);
_context = ctx; _context = ctx;
@ -171,13 +169,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_outboundMessages = mq; _outboundMessages = mq;
_activeThrottle = mq; _activeThrottle = mq;
_fastBid = new SharedBid(50); _cachedBid = new SharedBid[BID_VALUES.length];
_slowBid = new SharedBid(65); for (int i = 0; i < BID_VALUES.length; i++) {
_fastPreferredBid = new SharedBid(15); _cachedBid[i] = new SharedBid(BID_VALUES[i]);
_slowPreferredBid = new SharedBid(20); }
_slowestBid = new SharedBid(80);
_nearCapacityBid = new SharedBid(100);
_transientFail = new SharedBid(TransportBid.TRANSIENT_FAIL);
_fragments = new OutboundMessageFragments(_context, this, _activeThrottle); _fragments = new OutboundMessageFragments(_context, this, _activeThrottle);
_inboundFragments = new InboundMessageFragments(_context, _fragments, this); _inboundFragments = new InboundMessageFragments(_context, _fragments, this);
@ -1014,9 +1009,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("bidding on a message to an established peer: " + peer); _log.debug("bidding on a message to an established peer: " + peer);
if (preferUDP()) if (preferUDP())
return _fastPreferredBid; return _cachedBid[FAST_PREFERRED_BID];
else else
return _fastBid; return _cachedBid[FAST_BID];
} else { } else {
// If we don't have a port, all is lost // If we don't have a port, all is lost
if ( _reachabilityStatus == CommSystemFacade.STATUS_HOSED) { if ( _reachabilityStatus == CommSystemFacade.STATUS_HOSED) {
@ -1043,7 +1038,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
} }
} }
if (!allowConnection()) if (!allowConnection())
return _transientFail; return _cachedBid[TRANSIENT_FAIL_BID];
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("bidding on a message to an unestablished peer: " + to.toBase64()); _log.debug("bidding on a message to an unestablished peer: " + to.toBase64());
@ -1060,13 +1055,20 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
} }
if (alwaysPreferUDP() || count < MIN_PEERS || if (alwaysPreferUDP() || count < MIN_PEERS ||
(introducersRequired() && _introManager.introducerCount() < MIN_INTRODUCER_POOL)) (introducersRequired() && _introManager.introducerCount() < MIN_INTRODUCER_POOL))
return _slowPreferredBid; return _cachedBid[SLOW_PREFERRED_BID];
else if (preferUDP()) else if (preferUDP())
return _slowBid; return _cachedBid[SLOW_BID];
else if (haveCapacity()) else if (haveCapacity()) {
return _slowestBid; if (addr.getCost() > DEFAULT_COST)
return _cachedBid[SLOWEST_COST_BID];
else else
return _nearCapacityBid; return _cachedBid[SLOWEST_BID];
} else {
if (addr.getCost() > DEFAULT_COST)
return _cachedBid[NEAR_CAPACITY_COST_BID];
else
return _cachedBid[NEAR_CAPACITY_BID];
}
} }
} }