Merge branch 'JNI-158' into Release_2.1

master
heck 2 years ago
commit 661abc4205

@ -260,7 +260,6 @@ public class MainActivity extends AppCompatActivity {
@BindView(R.id.bRunTypes) Button runTypes;
@BindView(R.id.bRunAliceBob) Button runIntegration;
@BindView(R.id.bRunServerLookup) Button runLookup;
@BindView(R.id.bRunGenKey) Button runGenKey;
@BindView(R.id.encrypt_and_decrypt) Button runEncryptAndDecrypt;
@BindView(R.id.encrypt_and_decrypt_without_key) Button runEncryptAndDecryptWithoutKey;
@ -287,11 +286,6 @@ public class MainActivity extends AppCompatActivity {
runIntegration.setText(TESTING);
new RunTestTask().execute(6);
}
@OnClick(R.id.bRunServerLookup)
public void runLookup() {
runLookup.setText(TESTING);
new RunTestTask().execute(2);
}
@OnClick(R.id.bRunGenKey)
public void runGenKey() {
runGenKey.setText(TESTING);
@ -390,10 +384,6 @@ public class MainActivity extends AppCompatActivity {
testPEpTypes();
}
private void runTestKeyserverLookup() throws pEpException, InterruptedException, IOException {
testKeyserverLookup();
}
private void runTestKeyGen() throws pEpException, InterruptedException, IOException {
testKeyGen();
}
@ -1494,46 +1484,6 @@ public class MainActivity extends AppCompatActivity {
msg.setAttachments(attachments);
}
/*
tests its possible to find the fingerprint on server
*/
public void testKeyserverLookup() throws pEpException, IOException, AssertionError, InterruptedException {
log("TEST: ", "Test keyserver lookup loaded");
Engine e;
e = new Engine();
long lastTime = System.currentTimeMillis();
e.startKeyserverLookup();
log("engine.startLookup", String.valueOf(System.currentTimeMillis() - lastTime));
Identity vb = new Identity();
vb.username = "pEpDontAssert";
vb.address = "vb@ulm.ccc.de";
vb.user_id = "SsI6H9";
updateIdentityOnEngine(e, vb);
int count = 0;
while (count++ < 5000) {
Thread.sleep(1);
}
String fpr = e.updateIdentity(vb).fpr;
log("PEPTEST", "keyserver test fpr");
log("PEPTEST", fpr != null ? fpr : "NULL");
if (fpr == null) throw new AssertionError();
lastTime = System.currentTimeMillis();
e.stopKeyserverLookup();
log("engine.stopLookup", String.valueOf(System.currentTimeMillis() - lastTime));
lastTime = System.currentTimeMillis();
e.close();
log("engine.close", String.valueOf(System.currentTimeMillis() - lastTime));
log("TEST: ", "Test keyserver lookup finished");
}
/*
tests I can get my own fingerprint
*/
@ -1927,18 +1877,15 @@ public class MainActivity extends AppCompatActivity {
runTestPEpTypes();
return 1;
case 2:
runTestKeyserverLookup();
return 2;
case 3:
runEncryptAndDecryptTest();
return 3;
case 4:
case 3:
runEncryptAndDecryptWithoutKeyTest();
return 4;
case 5:
case 4:
runColorRatingsTest();
return 5;
case 6:
case 5:
runIntegrationTest();
return 6;
case 16:

@ -57,27 +57,6 @@
android:text="Run" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Server Lookup"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/bRunServerLookup"
style="?android:attr/buttonStyleSmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Run" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

@ -1,5 +1,4 @@
#include "foundation_pEp_jniadapter_AbstractEngine.h"
#include <unistd.h>
#include <pEp/keymanagement.h>
#include <pEp/message_api.h>
#include <pEp/sync_api.h>
@ -326,119 +325,6 @@ int examine_identity(pEp_identity *ident,
return 0;
}
pEp_identity *retrieve_next_identity(void *arg)
{
pEpLog("called");
locked_queue < pEp_identity * > *queue = static_cast<locked_queue < pEp_identity * > * > (arg);
while (!queue->size()) {
usleep(100000);
}
pEp_identity *ident = queue->front();
queue->pop_front();
return ident;
}
static void *keyserver_thread_routine(void *arg)
{
PEP_STATUS status = do_keymanagement(retrieve_next_identity, arg);
locked_queue < pEp_identity * > *queue = static_cast<locked_queue < pEp_identity * > * > (arg);
while (queue->size()) {
pEp_identity *ident = queue->front();
queue->pop_front();
free_identity(ident);
}
delete queue;
return reinterpret_cast<void *>(status);
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startKeyserverLookup(JNIEnv *env,
jobject obj)
{
std::mutex *mutex_local = nullptr;
{
std::lock_guard<std::mutex> l(global_mutex);
pEpLog("called with lock_guard");
mutex_local = get_engine_java_object_mutex(env, obj);
}
std::lock_guard<std::mutex> l(*mutex_local);
pthread_t *thread = nullptr;
locked_queue< pEp_identity * > *queue = nullptr;
jfieldID thread_handle;
jfieldID queue_handle;
try {
thread_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverThread", "J");
queue_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverQueue", "J");
}
catch (std::exception& ex) {
assert(0);
return;
}
thread = reinterpret_cast<pthread_t*>(env->GetLongField(obj, thread_handle));
if (thread)
return;
thread = static_cast<pthread_t*>(calloc(1, sizeof(pthread_t)));
assert(thread);
env->SetLongField(obj, thread_handle, reinterpret_cast<jlong>(thread));
queue = new locked_queue< pEp_identity * >();
env->SetLongField(obj, queue_handle, reinterpret_cast<jlong>(queue));
register_examine_function(Adapter::session(), examine_identity,static_cast<void*>(queue));
pthread_create(thread, nullptr, keyserver_thread_routine, static_cast<void*>(queue));
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1stopKeyserverLookup(JNIEnv *env,
jobject obj)
{
std::mutex *mutex_local = nullptr;
{
std::lock_guard<std::mutex> l(global_mutex);
pEpLog("called with lock_guard");
mutex_local = get_engine_java_object_mutex(env, obj);
}
std::lock_guard<std::mutex> l(*mutex_local);
pthread_t *thread = nullptr;
locked_queue< pEp_identity * > *queue = nullptr;
jfieldID thread_handle;
jfieldID queue_handle;
try {
thread_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverThread", "J");
queue_handle = getFieldID(env, "foundation/pEp/jniadapter/Engine", "keyserverQueue", "J");
}
catch (std::exception& ex) {
assert(0);
return;
}
thread = reinterpret_cast<pthread_t*>(env->GetLongField(obj, thread_handle));
if (!thread)
return;
queue = reinterpret_cast<locked_queue<pEp_identity*>*>(env->GetLongField(obj, queue_handle));
env->SetLongField(obj, queue_handle, 0);
env->SetLongField(obj, thread_handle, 0);
register_examine_function(Adapter::session(), nullptr, nullptr);
queue->push_front(nullptr);
pthread_join(*thread, nullptr);
free(thread);
}
JNIEXPORT void JNICALL Java_foundation_pEp_jniadapter_AbstractEngine__1startSync(JNIEnv *env,
jobject obj)
{

@ -1,17 +1,7 @@
#include <cassert>
#include "jniutils.hh"
#include <pEp/pEpLog.hh>
#ifndef __LP64__
#include <time64.h>
#define time_t time64_t
#define timegm timegm64
#define gmtime_r gmtime64_r
#else
#include <string.h>
#endif
#include <cassert>
#include <cstring>
namespace pEp {
namespace JNIAdapter {

@ -23,9 +23,6 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AbstractEn
private native void init();
private native void release();
private long keyserverThread;
private long keyserverQueue;
public AbstractEngine() throws pEpException {
synchronized (AbstractEngine.class) {
init();
@ -67,20 +64,6 @@ abstract class AbstractEngine extends UniquelyIdentifiable implements AbstractEn
private native String _getProtocolVersion();
public void startKeyserverLookup() {
_startKeyserverLookup();
}
private native void _startKeyserverLookup();
public void stopKeyserverLookup() {
_startKeyserverLookup();
}
private native void _stopKeyserverLookup();
public void startSync() {
_startSync();
}

@ -8,10 +8,6 @@ public interface AbstractEngineInterface extends AutoCloseable {
public String getProtocolVersion();
public void startKeyserverLookup();
public void stopKeyserverLookup();
public void startSync();
public void stopSync();

@ -276,10 +276,6 @@ class TestMain {
ctx.engine.getProtocolVersion();
});
new TestUnit<CTXBase>("Engine.startKeyserverLookup", new CTXBase(), ctx -> {
ctx.engine.startKeyserverLookup();
});
new TestUnit<CTXBase>("Engine.startSync", new CTXBase(), ctx -> {
ctx.engine.startSync();
});

Loading…
Cancel
Save