diff --git a/.gitmodules b/.gitmodules
index 2f69bb7b2..5199bdb4d 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -17,3 +17,6 @@
[submodule "supportlibs/libsam3"]
path = supportlibs/libsam3
url = https://github.com/i2p/libsam3.git
+[submodule "supportlibs/jni.hpp"]
+ path = supportlibs/jni.hpp
+ url = https://github.com/RetroShare/jni.hpp.git
diff --git a/build_scripts/Android/prepare-toolchain-clang.sh b/build_scripts/Android/prepare-toolchain-clang.sh
index 25fefccba..510b04855 100755
--- a/build_scripts/Android/prepare-toolchain-clang.sh
+++ b/build_scripts/Android/prepare-toolchain-clang.sh
@@ -112,6 +112,9 @@ define_default_value MVPTREE_SOURCE_VERSION origin/master
define_default_value REPORT_DIR "$(pwd)/$(basename ${NATIVE_LIBS_TOOLCHAIN_PATH})_build_report/"
+define_default_value RS_SRC_DIR "$(realpath $(dirname $BASH_SOURCE)/../../)"
+
+
cArch=""
eABI=""
cmakeABI=""
@@ -829,6 +832,15 @@ build_phash()
popd
}
+task_register fetch_jni_hpp
+fetch_jni_hpp()
+{
+ local rDir="supportlibs/jni.hpp/"
+
+ [ "$(ls "${RS_SRC_DIR}/${rDir}" | wc -l)" -gt "4" ] ||
+ git -C ${RS_SRC_DIR} submodule update --init ${rDir}
+}
+
task_register build_mvptree
build_mvptree()
{
@@ -862,6 +874,7 @@ build_default_toolchain()
task_run build_xapian || return $?
task_run build_miniupnpc || return $?
task_run build_phash || return $?
+ task_run fetch_jni_hpp || return $?
task_run deduplicate_includes || return $?
task_run get_native_libs_toolchain_path || return $?
}
diff --git a/libretroshare/src/jsonapi/jsonapi.cpp b/libretroshare/src/jsonapi/jsonapi.cpp
index 4b003f225..2f2ded30c 100644
--- a/libretroshare/src/jsonapi/jsonapi.cpp
+++ b/libretroshare/src/jsonapi/jsonapi.cpp
@@ -796,8 +796,9 @@ void JsonApiServer::run()
}
catch(std::exception& e)
{
- RsErr() << __PRETTY_FUNCTION__ << " Failure starting JSON API server: "
- << e.what() << std::endl;
+ /* TODO: find a way to report back programmatically if failed listening
+ * port */
+ RS_ERR("Failure starting JSON API server: ", e.what());
print_stacktrace();
return;
}
diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro
index 36103f856..2bad4682f 100644
--- a/libretroshare/src/libretroshare.pro
+++ b/libretroshare/src/libretroshare.pro
@@ -1101,13 +1101,11 @@ android-* {
DEFINES *= "fseeko64=fseeko"
DEFINES *= "ftello64=ftello"
- ## @See: android_ifaddrs/README.adoc
- !contains(DEFINES, LIBRETROSHARE_ANDROID_IFADDRS_QT) {
- HEADERS += \
- android_ifaddrs/ifaddrs-android.h \
- android_ifaddrs/LocalArray.h \
- android_ifaddrs/ScopedFd.h
- }
+## @See: rs_android/README-ifaddrs-android.adoc
+ HEADERS += \
+ rs_android/ifaddrs-android.h \
+ rs_android/LocalArray.h \
+ rs_android/ScopedFd.h
}
## Static library are very susceptible to order in command line
@@ -1116,6 +1114,13 @@ android-* {
LIBS += $$linkStaticLibs(sLibs)
PRE_TARGETDEPS += $$pretargetStaticLibs(sLibs)
- HEADERS += util/androiddebug.h
+ HEADERS += \
+ rs_android/androidcoutcerrcatcher.hpp \
+ rs_android/retroshareserviceandroid.hpp \
+ rs_android/rsjni.hpp
+
+ SOURCES += rs_android/rsjni.cpp \
+ rs_android/retroshareserviceandroid.cpp \
+ rs_android/errorconditionwrap.cpp
}
diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc
index 83c4d9366..f1d604ea5 100644
--- a/libretroshare/src/pqi/p3peermgr.cc
+++ b/libretroshare/src/pqi/p3peermgr.cc
@@ -1398,11 +1398,11 @@ bool p3PeerMgrIMPL::UpdateOwnAddress( const sockaddr_storage& pLocalAddr,
sockaddr_storage_copy(pExtAddr, extAddr);
sockaddr_storage_ipv6_to_ipv4(extAddr);
-//#ifdef PEER_DEBUG
+#ifdef PEER_DEBUG
std::cerr << "p3PeerMgrIMPL::UpdateOwnAddress("
<< sockaddr_storage_tostring(localAddr) << ", "
<< sockaddr_storage_tostring(extAddr) << ")" << std::endl;
-//#endif
+#endif
if( rsBanList &&
!rsBanList->isAddressAccepted(localAddr,
diff --git a/libretroshare/src/pqi/pqinetwork.cc b/libretroshare/src/pqi/pqinetwork.cc
index b6c52fc27..2b786f488 100644
--- a/libretroshare/src/pqi/pqinetwork.cc
+++ b/libretroshare/src/pqi/pqinetwork.cc
@@ -21,16 +21,6 @@
* along with this program. If not, see . *
* *
*******************************************************************************/
-#ifdef WINDOWS_SYS
-# include "util/rswin.h"
-# include "util/rsmemory.h"
-# include
-#endif // WINDOWS_SYS
-
-/// @See: android_ifaddrs/README.adoc
-#ifdef __ANDROID__
-# include
-#endif // def __ANDROID__
#include
#include
@@ -44,6 +34,28 @@
#include "util/rsnet.h"
#include "util/stacktrace.h"
+#ifdef WINDOWS_SYS
+# include "util/rswin.h"
+# include "util/rsmemory.h"
+# include
+#endif // WINDOWS_SYS
+
+/// @See: android_ifaddrs/README.adoc
+#ifdef __ANDROID__
+# include
+#endif // def __ANDROID__
+
+#ifdef WINDOWS_SYS /* Windows - define errno */
+int errno;
+#else /* Windows - define errno */
+#include
+#endif
+
+#ifdef __HAIKU__
+# include
+# define IFF_RUNNING 0x0001
+#endif
+
static struct RsLog::logInfo pqinetzoneInfo = {RsLog::Default, "pqinet"};
#define pqinetzone &pqinetzoneInfo
@@ -51,21 +63,6 @@ static struct RsLog::logInfo pqinetzoneInfo = {RsLog::Default, "pqinet"};
* #define NET_DEBUG 1
****/
-#ifdef WINDOWS_SYS /* Windows - define errno */
-
-int errno;
-
-#else /* Windows - define errno */
-
-#include
-
-#endif
-
-#ifdef __HAIKU__
- #include
- #define IFF_RUNNING 0x0001
-#endif
-
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS
@@ -271,24 +268,16 @@ int inet_aton(const char *name, struct in_addr *addr)
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
-
+#include "util/cxx17retrocompat.h"
#include
#ifdef WINDOWS_SYS
# include
# include
# pragma comment(lib, "IPHLPAPI.lib")
-#elif defined(__ANDROID__) && __ANDROID_API__ < 24 && \
- defined(LIBRETROSHARE_ANDROID_IFADDRS_QT)
+#elif defined(__ANDROID__) && __ANDROID_API__ < 24
/// @See: android_ifaddrs/README.adoc
-# include
-# include
-# include
-# include
-#elif defined(__ANDROID__) && __ANDROID_API__ < 24 && \
- !defined(LIBRETROSHARE_ANDROID_IFADDRS_QT)
-/// @See: android_ifaddrs/README.adoc
-# include "android_ifaddrs/ifaddrs-android.h"
-#else // not __ANDROID__ nor WINDOWS => Linux and other unixes
+# include "rs_android/ifaddrs-android.h"
+#else // not WINDOWS => Linux and other unixes
# include
# include
#endif // WINDOWS_SYS
@@ -331,17 +320,7 @@ bool getLocalAddresses(std::vector& addrs)
}
}
free(adapter_addresses);
-#elif defined(__ANDROID__) && __ANDROID_API__ < 24 && \
- defined(LIBRETROSHARE_ANDROID_IFADDRS_QT)
-/// @See: android_ifaddrs/README.adoc
- for(auto& qAddr: QNetworkInterface::allAddresses())
- {
- sockaddr_storage tmpAddr;
- sockaddr_storage_clear(tmpAddr);
- if(sockaddr_storage_ipv4_aton(tmpAddr, qAddr.toString().toStdString().c_str()))
- addrs.push_back(tmpAddr);
- }
-#else // not WINDOWS_SYS not ANDROID => Linux and other unixes
+#else // not WINDOWS_SYS => Linux and other unixes
struct ifaddrs *ifsaddrs, *ifa;
if(getifaddrs(&ifsaddrs) != 0)
{
@@ -355,18 +334,19 @@ bool getLocalAddresses(std::vector& addrs)
{
sockaddr_storage tmp;
sockaddr_storage_clear(tmp);
- if (sockaddr_storage_copyip(tmp, *reinterpret_cast(ifa->ifa_addr)))
+ if(sockaddr_storage_copyip(
+ tmp,
+ *reinterpret_cast(ifa->ifa_addr) ))
addrs.push_back(tmp);
}
freeifaddrs(ifsaddrs);
#endif // WINDOWS_SYS
#ifdef NET_DEBUG
- std::list::iterator it;
- std::cout << "getLocalAddresses(...) returning: <" ;
- for(it = addrs.begin(); it != addrs.end(); ++it)
- std::cout << sockaddr_storage_iptostring(*it) << ", ";
- std::cout << ">" << std::endl;
+ auto&& dbg = RS_DBG("returning: [");
+ for(auto& addr: std::as_const(addrs))
+ dbg << sockaddr_storage_iptostring(addr) << ", ";
+ dbg << "]" << std::endl;
#endif
return !addrs.empty();
diff --git a/libretroshare/src/pqi/pqinetwork.h b/libretroshare/src/pqi/pqinetwork.h
index e4238ee5e..9519bf197 100644
--- a/libretroshare/src/pqi/pqinetwork.h
+++ b/libretroshare/src/pqi/pqinetwork.h
@@ -4,7 +4,8 @@
* libretroshare: retroshare core library *
* *
* Copyright (C) 2004-2006 Robert Fernie *
- * Copyright (C) 2015-2018 Gioacchino Mazzurco *
+ * Copyright (C) 2015-2021 Gioacchino Mazzurco *
+ * Copyright (C) 2021 Asociación Civil Altermundi *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@@ -20,8 +21,7 @@
* along with this program. If not, see . *
* *
*******************************************************************************/
-#ifndef MRK_PQI_NETWORKING_HEADER
-#define MRK_PQI_NETWORKING_HEADER
+#pragma once
#include
@@ -86,9 +86,13 @@ extern int errno; /* Define extern errno, to duplicate unix behaviour */
#include
#include
+#include "util/rsdeprecate.h"
+
// Same def - different functions...
+RS_DEPRECATED_FOR("use std::error_condition instead")
void showSocketError(std::string &out);
+RS_DEPRECATED_FOR("use std::error_condition instead")
std::string socket_errorType(int err);
bool getLocalAddresses(std::vector & addrs);
@@ -103,10 +107,6 @@ int unix_getsockopt_error(int sockfd, int *err);
#ifdef WINDOWS_SYS // WINDOWS
/******************* WINDOWS SPECIFIC PART ******************/
+RS_DEPRECATED_FOR("use std::error_condition instead")
int WinToUnixError(int error);
#endif
-
-
-
-#endif
-
diff --git a/libretroshare/src/android_ifaddrs/LocalArray.h b/libretroshare/src/rs_android/LocalArray.h
similarity index 100%
rename from libretroshare/src/android_ifaddrs/LocalArray.h
rename to libretroshare/src/rs_android/LocalArray.h
diff --git a/libretroshare/src/android_ifaddrs/README.adoc b/libretroshare/src/rs_android/README-ifaddrs-android.adoc
similarity index 75%
rename from libretroshare/src/android_ifaddrs/README.adoc
rename to libretroshare/src/rs_android/README-ifaddrs-android.adoc
index ba0355df7..0c0065f92 100644
--- a/libretroshare/src/android_ifaddrs/README.adoc
+++ b/libretroshare/src/rs_android/README-ifaddrs-android.adoc
@@ -24,9 +24,8 @@ plus depending on Qt networking module just for this is frustrating.
Update: the warning flood seems have been fixed in later Qt versions
https://bugreports.qt.io/browse/QTBUG-86394
-This solution is the first working we implemented in our code it is disabled by
-default but can be enabled passing `DEFINES+=LIBRETROSHARE_ANDROID_IFADDRS_QT`
-when running `qmake` command.
+This solution was the first working we implemented in our code it has been
+removed to avoid dependency on Qt, as lighter alternatives are possible.
== Code copied from Android Gingerbread release
@@ -43,3 +42,8 @@ https://android.googlesource.com/platform/libcore/+/refs/heads/gingerbread-relea
is particularly easy to include in our code base and compile.
This solution seems the best fitting and doesn't introduce dependency on Qt.
+Newer Android releases (expecially 11) have introduced multiple restrictions
+on network information access so we suggest you to prepare different APK for
+different API level in order to use the `getifaddrs` provided by Android NDK
+which deal gracefully with those restrictions as soon as available.
+
diff --git a/libretroshare/src/android_ifaddrs/ScopedFd.h b/libretroshare/src/rs_android/ScopedFd.h
similarity index 100%
rename from libretroshare/src/android_ifaddrs/ScopedFd.h
rename to libretroshare/src/rs_android/ScopedFd.h
diff --git a/libretroshare/src/util/androiddebug.h b/libretroshare/src/rs_android/androidcoutcerrcatcher.hpp
similarity index 83%
rename from libretroshare/src/util/androiddebug.h
rename to libretroshare/src/rs_android/androidcoutcerrcatcher.hpp
index c358be553..43cf16dd7 100644
--- a/libretroshare/src/util/androiddebug.h
+++ b/libretroshare/src/rs_android/androidcoutcerrcatcher.hpp
@@ -1,9 +1,9 @@
/*******************************************************************************
- * libretroshare/src/util: androiddebug.h *
* *
* libretroshare: retroshare core library *
* *
- * Copyright (C) 2016 Gioacchino Mazzurco *
+ * Copyright (C) 2016-2021 Gioacchino Mazzurco *
+ * Copyright (C) 2021 Asociación Civil Altermundi *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@@ -36,10 +36,10 @@
* class at the beginning of the main of your program to get them (stdout and
* stderr) on logcat output.
*/
-class AndroidStdIOCatcher
+class AndroidCoutCerrCatcher
{
public:
- AndroidStdIOCatcher(const std::string& dTag = "RetroShare",
+ AndroidCoutCerrCatcher(const std::string& dTag = "RetroShare",
android_LogPriority stdout_pri = ANDROID_LOG_INFO,
android_LogPriority stderr_pri = ANDROID_LOG_ERROR) :
tag(dTag), cout_pri(stdout_pri), cerr_pri(stderr_pri), should_stop(false)
@@ -63,10 +63,10 @@ public:
pthread_detach(thr);
}
- ~AndroidStdIOCatcher()
+ ~AndroidCoutCerrCatcher()
{
should_stop = true;
- pthread_join(thr, NULL);
+ pthread_join(thr, nullptr);
}
private:
@@ -79,11 +79,13 @@ private:
pthread_t thr;
std::atomic should_stop;
- static void *thread_func(void* instance)
+ static void* thread_func(void* instance)
{
- __android_log_write(ANDROID_LOG_INFO, "RetroShare", "Android debugging start");
+ __android_log_write(
+ ANDROID_LOG_INFO, "RetroShare",
+ "Android standard I/O catcher start" );
- AndroidStdIOCatcher &i = *static_cast(instance);
+ AndroidCoutCerrCatcher &i = *static_cast(instance);
std::string out_buf;
std::string err_buf;
@@ -113,9 +115,11 @@ private:
usleep(10000);
}
- __android_log_write(ANDROID_LOG_INFO, "RetroShare", "Android debugging stop");
+ __android_log_write(
+ ANDROID_LOG_INFO, "RetroShare",
+ "Android standard I/O catcher stop" );
- return NULL;
+ return nullptr;
}
};
diff --git a/libretroshare/src/rs_android/errorconditionwrap.cpp b/libretroshare/src/rs_android/errorconditionwrap.cpp
new file mode 100644
index 000000000..e27495878
--- /dev/null
+++ b/libretroshare/src/rs_android/errorconditionwrap.cpp
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * *
+ * libretroshare: retroshare core library *
+ * *
+ * Copyright (C) 2021 Gioacchino Mazzurco *
+ * Copyright (C) 2021 Asociación Civil Altermundi *
+ * *
+ * This program is free software: you can redistribute it and/or modify *
+ * it under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation, either version 3 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public License *
+ * along with this program. If not, see . *
+ * *
+ *******************************************************************************/
+
+#include "rs_android/rsjni.hpp"
+
+namespace jni
+{
+Local