Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Traceroute #572

Merged
merged 36 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dc1a549
Basic ICMP Ping working
ssawchenko Sep 7, 2017
3f27d87
Now reading response ip
ssawchenko Sep 7, 2017
0bfd8f6
Removed redundant boost library; renamed to External-Code-Android
ssawchenko Sep 7, 2017
1662e43
temp commit
ssawchenko Sep 14, 2017
8ab47e8
temp
ssawchenko Sep 15, 2017
4f59088
Attempting to fix looping logic; adding more comments
ssawchenko Sep 15, 2017
a8c72ae
Moved tracepath code into separate tracepath.cpp/h files
ssawchenko Sep 15, 2017
2f98378
temp
ssawchenko Sep 18, 2017
d8591f9
Traceroute UI support; added trace route view with list, map translat…
ssawchenko Sep 19, 2017
908b10b
Temp commit, attempting to getprobeDestinationAddressWithTTL returnin…
ssawchenko Sep 20, 2017
24ea0c2
Created ProbeWrapper to be passed back as mapControllerWrapper.probeD…
ssawchenko Sep 20, 2017
b013432
Moved trace code into NodePopup
ssawchenko Sep 21, 2017
cc0a10b
Added highlightRoute to JNI; still in progress
ssawchenko Sep 21, 2017
b91fbc0
Process hops in order
ssawchenko Sep 21, 2017
8719ccd
Updated getIPsFromASN; traceroute now attempting to report on trace f…
ssawchenko Sep 21, 2017
088c68b
Clear lines, better error handling of unknown ASNs
ssawchenko Sep 22, 2017
68a9430
Attempting to pass back hop trip time from tracepath.cpp
ssawchenko Sep 22, 2017
f53a460
CommonCallback onFailure attempts to report network loss issues
ssawchenko Sep 22, 2017
d20c57b
Fixed up Xcode project
ssawchenko Sep 22, 2017
2879f3b
Fixed issue where traceroute UI was getting reset at incorrect times
ssawchenko Sep 22, 2017
3afe002
Fixed up build issues with latest NDK
ssawchenko May 8, 2018
a608f02
Elapsed time seems to work, small format changes
ssawchenko May 8, 2018
de462d4
Fixed crash if ASP IP was not found
ssawchenko May 10, 2018
a320625
Fixed issue where trace could get stuck in a loop
ssawchenko May 10, 2018
f083186
Small code cleanup
ssawchenko May 10, 2018
78ab365
Removed old MK files
ssawchenko May 10, 2018
a8ff4d6
Added style for brand_button; traceroute button now styled
ssawchenko May 10, 2018
83c0c6c
Attempting to fix crash due to bad Garbage Collection
ssawchenko Jun 27, 2018
5b94ba7
Removed commented code
ssawchenko Jun 29, 2018
e8b84ab
Removed commented code; ported isInvalidOrPrivate method from iOS.
ssawchenko Jun 30, 2018
0f3d3e8
Remove unused file
ssawchenko Jul 3, 2018
b1ffd81
Fixed typo in isInvalidOrPrivate
ssawchenko Jul 3, 2018
20485c7
Removed traceroute destination global variables from jniapp.cpp
ssawchenko Jul 3, 2018
220a41e
Fixed crash that would occur if Node popup window closed quickly afte…
ssawchenko Jul 3, 2018
8031a17
Fixed crash when NodePopup showing on timeline (ie. no traceroute)
ssawchenko Jul 12, 2018
dd0313e
Final destination highlight now added (to match iOS); small code cleanup
ssawchenko Jul 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
14 changes: 0 additions & 14 deletions Android-NDK/Android.mk

This file was deleted.

3 changes: 0 additions & 3 deletions Android-NDK/Application.mk

This file was deleted.

12 changes: 8 additions & 4 deletions Android-NDK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
# May also need CMAKE_C_FLAGS?

# Boost C++ lib setup
set(BOOST_ROOT ../Android-Boost)
set(BOOST_LIBRARYDIR ../Android-Boost)
set(BOOST_INCLUDEDIR ../Android-Boost)
set(Boost_INCLUDE_DIR ../Android-Boost)
set(BOOST_ROOT "../External-Code-Android")
set(BOOST_LIBRARYDIR "../External-Code-Android")
set(BOOST_INCLUDEDIR "../External-Code-Android")
set(Boost_INCLUDE_DIR "../External-Code-Android")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost)

