feat: start on closed group polling for new signatures

This commit is contained in:
0x330a
2023-09-13 10:12:35 +10:00
parent 6067916da9
commit df29ed8f16
17 changed files with 151 additions and 58 deletions

View File

@@ -13,7 +13,7 @@ inline session::config::Contacts *ptrToContacts(JNIEnv *env, jobject obj) {
inline jobject serialize_contact(JNIEnv *env, session::config::contact_info info) {
jclass contactClass = env->FindClass("network/loki/messenger/libsession_util/util/Contact");
jmethodID constructor = env->GetMethodID(contactClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;ILnetwork/loki/messenger/libsession_util/util/ExpiryMode;)V");
jmethodID constructor = env->GetMethodID(contactClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZZZLnetwork/loki/messenger/libsession_util/util/UserPic;JLnetwork/loki/messenger/libsession_util/util/ExpiryMode;)V");
jstring id = env->NewStringUTF(info.session_id.data());
jstring name = env->NewStringUTF(info.name.data());
jstring nickname = env->NewStringUTF(info.nickname.data());
@@ -24,7 +24,7 @@ inline jobject serialize_contact(JNIEnv *env, session::config::contact_info info
auto created = info.created;
jobject profilePic = util::serialize_user_pic(env, info.profile_picture);
jobject returnObj = env->NewObject(contactClass, constructor, id, name, nickname, approved,
approvedMe, blocked, profilePic, info.priority,
approvedMe, blocked, profilePic, (jlong)info.priority,
util::serialize_expiry(env, info.exp_mode, info.exp_timer));
return returnObj;
}
@@ -42,14 +42,14 @@ deserialize_contact(JNIEnv *env, jobject info, session::config::Contacts *conf)
getBlocked = env->GetFieldID(contactClass, "blocked", "Z");
getUserPic = env->GetFieldID(contactClass, "profilePicture",
"Lnetwork/loki/messenger/libsession_util/util/UserPic;");
getPriority = env->GetFieldID(contactClass, "priority", "I");
getPriority = env->GetFieldID(contactClass, "priority", "J");
getExpiry = env->GetFieldID(contactClass, "expiryMode", "Lnetwork/loki/messenger/libsession_util/util/ExpiryMode;");
jstring name, nickname, session_id;
session_id = static_cast<jstring>(env->GetObjectField(info, getId));
name = static_cast<jstring>(env->GetObjectField(info, getName));
nickname = static_cast<jstring>(env->GetObjectField(info, getNick));
bool approved, approvedMe, blocked, hidden;
int priority = env->GetIntField(info, getPriority);
int priority = env->GetLongField(info, getPriority);
approved = env->GetBooleanField(info, getApproved);
approvedMe = env->GetBooleanField(info, getApprovedMe);
blocked = env->GetBooleanField(info, getBlocked);

View File

@@ -72,20 +72,19 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_groupKeys(JNIEnv *e
extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_loadKey(JNIEnv *env, jobject thiz,
jbyteArray message,
jstring hash,
jbyteArray data,
jbyteArray msg_id,
jlong timestamp_ms,
jobject info_jobject,
jobject members_jobject) {
std::lock_guard lock{util::util_mutex_};
auto keys = ptrToKeys(env, thiz);
auto message_bytes = util::ustring_from_bytes(env, message);
auto hash_bytes = env->GetStringUTFChars(hash, nullptr);
auto data_bytes = util::ustring_from_bytes(env, data);
auto msg_bytes = util::ustring_from_bytes(env, msg_id);
auto info = ptrToInfo(env, info_jobject);
auto members = ptrToMembers(env, members_jobject);
keys->load_key_message(hash_bytes, data_bytes, timestamp_ms, *info, *members);
keys->load_key_message(hash_bytes, message_bytes, timestamp_ms, *info, *members);
env->ReleaseStringUTFChars(hash, hash_bytes);
}
@@ -112,8 +111,8 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_pendingKey(JNIEnv *
extern "C"
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_pendingPush(JNIEnv *env,
jobject thiz) {
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_pendingConfig(JNIEnv *env,
jobject thiz) {
std::lock_guard lock{util::util_mutex_};
auto keys = ptrToKeys(env, thiz);
auto pending = keys->pending_config();
@@ -135,4 +134,20 @@ Java_network_loki_messenger_libsession_1util_GroupKeysConfig_rekey(JNIEnv *env,
auto rekey = keys->rekey(*info, *members);
auto rekey_bytes = util::bytes_from_ustring(env, rekey.data());
return rekey_bytes;
}
}
extern "C"
JNIEXPORT jbyteArray JNICALL
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_keyDump(JNIEnv *env, jobject thiz) {
auto keys = ptrToKeys(env, thiz);
auto dump = keys->dump();
auto byte_array = util::bytes_from_ustring(env, dump);
return byte_array;
}
extern "C"
JNIEXPORT void JNICALL
Java_network_loki_messenger_libsession_1util_GroupKeysConfig_free(JNIEnv *env, jobject thiz) {
auto ptr = ptrToKeys(env, thiz);
delete ptr;
}

View File

@@ -28,7 +28,6 @@ sealed class ConfigBase(protected val /* yucky */ pointer: Long) {
is ConversationVolatileConfig -> Kind.CONVO_INFO_VOLATILE
is UserGroupsConfig -> Kind.GROUPS
is GroupInfoConfig -> Kind.CLOSED_GROUP_INFO
is GroupKeysConfig -> Kind.ENCRYPTION_KEYS
is GroupMembersConfig -> Kind.CLOSED_GROUP_MEMBERS
}
@@ -275,7 +274,7 @@ class GroupMembersConfig(pointer: Long): ConfigBase(pointer), Closeable {
}
}
class GroupKeysConfig(pointer: Long): ConfigBase(pointer), Closeable {
class GroupKeysConfig(private val pointer: Long): Closeable {
companion object {
init {
System.loadLibrary("session_util")
@@ -292,16 +291,16 @@ class GroupKeysConfig(pointer: Long): ConfigBase(pointer), Closeable {
}
external fun groupKeys(): Stack<ByteArray>
external fun keyDump(): ByteArray
external fun loadKey(hash: String,
data: ByteArray,
msgId: ByteArray,
external fun loadKey(message: ByteArray,
hash: String,
timestampMs: Long,
info: GroupInfoConfig,
members: GroupMembersConfig)
external fun needsRekey(): Boolean
external fun pendingKey(): ByteArray?
external fun pendingPush(): ByteArray?
external fun pendingConfig(): ByteArray?
external fun rekey(info: GroupInfoConfig, members: GroupMembersConfig): ByteArray
external fun free()
override fun close() {
free()
}