use of com.biglybt.platform.PlatformManagerPingCallback in project BiglyBT by BiglySoftware.
the class NetworkAdminImpl method getRoute.
public NetworkAdminNode[] getRoute(InetAddress interface_address, InetAddress target, final int max_millis, final NetworkAdminRouteListener listener) throws NetworkAdminException {
PlatformManager pm = PlatformManagerFactory.getPlatformManager();
if (!canTraceRoute()) {
throw (new NetworkAdminException("No trace-route capability on platform"));
}
final List nodes = new ArrayList();
try {
pm.traceRoute(interface_address, target, new PlatformManagerPingCallback() {
private long start_time = SystemTime.getCurrentTime();
@Override
public boolean reportNode(int distance, InetAddress address, int millis) {
boolean timeout = false;
if (max_millis >= 0) {
long now = SystemTime.getCurrentTime();
if (now < start_time) {
start_time = now;
}
if (now - start_time >= max_millis) {
timeout = true;
}
}
NetworkAdminNode node = null;
if (address != null) {
node = new networkNode(address, distance, millis);
nodes.add(node);
}
boolean result;
if (listener == null) {
result = true;
} else {
if (node == null) {
result = listener.timeout(distance);
} else {
result = listener.foundNode(node, distance, millis);
}
}
return (result && !timeout);
}
});
} catch (PlatformManagerException e) {
throw (new NetworkAdminException("trace-route failed", e));
}
return ((NetworkAdminNode[]) nodes.toArray(new NetworkAdminNode[nodes.size()]));
}
use of com.biglybt.platform.PlatformManagerPingCallback in project BiglyBT by BiglySoftware.
the class NetworkAdminImpl method pingTarget.
public NetworkAdminNode pingTarget(InetAddress interface_address, InetAddress target, final int max_millis, final NetworkAdminRouteListener listener) throws NetworkAdminException {
PlatformManager pm = PlatformManagerFactory.getPlatformManager();
if (!canPing()) {
throw (new NetworkAdminException("No ping capability on platform"));
}
final NetworkAdminNode[] nodes = { null };
try {
pm.ping(interface_address, target, new PlatformManagerPingCallback() {
private long start_time = SystemTime.getCurrentTime();
@Override
public boolean reportNode(int distance, InetAddress address, int millis) {
boolean timeout = false;
if (max_millis >= 0) {
long now = SystemTime.getCurrentTime();
if (now < start_time) {
start_time = now;
}
if (now - start_time >= max_millis) {
timeout = true;
}
}
NetworkAdminNode node = null;
if (address != null) {
node = new networkNode(address, distance, millis);
nodes[0] = node;
}
boolean result;
if (listener == null) {
result = false;
} else {
if (node == null) {
result = listener.timeout(distance);
} else {
result = listener.foundNode(node, distance, millis);
}
}
return (result && !timeout);
}
});
} catch (PlatformManagerException e) {
throw (new NetworkAdminException("ping failed", e));
}
return (nodes[0]);
}
Aggregations