forked from I2P_Developers/i2p.i2p
FloodfillPeerSelector, ProfileOrganizer: Use 8 bytes for IPv6 check
Transports: - Add IPv6 column on /peers - Other minor /peers cleanup
This commit is contained in:
@ -294,7 +294,7 @@ class FloodfillPeerSelector extends PeerSelector {
|
|||||||
* @since 0.9.5 modified from ProfileOrganizer
|
* @since 0.9.5 modified from ProfileOrganizer
|
||||||
*/
|
*/
|
||||||
private Set<Integer> maskedIPSet(Hash peer, RouterInfo pinfo, int mask) {
|
private Set<Integer> maskedIPSet(Hash peer, RouterInfo pinfo, int mask) {
|
||||||
Set<Integer> rv = new HashSet(2);
|
Set<Integer> rv = new HashSet(4);
|
||||||
byte[] commIP = _context.commSystem().getIP(peer);
|
byte[] commIP = _context.commSystem().getIP(peer);
|
||||||
if (commIP != null)
|
if (commIP != null)
|
||||||
rv.add(maskedIP(commIP, mask));
|
rv.add(maskedIP(commIP, mask));
|
||||||
@ -313,12 +313,22 @@ class FloodfillPeerSelector extends PeerSelector {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* generate an arbitrary unique value for this ip/mask (mask = 1-4)
|
* generate an arbitrary unique value for this ip/mask (mask = 1-4)
|
||||||
|
* If IPv6, force mask = 8.
|
||||||
* @since 0.9.5 copied from ProfileOrganizer
|
* @since 0.9.5 copied from ProfileOrganizer
|
||||||
*/
|
*/
|
||||||
private static Integer maskedIP(byte[] ip, int mask) {
|
private static Integer maskedIP(byte[] ip, int mask) {
|
||||||
int rv = 0;
|
int rv = ip[0];
|
||||||
for (int i = 0; i < mask; i++)
|
if (ip.length == 16) {
|
||||||
rv = (rv << 8) | (ip[i] & 0xff);
|
for (int i = 1; i < 8; i++) {
|
||||||
|
rv <<= i * 4;
|
||||||
|
rv ^= ip[i];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 1; i < mask; i++) {
|
||||||
|
rv <<= 8;
|
||||||
|
rv ^= ip[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
return Integer.valueOf(rv);
|
return Integer.valueOf(rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1264,7 +1264,7 @@ public class ProfileOrganizer {
|
|||||||
* @return an opaque set of masked IPs for this peer
|
* @return an opaque set of masked IPs for this peer
|
||||||
*/
|
*/
|
||||||
private Set<Integer> maskedIPSet(Hash peer, int mask) {
|
private Set<Integer> maskedIPSet(Hash peer, int mask) {
|
||||||
Set<Integer> rv = new HashSet(2);
|
Set<Integer> rv = new HashSet(4);
|
||||||
byte[] commIP = _context.commSystem().getIP(peer);
|
byte[] commIP = _context.commSystem().getIP(peer);
|
||||||
if (commIP != null)
|
if (commIP != null)
|
||||||
rv.add(maskedIP(commIP, mask));
|
rv.add(maskedIP(commIP, mask));
|
||||||
@ -1282,11 +1282,23 @@ public class ProfileOrganizer {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** generate an arbitrary unique value for this ip/mask (mask = 1-4) */
|
/**
|
||||||
|
* generate an arbitrary unique value for this ip/mask (mask = 1-4)
|
||||||
|
* If IPv6, force mask = 8.
|
||||||
|
*/
|
||||||
private static Integer maskedIP(byte[] ip, int mask) {
|
private static Integer maskedIP(byte[] ip, int mask) {
|
||||||
int rv = 0;
|
int rv = ip[0];
|
||||||
for (int i = 0; i < mask; i++)
|
if (ip.length == 16) {
|
||||||
rv = (rv << 8) | (ip[i] & 0xff);
|
for (int i = 1; i < 8; i++) {
|
||||||
|
rv <<= i * 4;
|
||||||
|
rv ^= ip[i];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = 1; i < mask; i++) {
|
||||||
|
rv <<= 8;
|
||||||
|
rv ^= ip[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
return Integer.valueOf(rv);
|
return Integer.valueOf(rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.i2p.router.transport.ntcp;
|
package net.i2p.router.transport.ntcp;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.Inet6Address;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.SelectionKey;
|
import java.nio.channels.SelectionKey;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
@ -87,7 +88,7 @@ class NTCPConnection {
|
|||||||
private final NTCPTransport _transport;
|
private final NTCPTransport _transport;
|
||||||
private final boolean _isInbound;
|
private final boolean _isInbound;
|
||||||
private volatile boolean _closed;
|
private volatile boolean _closed;
|
||||||
private RouterAddress _remAddr;
|
private final RouterAddress _remAddr;
|
||||||
private RouterIdentity _remotePeer;
|
private RouterIdentity _remotePeer;
|
||||||
private long _clockSkew; // in seconds
|
private long _clockSkew; // in seconds
|
||||||
/**
|
/**
|
||||||
@ -161,6 +162,7 @@ class NTCPConnection {
|
|||||||
_log = ctx.logManager().getLog(getClass());
|
_log = ctx.logManager().getLog(getClass());
|
||||||
_created = System.currentTimeMillis();
|
_created = System.currentTimeMillis();
|
||||||
_transport = transport;
|
_transport = transport;
|
||||||
|
_remAddr = null;
|
||||||
_chan = chan;
|
_chan = chan;
|
||||||
_readBufs = new ConcurrentLinkedQueue();
|
_readBufs = new ConcurrentLinkedQueue();
|
||||||
_writeBufs = new ConcurrentLinkedQueue();
|
_writeBufs = new ConcurrentLinkedQueue();
|
||||||
@ -212,15 +214,42 @@ class NTCPConnection {
|
|||||||
_prevReadBlock = new byte[BLOCK_SIZE];
|
_prevReadBlock = new byte[BLOCK_SIZE];
|
||||||
_transport.establishing(this);
|
_transport.establishing(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valid for inbound; valid for outbound shortly after creation
|
||||||
|
*/
|
||||||
public SocketChannel getChannel() { return _chan; }
|
public SocketChannel getChannel() { return _chan; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valid for inbound; valid for outbound shortly after creation
|
||||||
|
*/
|
||||||
public SelectionKey getKey() { return _conKey; }
|
public SelectionKey getKey() { return _conKey; }
|
||||||
public void setChannel(SocketChannel chan) { _chan = chan; }
|
public void setChannel(SocketChannel chan) { _chan = chan; }
|
||||||
public void setKey(SelectionKey key) { _conKey = key; }
|
public void setKey(SelectionKey key) { _conKey = key; }
|
||||||
public boolean isInbound() { return _isInbound; }
|
public boolean isInbound() { return _isInbound; }
|
||||||
public boolean isEstablished() { return _established; }
|
public boolean isEstablished() { return _established; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since IPv6
|
||||||
|
*/
|
||||||
|
public boolean isIPv6() {
|
||||||
|
return _chan != null &&
|
||||||
|
_chan.socket().getInetAddress() instanceof Inet6Address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only valid during establishment; null later
|
||||||
|
*/
|
||||||
public EstablishState getEstablishState() { return _establishState; }
|
public EstablishState getEstablishState() { return _establishState; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only valid for outbound; null for inbound
|
||||||
|
*/
|
||||||
public RouterAddress getRemoteAddress() { return _remAddr; }
|
public RouterAddress getRemoteAddress() { return _remAddr; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Valid for outbound; valid for inbound after handshake
|
||||||
|
*/
|
||||||
public RouterIdentity getRemotePeer() { return _remotePeer; }
|
public RouterIdentity getRemotePeer() { return _remotePeer; }
|
||||||
public void setRemotePeer(RouterIdentity ident) { _remotePeer = ident; }
|
public void setRemotePeer(RouterIdentity ident) { _remotePeer = ident; }
|
||||||
|
|
||||||
|
@ -1052,7 +1052,7 @@ public class NTCPTransport extends TransportImpl {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderStatusHTML(java.io.Writer out, String urlBase, int sortFlags) throws IOException {
|
public void renderStatusHTML(java.io.Writer out, String urlBase, int sortFlags) throws IOException {
|
||||||
TreeSet peers = new TreeSet(getComparator(sortFlags));
|
TreeSet<NTCPConnection> peers = new TreeSet(getComparator(sortFlags));
|
||||||
peers.addAll(_conByIdent.values());
|
peers.addAll(_conByIdent.values());
|
||||||
|
|
||||||
long offsetTotal = 0;
|
long offsetTotal = 0;
|
||||||
@ -1070,6 +1070,7 @@ public class NTCPTransport extends TransportImpl {
|
|||||||
"<table>\n" +
|
"<table>\n" +
|
||||||
"<tr><th><a href=\"#def.peer\">").append(_("Peer")).append("</a></th>" +
|
"<tr><th><a href=\"#def.peer\">").append(_("Peer")).append("</a></th>" +
|
||||||
"<th>").append(_("Dir")).append("</th>" +
|
"<th>").append(_("Dir")).append("</th>" +
|
||||||
|
"<th>").append(_("IPv6")).append("</th>" +
|
||||||
"<th align=\"right\"><a href=\"#def.idle\">").append(_("Idle")).append("</a></th>" +
|
"<th align=\"right\"><a href=\"#def.idle\">").append(_("Idle")).append("</a></th>" +
|
||||||
"<th align=\"right\"><a href=\"#def.rate\">").append(_("In/Out")).append("</a></th>" +
|
"<th align=\"right\"><a href=\"#def.rate\">").append(_("In/Out")).append("</a></th>" +
|
||||||
"<th align=\"right\"><a href=\"#def.up\">").append(_("Up")).append("</a></th>" +
|
"<th align=\"right\"><a href=\"#def.up\">").append(_("Up")).append("</a></th>" +
|
||||||
@ -1082,8 +1083,7 @@ public class NTCPTransport extends TransportImpl {
|
|||||||
" </tr>\n");
|
" </tr>\n");
|
||||||
out.write(buf.toString());
|
out.write(buf.toString());
|
||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
for (Iterator iter = peers.iterator(); iter.hasNext(); ) {
|
for (NTCPConnection con : peers) {
|
||||||
NTCPConnection con = (NTCPConnection)iter.next();
|
|
||||||
buf.append("<tr><td class=\"cells\" align=\"left\" nowrap>");
|
buf.append("<tr><td class=\"cells\" align=\"left\" nowrap>");
|
||||||
buf.append(_context.commSystem().renderPeerHTML(con.getRemotePeer().calculateHash()));
|
buf.append(_context.commSystem().renderPeerHTML(con.getRemotePeer().calculateHash()));
|
||||||
//byte[] ip = getIP(con.getRemotePeer().calculateHash());
|
//byte[] ip = getIP(con.getRemotePeer().calculateHash());
|
||||||
@ -1094,6 +1094,11 @@ public class NTCPTransport extends TransportImpl {
|
|||||||
buf.append("<img src=\"/themes/console/images/inbound.png\" alt=\"Inbound\" title=\"").append(_("Inbound")).append("\"/>");
|
buf.append("<img src=\"/themes/console/images/inbound.png\" alt=\"Inbound\" title=\"").append(_("Inbound")).append("\"/>");
|
||||||
else
|
else
|
||||||
buf.append("<img src=\"/themes/console/images/outbound.png\" alt=\"Outbound\" title=\"").append(_("Outbound")).append("\"/>");
|
buf.append("<img src=\"/themes/console/images/outbound.png\" alt=\"Outbound\" title=\"").append(_("Outbound")).append("\"/>");
|
||||||
|
buf.append("</td><td class=\"cells\" align=\"center\">");
|
||||||
|
if (con.isIPv6())
|
||||||
|
buf.append("✓");
|
||||||
|
else
|
||||||
|
buf.append(" ");
|
||||||
buf.append("</td><td class=\"cells\" align=\"right\">");
|
buf.append("</td><td class=\"cells\" align=\"right\">");
|
||||||
buf.append(DataHelper.formatDuration2(con.getTimeSinceReceive()));
|
buf.append(DataHelper.formatDuration2(con.getTimeSinceReceive()));
|
||||||
buf.append(THINSP).append(DataHelper.formatDuration2(con.getTimeSinceSend()));
|
buf.append(THINSP).append(DataHelper.formatDuration2(con.getTimeSinceSend()));
|
||||||
@ -1142,7 +1147,8 @@ public class NTCPTransport extends TransportImpl {
|
|||||||
|
|
||||||
if (!peers.isEmpty()) {
|
if (!peers.isEmpty()) {
|
||||||
// buf.append("<tr> <td colspan=\"11\"><hr></td></tr>\n");
|
// buf.append("<tr> <td colspan=\"11\"><hr></td></tr>\n");
|
||||||
buf.append("<tr class=\"tablefooter\"><td align=\"center\"><b>").append(peers.size()).append(' ').append(_("peers")).append("</b></td><td> </td><td> ");
|
buf.append("<tr class=\"tablefooter\"><td colspan=\"4\" align=\"left\"><b>").append(_("SUMMARY"))
|
||||||
|
.append("</b>");
|
||||||
buf.append("</td><td align=\"center\"><b>").append(formatRate(bpsRecv/1024)).append(THINSP).append(formatRate(bpsSend/1024)).append("</b>");
|
buf.append("</td><td align=\"center\"><b>").append(formatRate(bpsRecv/1024)).append(THINSP).append(formatRate(bpsSend/1024)).append("</b>");
|
||||||
buf.append("</td><td align=\"center\"><b>").append(DataHelper.formatDuration2(totalUptime/peers.size()));
|
buf.append("</td><td align=\"center\"><b>").append(DataHelper.formatDuration2(totalUptime/peers.size()));
|
||||||
buf.append("</b></td><td align=\"center\"><b>").append(DataHelper.formatDuration2(offsetTotal*1000/peers.size()));
|
buf.append("</b></td><td align=\"center\"><b>").append(DataHelper.formatDuration2(offsetTotal*1000/peers.size()));
|
||||||
|
@ -694,6 +694,12 @@ class PeerState {
|
|||||||
public int getConcurrentSendWindow() { return _concurrentMessagesAllowed; }
|
public int getConcurrentSendWindow() { return _concurrentMessagesAllowed; }
|
||||||
public int getConsecutiveSendRejections() { return _consecutiveRejections; }
|
public int getConsecutiveSendRejections() { return _consecutiveRejections; }
|
||||||
public boolean isInbound() { return _isInbound; }
|
public boolean isInbound() { return _isInbound; }
|
||||||
|
|
||||||
|
/** @since IPv6 */
|
||||||
|
public boolean isIPv6() {
|
||||||
|
return _remoteIP.length == 16;
|
||||||
|
}
|
||||||
|
|
||||||
public long getIntroducerTime() { return _lastIntroducerTime; }
|
public long getIntroducerTime() { return _lastIntroducerTime; }
|
||||||
public void setIntroducerTime() { _lastIntroducerTime = _context.clock().now(); }
|
public void setIntroducerTime() { _lastIntroducerTime = _context.clock().now(); }
|
||||||
|
|
||||||
|
@ -2449,6 +2449,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
appendSortLinks(buf, urlBase, sortFlags, _("Sort by peer hash"), FLAG_ALPHA);
|
appendSortLinks(buf, urlBase, sortFlags, _("Sort by peer hash"), FLAG_ALPHA);
|
||||||
buf.append("</th><th class=\"smallhead\" nowrap><a href=\"#def.dir\" title=\"")
|
buf.append("</th><th class=\"smallhead\" nowrap><a href=\"#def.dir\" title=\"")
|
||||||
.append(_("Direction/Introduction")).append("\">").append(_("Dir"))
|
.append(_("Direction/Introduction")).append("\">").append(_("Dir"))
|
||||||
|
.append("</a></th><th class=\"smallhead\" nowrap><a href=\"#def.ipv6\">").append(_("IPv6"))
|
||||||
.append("</a></th><th class=\"smallhead\" nowrap><a href=\"#def.idle\">").append(_("Idle")).append("</a><br>");
|
.append("</a></th><th class=\"smallhead\" nowrap><a href=\"#def.idle\">").append(_("Idle")).append("</a><br>");
|
||||||
appendSortLinks(buf, urlBase, sortFlags, _("Sort by idle inbound"), FLAG_IDLE_IN);
|
appendSortLinks(buf, urlBase, sortFlags, _("Sort by idle inbound"), FLAG_IDLE_IN);
|
||||||
buf.append(" / ");
|
buf.append(" / ");
|
||||||
@ -2491,8 +2492,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
out.write(buf.toString());
|
out.write(buf.toString());
|
||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
long now = _context.clock().now();
|
long now = _context.clock().now();
|
||||||
for (Iterator iter = peers.iterator(); iter.hasNext(); ) {
|
for (PeerState peer : peers) {
|
||||||
PeerState peer = (PeerState)iter.next();
|
|
||||||
if (now-peer.getLastReceiveTime() > 60*60*1000)
|
if (now-peer.getLastReceiveTime() > 60*60*1000)
|
||||||
continue; // don't include old peers
|
continue; // don't include old peers
|
||||||
|
|
||||||
@ -2536,6 +2536,13 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
//if (ip != null)
|
//if (ip != null)
|
||||||
// buf.append(' ').append(_context.blocklist().toStr(ip));
|
// buf.append(' ').append(_context.blocklist().toStr(ip));
|
||||||
buf.append("</td>");
|
buf.append("</td>");
|
||||||
|
|
||||||
|
buf.append("<td class=\"cells\" align=\"center\">");
|
||||||
|
if (peer.isIPv6())
|
||||||
|
buf.append("✓");
|
||||||
|
else
|
||||||
|
buf.append(" ");
|
||||||
|
buf.append("</td>");
|
||||||
|
|
||||||
long idleIn = Math.max(now-peer.getLastReceiveTime(), 0);
|
long idleIn = Math.max(now-peer.getLastReceiveTime(), 0);
|
||||||
long idleOut = Math.max(now-peer.getLastSendTime(), 0);
|
long idleOut = Math.max(now-peer.getLastSendTime(), 0);
|
||||||
@ -2660,23 +2667,24 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
numPeers++;
|
numPeers++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (numPeers > 0) {
|
||||||
// buf.append("<tr><td colspan=\"16\"><hr></td></tr>\n");
|
// buf.append("<tr><td colspan=\"16\"><hr></td></tr>\n");
|
||||||
buf.append("<tr class=\"tablefooter\"><td colspan=\"3\" align=\"left\"><b>").append(_("SUMMARY")).append("</b></td>" +
|
buf.append("<tr class=\"tablefooter\"><td colspan=\"4\" align=\"left\"><b>").append(_("SUMMARY")).append("</b></td>" +
|
||||||
"<td align=\"center\" nowrap><b>");
|
"<td align=\"center\" nowrap><b>");
|
||||||
buf.append(formatKBps(bpsIn)).append(THINSP).append(formatKBps(bpsOut));
|
buf.append(formatKBps(bpsIn)).append(THINSP).append(formatKBps(bpsOut));
|
||||||
long x = numPeers > 0 ? uptimeMsTotal/numPeers : 0;
|
long x = uptimeMsTotal/numPeers;
|
||||||
buf.append("</b></td>" +
|
buf.append("</b></td>" +
|
||||||
"<td align=\"center\"><b>").append(DataHelper.formatDuration2(x));
|
"<td align=\"center\"><b>").append(DataHelper.formatDuration2(x));
|
||||||
x = numPeers > 0 ? offsetTotal/numPeers : 0;
|
x = offsetTotal/numPeers;
|
||||||
buf.append("</b></td><td align=\"center\"><b>").append(DataHelper.formatDuration2(x)).append("</b></td>\n" +
|
buf.append("</b></td><td align=\"center\"><b>").append(DataHelper.formatDuration2(x)).append("</b></td>\n" +
|
||||||
"<td align=\"center\"><b>");
|
"<td align=\"center\"><b>");
|
||||||
buf.append(numPeers > 0 ? cwinTotal/(numPeers*1024) + "K" : "0K");
|
buf.append(cwinTotal/(numPeers*1024) + "K");
|
||||||
buf.append("</b></td><td> </td>\n" +
|
buf.append("</b></td><td> </td>\n" +
|
||||||
"<td align=\"center\"><b>");
|
"<td align=\"center\"><b>");
|
||||||
buf.append(numPeers > 0 ? DataHelper.formatDuration2(rttTotal/numPeers) : '0');
|
buf.append(DataHelper.formatDuration2(rttTotal/numPeers));
|
||||||
//buf.append("</b></td><td> </td><td align=\"center\"><b>");
|
//buf.append("</b></td><td> </td><td align=\"center\"><b>");
|
||||||
buf.append("</b></td><td align=\"center\"><b>");
|
buf.append("</b></td><td align=\"center\"><b>");
|
||||||
buf.append(numPeers > 0 ? DataHelper.formatDuration2(rtoTotal/numPeers) : '0');
|
buf.append(DataHelper.formatDuration2(rtoTotal/numPeers));
|
||||||
buf.append("</b></td><td align=\"center\"><b>").append(_mtu).append("</b></td><td align=\"center\"><b>");
|
buf.append("</b></td><td align=\"center\"><b>").append(_mtu).append("</b></td><td align=\"center\"><b>");
|
||||||
buf.append(sendTotal).append("</b></td><td align=\"center\"><b>").append(recvTotal).append("</b></td>\n" +
|
buf.append(sendTotal).append("</b></td><td align=\"center\"><b>").append(recvTotal).append("</b></td>\n" +
|
||||||
"<td align=\"center\"><b>").append(resentTotal);
|
"<td align=\"center\"><b>").append(resentTotal);
|
||||||
@ -2696,6 +2704,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
|
|||||||
buf.append(" pBRH direct: ").append(dir).append(" indirect: ").append(indir);
|
buf.append(" pBRH direct: ").append(dir).append(" indirect: ").append(indir);
|
||||||
buf.append("</td></tr>");
|
buf.append("</td></tr>");
|
||||||
}
|
}
|
||||||
|
} // numPeers > 0
|
||||||
buf.append("</table>\n");
|
buf.append("</table>\n");
|
||||||
|
|
||||||
/*****
|
/*****
|
||||||
|
Reference in New Issue
Block a user