* SSU fixes for per-address and IPv6 MTU

* MTU.main() print all interfaces
This commit is contained in:
zzz
2013-05-11 21:39:25 +00:00
parent 5e51c6abef
commit 0be3beb30e
3 changed files with 60 additions and 15 deletions

View File

@ -72,11 +72,29 @@ abstract class MTU {
/****
public static void main(String args[]) {
System.out.println("Cmd line interfaces:");
for (int i = 0; i < args.length; i++) {
try {
InetAddress test = InetAddress.getByName(args[i]);
System.out.println("MTU of " + args[i] + " is " + getMTU(test));
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("All interfaces:");
try {
InetAddress test = InetAddress.getByName(args[0]);
System.out.println("MTU is " + getMTU(test));
} catch (Exception e) {
e.printStackTrace();
Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces();
if (ifcs != null) {
while (ifcs.hasMoreElements()) {
NetworkInterface ifc = ifcs.nextElement();
for(Enumeration<InetAddress> addrs = ifc.getInetAddresses(); addrs.hasMoreElements();) {
InetAddress addr = addrs.nextElement();
System.out.println("MTU of " + addr.getHostAddress() + " is " + getMTU(addr));
}
}
}
} catch (SocketException se) {
System.out.println("no interfaces");
}
}
****/

View File

@ -267,7 +267,8 @@ class PeerState {
* and so PacketBuilder.buildPacket() works correctly.
*/
public static final int MIN_MTU = 620;
public static final int MIN_IPV6_MTU = 1280;
/** 1276 */
public static final int MIN_IPV6_MTU = MTU.rectify(1280);
private static final int DEFAULT_MTU = MIN_MTU;
/*
@ -319,11 +320,12 @@ class PeerState {
if (remoteIP.length == 4) {
_mtu = DEFAULT_MTU;
_mtuReceive = DEFAULT_MTU;
_largeMTU = transport.getMTU(false);
} else {
_mtu = MIN_IPV6_MTU;
_mtuReceive = MIN_IPV6_MTU;
_largeMTU = transport.getMTU(true);
}
_largeMTU = transport.getMTU();
//_mtuLastChecked = -1;
_lastACKSend = -1;
_rto = INIT_RTO;

View File

@ -82,6 +82,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
private long _lastInboundReceivedOn;
private final DHSessionKeyBuilder.Factory _dhFactory;
private int _mtu;
private int _mtu_ipv6;
/**
* Do we have a public IPv6 address?
* TODO periodically update via CSFI.NetMonitor?
@ -243,6 +245,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_introducersSelectedOn = -1;
_lastInboundReceivedOn = -1;
_mtu = PeerState.LARGE_MTU;
_mtu_ipv6 = PeerState.MIN_IPV6_MTU;
setupPort();
_needsRebuild = true;
@ -552,20 +555,29 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
/**
* Set the MTU for the socket interface at addr.
* @param addr null ok
* @return the mtu
* @since 0.9.2
*/
private void setMTU(InetAddress addr) {
private int setMTU(InetAddress addr) {
String p = _context.getProperty(PROP_DEFAULT_MTU);
if (p != null) {
try {
_mtu = MTU.rectify(Integer.parseInt(p));
return;
_mtu_ipv6 = Math.max(_mtu, PeerState.MIN_IPV6_MTU);
return _mtu;
} catch (NumberFormatException nfe) {}
}
int mtu = MTU.getMTU(addr);
if (mtu <= 0)
mtu = PeerState.LARGE_MTU;
_mtu = mtu;
if (addr != null && addr.getAddress().length == 16) {
if (mtu <= 0)
mtu = PeerState.MIN_IPV6_MTU;
_mtu_ipv6 = mtu;
} else {
if (mtu <= 0)
mtu = PeerState.LARGE_MTU;
_mtu = mtu;
}
return mtu;
}
/**
@ -574,8 +586,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
* @return limited to range PeerState.MIN_MTU to PeerState.LARGE_MTU.
* @since 0.9.2
*/
int getMTU() {
return _mtu;
int getMTU(boolean ipv6) {
// TODO multiple interfaces of each type
return ipv6 ? _mtu_ipv6 : _mtu;
}
/**
@ -1751,11 +1764,23 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
options.setProperty(UDPAddress.PROP_CAPACITY, ""+UDPAddress.CAPACITY_TESTING + UDPAddress.CAPACITY_INTRODUCER);
// MTU since 0.9.2
if (_mtu < PeerState.LARGE_MTU)
options.setProperty(UDPAddress.PROP_MTU, Integer.toString(_mtu));
int mtu;
if (host == null) {
mtu = _mtu;
} else {
try {
InetAddress ia = InetAddress.getByName(host);
mtu = setMTU(ia);
} catch (UnknownHostException uhe) {
mtu = _mtu;
}
}
if (mtu < PeerState.LARGE_MTU)
options.setProperty(UDPAddress.PROP_MTU, Integer.toString(mtu));
if (directIncluded || introducersIncluded) {
// This is called via TransportManager.configTransports() before startup(), prevent NPE
// Note that peers won't connect to us without this - see EstablishmentManager
if (_introKey != null)
options.setProperty(UDPAddress.PROP_INTRO_KEY, _introKey.toBase64());