Skip to content

Add FFI descriptors (WIP) - #683

Merged
jrconlin merged 1 commit into
masterfrom
push-ffi
Mar 6, 2019
Merged

Add FFI descriptors (WIP)#683
jrconlin merged 1 commit into
masterfrom
push-ffi

Conversation

@jrconlin

Copy link
Copy Markdown
Contributor

No description provided.

@thomccthomcc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just happened across this, and will note some issues I see here that will save you time or are subtle.

Haven't looked at the part where you actually call things from kotlin, i suspect a lot of this is based on how we were doing things on the kotlin side before we switched to using handles for almost everything.

Comment threadcomponents/push/ffi/src/lib.rs Outdated
Comment threadcomponents/push/android/src/main/java/org/mozilla/push/LibPushFFI.kt Outdated
Comment threadcomponents/push/android/src/main/java/org/mozilla/push/LibPushFFI.kt Outdated
Comment threadcomponents/push/android/src/main/java/org/mozilla/push/LibPushFFI.kt Outdated
Comment threadcomponents/push/android/src/main/java/org/mozilla/push/LibPushFFI.kt Outdated
Comment threadcomponents/push/ffi/src/lib.rs Outdated

@jonalmeidajonalmeida left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I realise this is still a WIP, but also consider my comments more as questions from a limited understanding on the internals of push. 😸

Comment threadcomponents/push/android/src/main/java/org/mozilla/push/PushConnection.kt Outdated
sender_id: String,
server_host: String?="push.service.mozilla.org",
socket_protocol: String?="https",
bridge_type:String?="fcm",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For the bridge_type, what are the valid types? Maybe it's easier with some typed class?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding a typed class for this, but I'm definitely a Kotlin noob. I'll see if there's anything like an enumeration that could be used.