# Android-NDK cpp files
include_directories(.)

# Removed local netinet files as they were having include issues. Use platform dependant system libs.
include_directories(${ANDROID_NDK}/platforms/${ANDROID_PLATFORM}/arch-${ANDROID_ABI}/usr/include)

# Android-Boost header files, kept separate to remove them from
# Android Studio's auto symbol generation (was taking ~20 mins to build symbols)
include_directories(${Boost_INCLUDE_DIRS})
Expand All @@ -27,6 +30,7 @@ include_directories(${Boost_INCLUDE_DIRS})
add_library(internetmaprenderer SHARED
jniapi.cpp
renderer.cpp
tracepath.cpp
../Common/Code/OpenGL.cpp
../Common/Code/DisplayLines.cpp
../Common/Code/DisplayNodes.cpp
Expand Down
84 changes: 82 additions & 2 deletions Android-NDK/jniapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
#include <string>
#include "jniapi.h"
#include "renderer.h"
#include "tracepath.h"

#include <../Common/Code/MapController.hpp>
#include <../Common/Code/MapDisplay.hpp>
#include <../Common/Code/Camera.hpp>

#include <arpa/inet.h>

static ANativeWindow *window = 0;
static Renderer *renderer = 0;

static jobject activity = 0;
static JavaVM* javaVM;

static Tracepath *tracepath = 0;

#define HOST_COLUMN_SIZE 52

jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
JNIEnv *env;
Expand Down Expand Up @@ -55,6 +61,29 @@ jobject wrapNode(JNIEnv* jenv, NodePointer node) {
return wrapper;
}

//helper function for wrappers returning a traceroute probe result
jobject wrapProbe(JNIEnv* jenv,
std::string probeAddress,
bool success,
double elapsedMs) {

//strings that need to be freed after
jstring from = jenv->NewStringUTF(probeAddress.c_str());
jclass probeWrapperClass = jenv->FindClass("com/peer1/internetmap/ProbeWrapper");

jmethodID constructor = jenv->GetMethodID(probeWrapperClass, "<init>", "(ZLjava/lang/String;D)V");
//note: if you change this code, triple-check that the argument order matches ProbeWrapper.

jobject probeWrapper = jenv->NewObject(probeWrapperClass, constructor, success, from, elapsedMs);

//free up the strings
jenv->DeleteLocalRef(from);
//oh, we need to free this too
jenv->DeleteLocalRef(probeWrapperClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the local / global ref docs I found when validating the probeWrapper behaviour (https://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/design.html#wp1242), I don't think these calls are required. These should be freed automatically when this function returns.


return probeWrapper;
}

JNIEXPORT jboolean JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnCreate(JNIEnv* jenv, jobject obj, bool smallScreen)
{
LOG("OnCreate");
Expand Down Expand Up @@ -85,7 +114,6 @@ JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnDestroy(JN
{
jenv->DeleteGlobalRef(activity);
activity = NULL;

return;
}

Expand All @@ -108,6 +136,12 @@ JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_rotateRad
renderer->bufferedRotationY(radY);
}

JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_translateYAnimated(JNIEnv* jenv, jobject obj, float translateY, float seconds) {
MapController* controller = renderer->beginControllerModification();
controller->display->camera->translateYAnimated(translateY, 1);
renderer->endControllerModification();
}

JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_startMomentumPanWithVelocity(JNIEnv* jenv, jobject obj,
float vX, float vY) {
MapController* controller = renderer->beginControllerModification();
Expand Down Expand Up @@ -276,6 +310,12 @@ JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_unhoverNo
renderer->endControllerModification();
}

JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_clearHighlightLines(JNIEnv* jenv, jobject obj) {
MapController* controller = renderer->beginControllerModification();
controller->clearHighlightLines();
renderer->endControllerModification();
}

JNIEXPORT jstring JNICALL Java_com_peer1_internetmap_NodeWrapper_nativeFriendlyDescription(JNIEnv* jenv, jobject obj, int index) {
MapController* controller = renderer->beginControllerModification();
if (index < 0 || index >= controller->data->nodes.size()) {
Expand All @@ -289,6 +329,46 @@ JNIEXPORT jstring JNICALL Java_com_peer1_internetmap_NodeWrapper_nativeFriendlyD
return ret;
}

JNIEXPORT jobject JNICALL Java_com_peer1_internetmap_MapControllerWrapper_probeDestinationAddressWithTTL(JNIEnv* jenv, jobject obj,

jstring destinationAddr, int ttl) {
if(!tracepath) {
tracepath = new Tracepath();
}

// Convert destination address
in_addr testaddr;
std::string c_destinationAddr = jenv->GetStringUTFChars(destinationAddr, 0);
inet_aton(c_destinationAddr.c_str(), &testaddr);

// Run probe
probe_result probeResult = tracepath->probeDestinationAddressWithTTL(&testaddr, ttl);

jobject result = wrapProbe(jenv, probeResult.receive_addr, probeResult.success, probeResult.elapsedMs);

return result;
}

JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_highlightRoute(JNIEnv* jenv, jobject obj, jobjectArray nodes, int length) {
MapController* controller = renderer->beginControllerModification();

// Iterate over NodeWrapper array and use indexes to lookup NodePointer.
std::vector<NodePointer> nodesVector;
jclass nodeWrapperClass = jenv->FindClass("com/peer1/internetmap/NodeWrapper");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another possible memory leak. I think this needs to have DeleteLocalRef called on it at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using the code from setTimelinePoint (which creates std::vectorstd::string names) as an example for creating a vector - and the code there did not call DeleteLocalRef.

I will look into this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my previous understanding of when DeleteLocalRef is needed was wrong. A couple of the places that it was used, I think it isn't needed, and it isn't actually needed here.


for (int i=0; i < length; i++) {
jobject obj = (jobject) jenv->GetObjectArrayElement(nodes, i);
jfieldID indexField = jenv->GetFieldID(nodeWrapperClass, "index", "I");
int index = jenv->GetIntField(obj, indexField);

NodePointer node = controller->data->nodeAtIndex(index);
nodesVector.push_back(node);
}

controller->highlightRoute(nodesVector);
renderer->endControllerModification();
}

void DetachThreadFromVM(void) {
javaVM->DetachCurrentThread();
}
Expand Down
77 changes: 38 additions & 39 deletions Android-NDK/jniapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,46 @@
#define JNIAPI_H

extern "C" {
//returns true if create actually created something
JNIEXPORT jboolean JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnCreate(JNIEnv* jenv, jobject obj, bool smallScreen);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnResume(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnPause(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnDestroy(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeSetSurface(JNIEnv* jenv, jobject obj,
jobject surface, float scale);
//returns true if create actually created something
JNIEXPORT jboolean JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnCreate(JNIEnv* jenv, jobject obj, bool smallScreen);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnResume(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnPause(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeOnDestroy(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_InternetMap_nativeSetSurface(JNIEnv* jenv, jobject obj, jobject surface, float scale);

//mapcontroller
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_rotateRadiansXY(JNIEnv* jenv, jobject obj,
float radX, float radY);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_startMomentumPanWithVelocity(JNIEnv* jenv, jobject obj,
float vX, float vY);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_handleTouchDownAtPoint(JNIEnv* jenv, jobject obj,
float x, float y);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_zoomByScale(JNIEnv* jenv, jobject obj,
float scale);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_startMomentumZoomWithVelocity(JNIEnv* jenv, jobject obj,
float velocity);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_rotateRadiansZ(JNIEnv* jenv, jobject obj,
float radians);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_startMomentumRotationWithVelocity(JNIEnv* jenv, jobject obj,
float velocity);
JNIEXPORT bool JNICALL Java_com_peer1_internetmap_MapControllerWrapper_selectHoveredNode(JNIEnv* jenv, jobject obj);
JNIEXPORT jobject JNICALL Java_com_peer1_internetmap_MapControllerWrapper_nodeAtIndex(JNIEnv* jenv, jobject obj, int index);
JNIEXPORT int JNICALL Java_com_peer1_internetmap_MapControllerWrapper_targetNodeIndex(JNIEnv* jenv, jobject obj);
JNIEXPORT jobject JNICALL Java_com_peer1_internetmap_MapControllerWrapper_nodeByAsn(JNIEnv* jenv, jobject obj, jstring asn);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_updateTargetForIndex(JNIEnv* jenv, jobject obj,
int index);
//get every node efficiently
JNIEXPORT jobjectArray JNICALL Java_com_peer1_internetmap_MapControllerWrapper_allNodes(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_setTimelinePoint(JNIEnv* jenv, jobject obj, jstring year);
JNIEXPORT jobjectArray JNICALL Java_com_peer1_internetmap_MapControllerWrapper_visualizationNames(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_setVisualization(JNIEnv* jenv, jobject obj, int index);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_deselectCurrentNode(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_resetZoomAndRotationAnimated(JNIEnv* jenv, jobject obj, bool isPortraitMode);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_setAllowIdleAnimation(JNIEnv* jenv, jobject obj, bool allow);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_unhoverNode(JNIEnv* jenv, jobject obj);
//mapcontroller
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_rotateRadiansXY(JNIEnv* jenv, jobject obj, float radX, float radY);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_translateYAnimated(JNIEnv* jenv, jobject obj, float translateY, float seconds);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_startMomentumPanWithVelocity(JNIEnv* jenv, jobject obj, float vX, float vY);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_handleTouchDownAtPoint(JNIEnv* jenv, jobject obj, float x, float y);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_zoomByScale(JNIEnv* jenv, jobject obj, float scale);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_startMomentumZoomWithVelocity(JNIEnv* jenv, jobject obj, float velocity);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_rotateRadiansZ(JNIEnv* jenv, jobject obj, float radians);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_startMomentumRotationWithVelocity(JNIEnv* jenv, jobject obj, float velocity);
JNIEXPORT bool JNICALL Java_com_peer1_internetmap_MapControllerWrapper_selectHoveredNode(JNIEnv* jenv, jobject obj);
JNIEXPORT jobject JNICALL Java_com_peer1_internetmap_MapControllerWrapper_nodeAtIndex(JNIEnv* jenv, jobject obj, int index);
JNIEXPORT int JNICALL Java_com_peer1_internetmap_MapControllerWrapper_targetNodeIndex(JNIEnv* jenv, jobject obj);
JNIEXPORT jobject JNICALL Java_com_peer1_internetmap_MapControllerWrapper_nodeByAsn(JNIEnv* jenv, jobject obj, jstring asn);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_updateTargetForIndex(JNIEnv* jenv, jobject obj, int index);
//get every node efficiently
JNIEXPORT jobjectArray JNICALL Java_com_peer1_internetmap_MapControllerWrapper_allNodes(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_setTimelinePoint(JNIEnv* jenv, jobject obj, jstring year);
JNIEXPORT jobjectArray JNICALL Java_com_peer1_internetmap_MapControllerWrapper_visualizationNames(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_setVisualization(JNIEnv* jenv, jobject obj, int index);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_deselectCurrentNode(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_resetZoomAndRotationAnimated(JNIEnv* jenv, jobject obj, bool isPortraitMode);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_setAllowIdleAnimation(JNIEnv* jenv, jobject obj, bool allow);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_unhoverNode(JNIEnv* jenv, jobject obj);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_clearHighlightLines(JNIEnv* jenv, jobject obj);

// Traceroute
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_sendPacket(JNIEnv* jenv, jobject obj);
JNIEXPORT jobject JNICALL Java_com_peer1_internetmap_MapControllerWrapper_probeDestinationAddressWithTTL(JNIEnv* jenv, jobject obj, jstring destinationAddr, int ttl);
JNIEXPORT void JNICALL Java_com_peer1_internetmap_MapControllerWrapper_highlightRoute(JNIEnv* jenv, jobject obj, jobjectArray nodeArray, int length);

//nodewrapper
JNIEXPORT jstring JNICALL Java_com_peer1_internetmap_NodeWrapper_nativeFriendlyDescription(JNIEnv* jenv, jobject obj, int index);

//nodewrapper
JNIEXPORT jstring JNICALL Java_com_peer1_internetmap_NodeWrapper_nativeFriendlyDescription(JNIEnv* jenv, jobject obj, int index);
};

#endif // JNIAPI_H
Loading