Skip to content

Conversation

aanorbel
Copy link
Member

@aanorbel aanorbel commented May 24, 2025

Closes #660

Check proper embedding of lib with conveyor

@aanorbel aanorbel requested a review from sdsantos May 26, 2025 11:12
Copy link
Contributor

@sdsantos sdsantos left a comment

Choose a reason for hiding this comment

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

Just missing making the library during the build step.

@aanorbel aanorbel changed the title feat: implement macOS network type detection using JNI feat: implement network type detection using JNI May 27, 2025
@aanorbel aanorbel requested review from hellais and sdsantos May 28, 2025 08:02
System.loadLibrary("networktypefinder")
libraryLoaded = true
} catch (e: UnsatisfiedLinkError) {
Logger.d("Failed to load native library: ${e.message}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be a warning log and not debug log.

"unknown"
}
} catch (e: Throwable) {
Logger.d("Error in native method call: ${e.message}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be a warning log and not debug log.

extern "C" {
#endif

JNIEXPORT jstring JNICALL Java_org_ooni_engine_MacOsNetworkTypeFinder_getNetworkType(JNIEnv *env, jobject obj);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not just MacOs right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

Comment on lines 89 to 91
#endif

#if defined(__APPLE__)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why close the #if defined(__APPLE__) to then open it again straight after?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me fix that.

conveyor.conf Outdated
}

app.inputs += {
from = "composeApp/src/desktopMain/build/libnetworktypefinder.dylib"
Copy link
Contributor

Choose a reason for hiding this comment

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

Only the macOs .dylib?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now.

} else if (nw_path_uses_interface_type(currentPath, nw_interface_type_wired)) {
result = @"wired_ethernet";
} else {
result = @"";
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should be unknown too?

}

// Helper to check if interface is up and has an IP address
static int iface_is_up_and_has_ip(const char *iface) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not return bool?

int n = sscanf(line, "%63s %lx %lx %X %u %u %u %x %u %u %u", iface, &dest, &gw, &flags, &refcnt, &use, &metric, &mask, &mtu, &win, &irtt);
if (n >= 11 && dest == 0) { // default route
if (is_vpn_iface(iface) && iface_is_up_and_has_ip(iface)) {
strcpy(vpn_iface, iface);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why copy it, if we don't need it? Maybe just have a is_vpn bool flag?
Or match the code below and fclose and return straight away?

@aanorbel aanorbel requested a review from sdsantos May 28, 2025 15:08
Copy link
Contributor

@sdsantos sdsantos left a comment

Choose a reason for hiding this comment

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

You'll commit the libraries to the repository once the workflow finishes right?

@aanorbel aanorbel merged commit c9aac06 into main May 28, 2025
11 checks passed
@aanorbel aanorbel deleted the issues/660 branch May 28, 2025 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

desktop: implement NetworkTypeFinder using native APIs

2 participants