Comment threadcomponents/push/android/src/main/java/org/mozilla/push/PushConnection.kt Outdated
socket_protocol: String?="https",
bridge_type:String?="fcm",
encryption_key: String? = null) : PushAPI, AutoCloseable {
private var conn: RawPushConnection?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

From my limited understanding, I believe this is a long-lived socket connection. If so, is there an automatic retry?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It's not quite a long lived connection, at least not on mobile.

Mobile will be using whatever the native messaging service offers. There are some calls that need to be made to the server, and those will be handled by the push connection. We're also going to wrap these inside of a "PushManager" which will handle more things like decryption and managing the individual connections.

As far as you should be concerned, there should be a fairly small set of functions that you'll need to call. You will have to keep some state, though, for things like which ChannelID goes to what callback, but ideally, we'll try to keep as much of that out of your hair as possible.

open class UrlParseFailed(msg: String): PushException(msg)
open class InvalidPlaceInfo(msg: String): PushException(msg)
open class PushConnectionBusy(msg: String): PushException(msg)
* @return Map of ChannelID: Endpoint, be sure to notify apps registered to given

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Would it be expected that the android component calls this check before performing any action first?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Not necessarily. This check can be a bit expensive, since it fetches content from the server and iterates through known connections. It's more a general "sanity check" on the known data state. Calling it once a day should be sufficient.

In the past we've had a few occasions where a client has gotten out of sync with the server. This has resulted in the subscription provider never knowing that a given subscription is no longer valid and sending effectively useless data to the Push Service. This function provides a way to rectify that situation in the future.

@jrconlin
jrconlinforce-pushed the push-ffi branch 2 times, most recently from 1f4a193 to 9c188aaCompareFebruary 26, 2019 00:50

@thomccthomcc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A lot of the FFI code is busted, due to using handles on the Rust side, but a PointerType subclass on the Kotlin side.

I suspect you can leverage ffi_support for making a bunch of the ffi rust code simpler too.

Comment threadcomponents/push/android/src/main/java/org/mozilla/push/LibPushFFI.kt Outdated
Comment threadcomponents/push/android/src/main/java/org/mozilla/push/PushManager.kt Outdated
Comment threadcomponents/push/android/src/main/java/org/mozilla/push/RustError.kt Outdated
Comment threadcomponents/push/error/src/lib.rs
Comment threadcomponents/push/ffi/src/lib.rs
Comment threadcomponents/push/ffi/src/lib.rs
Comment threadcomponents/push/ffi/src/lib.rs
Comment threadcomponents/push/storage/src/db.rs Outdated
Comment threadcomponents/push/storage/src/db.rs Outdated
Comment threadcomponents/push/ffi/src/lib.rs Outdated
Comment threadcomponents/push/ffi/src/lib.rs Outdated
Comment threadcomponents/push/ffi/src/lib.rs Outdated
Comment threadcomponents/push/ffi/src/lib.rs Outdated
Comment threadsettings.gradle
Comment threadcomponents/push/android/build.gradle
Comment threadcomponents/push/subscriber/src/lib.rs Outdated

@thomccthomcc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unsure about the package naming. I thought the only one that wasn't a domain name was the actual namespace in the code. @ncalexan: Ping?

You also need to add yourself to the megazords.

  1. add to the cargo.toml: (for example https://github.com/mozilla/application-services/blob/master/megazords/reference-browser/Cargo.toml)
  2. add to the lib.rs (for example https://github.com/mozilla/application-services/blob/master/megazords/reference-browser/src/lib.rs#L8)
  3. Add to the megazord definition list https://github.com/mozilla/application-services/blob/master/gradle-plugin/src/main/kotlin/mozilla/appservices/AppServicesExtension.kt#L38
  4. bump https://github.com/mozilla/application-services/blob/master/gradle-plugin/build.gradle#L3 (and after a release goes out with these changes, we need to talk to @ncalexan to bump the plugin version)

Or those steps can be done in another PR.

Comment threadautomation/taskcluster/decision_task.py Outdated
Comment threadcomponents/push/Cargo.toml Outdated
Comment threadcomponents/push/android/build.gradle Outdated
Comment threadcomponents/push/ffi/src/lib.rs
Comment threadcomponents/push/android/build.gradle Outdated
Comment threadcomponents/push/android/src/main/AndroidManifest.xml Outdated
@pjenvey

Copy link
Copy Markdown
Contributor

I still think this should be done in the same way the other FFIs do it but it's not a huge deal.

thanks Thom, we'll revisit this one after merging this

@jrconlin

Copy link
Copy Markdown
ContributorAuthor

doing the auto-squash might be a bit problematic due to age and intervening commits.

If preferred, I'm fine doing a manual squash to reduce the total number of commits.

@thomccthomcc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, but you need to update megazords/fenix/android/src/main/java/mozilla/appservices/FenixMegazord.java, megazords/fenix/src/lib.rs, I think

This patch adds:
* Kotlin FFI integration with unit tests
* simplifies decryption to accept raw header values
* adds new storage system
Closes#693, #544, #543, #542
@jrconlin
jrconlin merged commit 2685d00 into masterMar 6, 2019
@jrconlin
jrconlin deleted the push-ffi branch March 7, 2019 00:11
@ncalexan

Copy link
Copy Markdown
Member

Unsure about the package naming. I thought the only one that wasn't a domain name was the actual namespace in the code. @ncalexan: Ping?

You also need to add yourself to the megazords.

1. add to the cargo.toml: (for example https://github.com/mozilla/application-services/blob/master/megazords/reference-browser/Cargo.toml)
2. add to the lib.rs (for example https://github.com/mozilla/application-services/blob/master/megazords/reference-browser/src/lib.rs#L8)
3. Add to the megazord definition list https://github.com/mozilla/application-services/blob/master/gradle-plugin/src/main/kotlin/mozilla/appservices/AppServicesExtension.kt#L38
4. bump https://github.com/mozilla/application-services/blob/master/gradle-plugin/build.gradle#L3 (and after a release goes out with these changes, we need to talk to @ncalexan to bump the plugin version)

Or those steps can be done in another PR.

Sorry, this got lost in my github firehose. I published an updated version of the plugin for Grisha's use at the end of last week.

@rfk

rfk commented Mar 20, 2019

Copy link
Copy Markdown
Contributor

You also need to add yourself to the megazords.

Do we have a doc where JR should have been able to find this step (and its sub-steps)?

@thomcc

Copy link
Copy Markdown
Contributor

We don't (it's on my TODO) but I did describe the rough steps #683 (review)

Sign up for freeto 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.

8 participants

@jrconlin@pjenvey@ncalexan@rfk@thomcc@jonalmeida@mhammond@jdragojevic