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

Feature/blinded version #1583

Merged
merged 9 commits into from
Jul 30, 2024
Merged

Conversation

ThomasSession
Copy link
Collaborator

@ThomasSession ThomasSession commented Jul 30, 2024

SES-2483 - Updated Version API

We need the app to periodically (every 4hours at most) check the latest app version,
which is available on the File server API.

Two new endpoints were added to libsession to help with the required headers for the new version endpoint.
JNI bridging added in.

private var job: Job? = null

init {
runnable = Runnable {

Choose a reason for hiding this comment

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

inline


object BlindKeyAPI {
init {
System.loadLibrary("session_util")

Choose a reason for hiding this comment

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

would perhaps be ideal to just have one by lazy somewhere that we reference instead of loading this thing for the 8th time.

IDK if it's optimised away sometimes/always/never, but at least when we loaded a lib way to many times, it crashed on some devices.

?: throw (Error.NoEd25519KeyPair)

val blindedKeys = BlindKeyAPI.blindVersionKeyPair(secretKey)
val timestamp = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) // The current timestamp in seconds

Choose a reason for hiding this comment

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

so... you could perhaps more clearly:

val timestampSeconds = System.currentTimeMillis().milliseconds.inWholeSeconds

as it's useful to put units in the variable name if it is not contained in the type.

alternatively

val timestamp = System.currentTimeMillis().milliseconds
val signature = BlindKeyAPI.blindVersionSign(secretKey, timestamp.inWholeSeconds)
...
"X-FS-Timestamp" to timestamp.inWholeSeconds.toString(),

Comment on lines 154 to 159
val json = JsonUtil.fromJson(result, Map::class.java)
val statusCode = json.getOrDefault("status_code", 0) as Int
val version = json.getOrDefault("result", "") as String
val updated = json.getOrDefault("updated", 0.0) as Double

return VersionData(statusCode, version, updated)

Choose a reason for hiding this comment

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

Seeing as there's all of these named vals that are simple enough to inline, they may as well be named params, and you get a little bit more safety that they're in the right order etc.

Suggested change
val json = JsonUtil.fromJson(result, Map::class.java)
val statusCode = json.getOrDefault("status_code", 0) as Int
val version = json.getOrDefault("result", "") as String
val updated = json.getOrDefault("updated", 0.0) as Double
return VersionData(statusCode, version, updated)
return JsonUtil.fromJson(result, Map::class.java).let {
VersionData(
statusCode = it["status_code"] as? Int ?: 0
version = it["result"] as? String ?: ""
updated = it["updated"] as? Double ?: 0.0
)
}

@@ -142,6 +143,7 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
private HandlerThread conversationListHandlerThread;
private Handler conversationListHandler;
private PersistentLogger persistentLogger;
private VersionUtil versionUtil;

Choose a reason for hiding this comment

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

could probably inject without much trouble

@ThomasSession ThomasSession merged commit fc4bf6f into release/1.19.0 Jul 30, 2024
2 checks passed
@simophin simophin deleted the feature/blinded-version branch August 14, 2024 00:53
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.

4 participants