mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-30 23:02:15 +00:00
Show reverse DNS for nodes in PeerMonitor.
This commit is contained in:
parent
4bcb550796
commit
3b7a494a37
@ -34,6 +34,7 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.event.WindowAdapter;
|
import java.awt.event.WindowAdapter;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +46,8 @@ public class PeerMonitor {
|
|||||||
private PeerTableModel peerTableModel;
|
private PeerTableModel peerTableModel;
|
||||||
private PeerTableRenderer peerTableRenderer;
|
private PeerTableRenderer peerTableRenderer;
|
||||||
|
|
||||||
|
private final HashMap<Peer, String> reverseDnsLookups = new HashMap<Peer, String>();
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
BriefLogFormatter.init();
|
BriefLogFormatter.init();
|
||||||
new PeerMonitor();
|
new PeerMonitor();
|
||||||
@ -66,15 +69,33 @@ public class PeerMonitor {
|
|||||||
@Override
|
@Override
|
||||||
public void onPeerConnected(final Peer peer, int peerCount) {
|
public void onPeerConnected(final Peer peer, int peerCount) {
|
||||||
refreshUI();
|
refreshUI();
|
||||||
|
lookupReverseDNS(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPeerDisconnected(Peer peer, int peerCount) {
|
public void onPeerDisconnected(final Peer peer, int peerCount) {
|
||||||
refreshUI();
|
refreshUI();
|
||||||
|
synchronized (reverseDnsLookups) {
|
||||||
|
reverseDnsLookups.remove(peer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void lookupReverseDNS(final Peer peer) {
|
||||||
|
new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// This can take a looooong time.
|
||||||
|
String reverseDns = peer.getAddress().getAddr().getCanonicalHostName();
|
||||||
|
synchronized (reverseDnsLookups) {
|
||||||
|
reverseDnsLookups.put(peer, reverseDns);
|
||||||
|
}
|
||||||
|
refreshUI();
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshUI() {
|
private void refreshUI() {
|
||||||
// Tell the Swing UI thread to redraw the peers table.
|
// Tell the Swing UI thread to redraw the peers table.
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@ -117,11 +138,12 @@ public class PeerMonitor {
|
|||||||
peerTable.setDefaultRenderer(String.class, peerTableRenderer);
|
peerTable.setDefaultRenderer(String.class, peerTableRenderer);
|
||||||
peerTable.setDefaultRenderer(Integer.class, peerTableRenderer);
|
peerTable.setDefaultRenderer(Integer.class, peerTableRenderer);
|
||||||
peerTable.setDefaultRenderer(Long.class, peerTableRenderer);
|
peerTable.setDefaultRenderer(Long.class, peerTableRenderer);
|
||||||
|
peerTable.getColumnModel().getColumn(0).setPreferredWidth(300);
|
||||||
|
|
||||||
JScrollPane scrollPane = new JScrollPane(peerTable);
|
JScrollPane scrollPane = new JScrollPane(peerTable);
|
||||||
window.getContentPane().add(scrollPane, BorderLayout.CENTER);
|
window.getContentPane().add(scrollPane, BorderLayout.CENTER);
|
||||||
window.pack();
|
window.pack();
|
||||||
window.setSize(640, 480);
|
window.setSize(720, 480);
|
||||||
window.setVisible(true);
|
window.setVisible(true);
|
||||||
|
|
||||||
// Refresh the UI every half second to get the latest ping times. The event handler runs in the UI thread.
|
// Refresh the UI every half second to get the latest ping times. The event handler runs in the UI thread.
|
||||||
@ -156,7 +178,7 @@ public class PeerMonitor {
|
|||||||
@Override
|
@Override
|
||||||
public String getColumnName(int i) {
|
public String getColumnName(int i) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case IP_ADDRESS: return "IP address";
|
case IP_ADDRESS: return "Address";
|
||||||
case PROTOCOL_VERSION: return "Protocol version";
|
case PROTOCOL_VERSION: return "Protocol version";
|
||||||
case USER_AGENT: return "User Agent";
|
case USER_AGENT: return "User Agent";
|
||||||
case CHAIN_HEIGHT: return "Chain height";
|
case CHAIN_HEIGHT: return "Chain height";
|
||||||
@ -189,7 +211,7 @@ public class PeerMonitor {
|
|||||||
Peer peer = pendingPeers.get(row - connectedPeers.size());
|
Peer peer = pendingPeers.get(row - connectedPeers.size());
|
||||||
switch (col) {
|
switch (col) {
|
||||||
case IP_ADDRESS:
|
case IP_ADDRESS:
|
||||||
return peer.getAddress().getAddr().getHostAddress();
|
return getAddressForPeer(peer);
|
||||||
case PROTOCOL_VERSION:
|
case PROTOCOL_VERSION:
|
||||||
return 0;
|
return 0;
|
||||||
case CHAIN_HEIGHT:
|
case CHAIN_HEIGHT:
|
||||||
@ -203,7 +225,7 @@ public class PeerMonitor {
|
|||||||
Peer peer = connectedPeers.get(row);
|
Peer peer = connectedPeers.get(row);
|
||||||
switch (col) {
|
switch (col) {
|
||||||
case IP_ADDRESS:
|
case IP_ADDRESS:
|
||||||
return peer.getAddress().getAddr().getHostAddress();
|
return getAddressForPeer(peer);
|
||||||
case PROTOCOL_VERSION:
|
case PROTOCOL_VERSION:
|
||||||
return Integer.toString(peer.getPeerVersionMessage().clientVersion);
|
return Integer.toString(peer.getPeerVersionMessage().clientVersion);
|
||||||
case USER_AGENT:
|
case USER_AGENT:
|
||||||
@ -217,6 +239,17 @@ public class PeerMonitor {
|
|||||||
default: throw new RuntimeException();
|
default: throw new RuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object getAddressForPeer(Peer peer) {
|
||||||
|
String s;
|
||||||
|
synchronized (reverseDnsLookups) {
|
||||||
|
s = reverseDnsLookups.get(peer);
|
||||||
|
}
|
||||||
|
if (s != null)
|
||||||
|
return s;
|
||||||
|
else
|
||||||
|
return peer.getAddress().getAddr().getHostAddress();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PeerTableRenderer extends JLabel implements TableCellRenderer {
|
private class PeerTableRenderer extends JLabel implements TableCellRenderer {
|
||||||
|
Loading…
Reference in New Issue
Block a user