forked from I2P_Developers/i2p.i2p
SSU2: Fix last check of local RI for relay
Expire relay token quickly Log tweaks
This commit is contained in:
@@ -2523,12 +2523,22 @@ class EstablishmentManager {
|
||||
* @since 0.9.54
|
||||
*/
|
||||
public Token getInboundToken(RemoteHostId peer) {
|
||||
return getInboundToken(peer, IB_TOKEN_EXPIRATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a token that can be used later for the peer to connect to us
|
||||
*
|
||||
* @param expiration time from now
|
||||
* @since 0.9.55
|
||||
*/
|
||||
public Token getInboundToken(RemoteHostId peer, long expiration) {
|
||||
long token;
|
||||
do {
|
||||
token = _context.random().nextLong();
|
||||
} while (token == 0);
|
||||
// TODO shorten expiration based on _inboundTokens size
|
||||
long expires = _context.clock().now() + IB_TOKEN_EXPIRATION;
|
||||
long expires = _context.clock().now() + expiration;
|
||||
Token tok = new Token(token, expires);
|
||||
synchronized(_inboundTokens) {
|
||||
_inboundTokens.put(peer, tok);
|
||||
|
||||
@@ -904,7 +904,10 @@ class IntroductionManager {
|
||||
*/
|
||||
private boolean receiveRelayIntro(PeerState2 bob, Hash alice, byte[] data, int retryCount) {
|
||||
RouterInfo aliceRI = null;
|
||||
if (retryCount < 5 && !_context.banlist().isBanlisted(alice)) {
|
||||
if (retryCount >= 5) {
|
||||
// last chance
|
||||
aliceRI = _context.netDb().lookupRouterInfoLocally(alice);
|
||||
} else if (!_context.banlist().isBanlisted(alice)) {
|
||||
aliceRI = _context.netDb().lookupRouterInfoLocally(alice);
|
||||
if (aliceRI == null) {
|
||||
if (_log.shouldInfo())
|
||||
@@ -1044,7 +1047,7 @@ class IntroductionManager {
|
||||
long token;
|
||||
if (rcode == SSU2Util.RELAY_ACCEPT) {
|
||||
RemoteHostId aliceID = new RemoteHostId(testIP, testPort);
|
||||
EstablishmentManager.Token tok = _transport.getEstablisher().getInboundToken(aliceID);
|
||||
EstablishmentManager.Token tok = _transport.getEstablisher().getInboundToken(aliceID, 60*1000);
|
||||
token = tok.token;
|
||||
} else {
|
||||
token = 0;
|
||||
@@ -1060,6 +1063,7 @@ class IntroductionManager {
|
||||
UDPPacket packet = _builder2.buildRelayResponse(data, bob);
|
||||
if (_log.shouldInfo())
|
||||
_log.info("Send relay response " + rcode + " as charlie " + " nonce " + nonce + " to bob " + bob +
|
||||
" with token " + token +
|
||||
" for alice " + Addresses.toString(testIP, testPort) + ' ' + aliceRI);
|
||||
_transport.send(packet);
|
||||
if (rcode == SSU2Util.RELAY_ACCEPT) {
|
||||
|
||||
@@ -286,7 +286,7 @@ class PacketBuilder2 {
|
||||
" data size " + dataSize +
|
||||
" pkt size " + (off + ipHeaderSize) +
|
||||
" MTU " + currentMTU +
|
||||
" Fragments: " + DataHelper.toString(fragments), new Exception());
|
||||
" Fragments: " + DataHelper.toString(fragments) /* , new Exception() */ );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1329,6 +1329,7 @@ public class PeerState {
|
||||
*/
|
||||
synchronized void packetReceived(int size) {
|
||||
_packetsReceived++;
|
||||
// SSU2 overhead header + MAC == SSU overhead IV + MAC
|
||||
if (_remoteIP.length == 4) {
|
||||
size += OVERHEAD_SIZE;
|
||||
} else {
|
||||
|
||||
@@ -377,8 +377,8 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback
|
||||
}
|
||||
|
||||
public void gotRI(RouterInfo ri, boolean isHandshake, boolean flood) throws DataFormatException {
|
||||
if (_log.shouldDebug())
|
||||
_log.debug("Got updated RI");
|
||||
if (_log.shouldInfo())
|
||||
_log.info("Got RI in data phase " + ri + "\non: " + this);
|
||||
try {
|
||||
Hash h = ri.getHash();
|
||||
if (h.equals(_context.routerHash()))
|
||||
@@ -481,8 +481,9 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback
|
||||
}
|
||||
|
||||
public void gotFragment(byte[] data, int off, int len, long messageId, int frag, boolean isLast) throws DataFormatException {
|
||||
if (_log.shouldDebug())
|
||||
_log.debug("Got FRAGMENT block: " + messageId + " fragment " + frag + " isLast? " + isLast);
|
||||
if (_log.shouldInfo())
|
||||
_log.info("Got FRAGMENT block: " + messageId + " fragment " + frag + " len " + len +
|
||||
" isLast? " + isLast + " on " + _remotePeer.toBase64());
|
||||
InboundMessageState state;
|
||||
boolean messageComplete = false;
|
||||
boolean messageExpired = false;
|
||||
|
||||
@@ -2064,16 +2064,16 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
||||
for (int i = 0; i < count; i++) {
|
||||
long exp = ua.getIntroducerExpiration(i);
|
||||
if (exp > 0 && exp < now + INTRODUCER_EXPIRATION_MARGIN) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn((ipv6 ? "IPv6" : "IPv4") + " Introducer " + i + " expiring soon, need to replace");
|
||||
if (_log.shouldInfo())
|
||||
_log.info((ipv6 ? "IPv6" : "IPv4") + " Introducer " + i + " expiring soon, need to replace");
|
||||
continue;
|
||||
}
|
||||
long tag = ua.getIntroducerTag(i);
|
||||
if (_introManager.isInboundTagValid(tag)) {
|
||||
valid++;
|
||||
} else {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn((ipv6 ? "IPv6" : "IPv4") + " Introducer " + i + " no longer connected, need to replace");
|
||||
if (_log.shouldInfo())
|
||||
_log.info((ipv6 ? "IPv6" : "IPv4") + " Introducer " + i + " no longer connected, need to replace");
|
||||
}
|
||||
}
|
||||
long sinceSelected = now - (ipv6 ? _v6IntroducersSelectedOn : _v4IntroducersSelectedOn);
|
||||
|
||||
Reference in New Issue
Block a user