* Transports:

- Really fix IPv6-only option
   - Treat RFC 4193 addresses fc00::/7 as local
   - Log tweaks, javadocs
This commit is contained in:
zzz
2013-07-26 22:39:35 +00:00
parent b2d72f90ce
commit 482787fbc3
6 changed files with 34 additions and 9 deletions

View File

@@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 11;
public final static long BUILD = 12;
/** for example "-test" */
public final static String EXTRA = "";

View File

@@ -19,7 +19,10 @@ import net.i2p.data.RouterInfo;
import net.i2p.router.OutNetMessage;
/**
* Defines a way to send a message to another peer and start listening for messages
* Defines a way to send a message to another peer and start listening for messages.
*
* To implement a new or pluggable I2P transport, implement this interface,
* and add it to TransportManager.startListening().
*
*/
public interface Transport {
@@ -116,6 +119,7 @@ public interface Transport {
/** Who to notify on message availability */
public void setListener(TransportEventListener listener);
/** The unique identity of this Transport */
public String getStyle();
public int countPeers();
@@ -129,13 +133,13 @@ public interface Transport {
public void renderStatusHTML(Writer out, String urlBase, int sortFlags) throws IOException;
public short getReachabilityStatus();
public void recheckReachability();
public boolean isBacklogged(Hash dest);
public boolean isBacklogged(Hash peer);
/**
* Was the peer UNreachable (outbound only) the last time we tried it?
* This is NOT reset if the peer contacts us and it is never expired.
*/
public boolean wasUnreachable(Hash dest);
public boolean wasUnreachable(Hash peer);
public boolean isUnreachable(Hash peer);
public boolean isEstablished(Hash peer);

View File

@@ -341,7 +341,7 @@ public abstract class TransportImpl implements Transport {
long allTime = now - msg.getCreated();
if (allTime > 5*1000) {
if (_log.shouldLog(Log.INFO))
_log.info("Took too long from preperation to afterSend(ok? " + sendSuccessful
_log.info("Took too long from preparation to afterSend(ok? " + sendSuccessful
+ "): " + allTime + "ms/" + sendTime + "ms after failing on: "
+ msg.getFailedTransports() + " and succeeding on " + getStyle());
if ( (allTime > 60*1000) && (sendSuccessful) ) {
@@ -604,12 +604,13 @@ public abstract class TransportImpl implements Transport {
adj = -1; break;
case IPV6_ONLY:
adj = -10;
// IPv4 addresses not rejected in isPubliclyRoutable()
/**** IPv6 addresses will be rejected in isPubliclyRoutable()
for (Iterator<RouterAddress> iter = rv.iterator(); iter.hasNext(); ) {
byte[] ip = iter.next().getIP();
if (ip != null && ip.length == 4)
iter.remove();
}
****/
break;
}
if (rv.size() > 1)
@@ -824,8 +825,10 @@ public abstract class TransportImpl implements Transport {
* @param addr non-null
*/
protected boolean isPubliclyRoutable(byte addr[]) {
TransportUtil.IPv6Config cfg = getIPv6Config();
return TransportUtil.isPubliclyRoutable(addr,
getIPv6Config() != TransportUtil.IPv6Config.IPV6_DISABLED);
cfg != TransportUtil.IPv6Config.IPV6_ONLY,
cfg != TransportUtil.IPv6Config.IPV6_DISABLED);
}
private static final String BUNDLE_NAME = "net.i2p.router.web.messages";

View File

@@ -98,7 +98,17 @@ public abstract class TransportUtil {
* @since IPv6 moved from TransportImpl
*/
public static boolean isPubliclyRoutable(byte addr[], boolean allowIPv6) {
return isPubliclyRoutable(addr, true, allowIPv6);
}
/**
* @param addr non-null
* @since IPv6
*/
public static boolean isPubliclyRoutable(byte addr[], boolean allowIPv4, boolean allowIPv6) {
if (addr.length == 4) {
if (!allowIPv4)
return false;
int a0 = addr[0] & 0xFF;
if (a0 == 127) return false;
if (a0 == 10) return false;
@@ -116,6 +126,10 @@ public abstract class TransportUtil {
// disallow 2002::/16 (6to4 RFC 3056)
if (addr[0] == 0x20 && addr[1] == 0x02)
return false;
// disallow fc00::/8 and fd00::/8 (Unique local addresses RFC 4193)
// not recognized as local by InetAddress
if ((addr[0] & 0xfe) == 0xfc)
return false;
try {
InetAddress ia = InetAddress.getByAddress(addr);
return

View File

@@ -672,7 +672,7 @@ class PacketBuilder {
return null;
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("Sending request");
_log.debug("Sending request to " + Addresses.toString(toIP));
// now for the body
byte[] x = state.getSentX();

View File

@@ -1562,6 +1562,10 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
(Arrays.equals(ip, getExternalIP()) && !allowLocal())) {
continue;
}
} else {
// introducers
if (getIPv6Config() == IPV6_ONLY)
continue;
}
return addr;
}
@@ -2056,7 +2060,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
public void failed(OutNetMessage msg, String reason) {
if (msg == null) return;
if (_log.shouldLog(Log.INFO))
_log.info("Sending message failed: " + msg, new Exception("failed from"));
_log.info("Send failed: " + reason + " msg: " + msg, new Exception("failed from"));
if (_context.messageHistory().getDoLog())
_context.messageHistory().sendMessage(msg.getMessageType(), msg.getMessageId(), msg.getExpiration(),