-
Notifications
You must be signed in to change notification settings - Fork 8
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
Federation Data Exchange for FE2 #1943
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8d576ec
Added Result and TokensExchange messages, adapted handler
quadcopterman e80f557
Added Result and TokensExchange messages, adapted handler
quadcopterman 1677c00
FederationResult now works as expected
quadcopterman bbc7b5e
Added the function to send TokensExchange data
quadcopterman 71e63ad
Removed bad condition
quadcopterman 05c3de9
Added federation support for multiple LAOs in the same app
quadcopterman 62f22bb
Fix for a few bugs
quadcopterman 05c5dcb
Adapted chirps for federation, first test
quadcopterman 7bf43cb
Adapted chirps for federation, update
quadcopterman 65dc966
Corrected tests
quadcopterman ac25784
Corrected ChirpListFragmentTest
quadcopterman 4a32b59
Cleaned handler and added tests
quadcopterman 4b52dbf
Added one test
quadcopterman 07913e0
Corrected one condition
quadcopterman 147f0be
Improved result, handler and new tests
quadcopterman 20998ca
Added message validation
quadcopterman 9550e1e
More message validation, added disposables in the repository
quadcopterman 5008da9
Corrected sonarcloud issue
quadcopterman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
.../github/dedis/popstellar/model/network/method/message/data/federation/FederationResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.github.dedis.popstellar.model.network.method.message.data.federation | ||
|
||
import com.github.dedis.popstellar.model.network.method.message.MessageGeneral | ||
import com.github.dedis.popstellar.model.network.method.message.data.Action | ||
import com.github.dedis.popstellar.model.network.method.message.data.Data | ||
import com.github.dedis.popstellar.model.network.method.message.data.Objects | ||
import com.github.dedis.popstellar.utility.MessageValidator | ||
import com.google.gson.annotations.SerializedName | ||
|
||
/** Informs about the result of the authentication procedure */ | ||
class FederationResult | ||
/** | ||
* Constructor for a data Federation Result | ||
* | ||
* @param status status of the result (either success or failure) | ||
* @param reason reason of the failure | ||
* @param publicKey public key of the other LAO organizer | ||
* @param challenge challenge used to connect the LAOs | ||
*/ | ||
( | ||
val status: String, | ||
val reason: String? = null, | ||
@SerializedName("public_key") val publicKey: String? = null, | ||
val challenge: MessageGeneral, | ||
) : Data { | ||
|
||
init { | ||
MessageValidator.verify().isValidFederationResult(status, reason, publicKey, challenge) | ||
} | ||
|
||
override val `object`: String | ||
get() = Objects.FEDERATION.`object` | ||
|
||
override val action: String | ||
get() = Action.RESULT.action | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (other == null || javaClass != other.javaClass) { | ||
return false | ||
} | ||
val that = other as FederationResult | ||
return status == that.status && | ||
reason == that.reason && | ||
publicKey == that.publicKey && | ||
challenge == that.challenge | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return java.util.Objects.hash(status, reason, publicKey, challenge) | ||
} | ||
|
||
override fun toString(): String { | ||
if (status == FAILURE) { | ||
return "FederationResult{status='$status', reason='$reason', challenge='$challenge'}" | ||
} else if (status == SUCCESS) { | ||
return "FederationResult{status='$status', public_key='$publicKey', " + | ||
"challenge='$challenge'}" | ||
} | ||
return "FederationResult{ERROR}" | ||
} | ||
|
||
fun isSuccess(): Boolean { | ||
return status == SUCCESS | ||
} | ||
|
||
companion object { | ||
const val SUCCESS = "success" | ||
const val FAILURE = "failure" | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...om/github/dedis/popstellar/model/network/method/message/data/federation/TokensExchange.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.github.dedis.popstellar.model.network.method.message.data.federation | ||
|
||
import com.github.dedis.popstellar.model.network.method.message.data.Action | ||
import com.github.dedis.popstellar.model.network.method.message.data.Data | ||
import com.github.dedis.popstellar.model.network.method.message.data.Objects | ||
import com.github.dedis.popstellar.utility.MessageValidator | ||
import com.google.gson.annotations.SerializedName | ||
|
||
/** Token exchange to be broadcast in the LAO */ | ||
class TokensExchange | ||
/** | ||
* Constructor for a data TokenExchange | ||
* | ||
* @param laoId ID of the remote LAO | ||
* @param rollCallId ID of the rollCall of the remote LAO | ||
* @param tokens array of tokens contained in the rollCall | ||
* @param timestamp timestamp of the message | ||
*/ | ||
( | ||
@SerializedName("lao_id") val laoId: String, | ||
@SerializedName("roll_call_id") val rollCallId: String, | ||
val tokens: Array<String>, | ||
val timestamp: Long | ||
) : Data { | ||
|
||
init { | ||
MessageValidator.verify() | ||
.isNotEmptyBase64(laoId, "lao_id") | ||
.isBase64(rollCallId, "roll_call_id") | ||
.arrayElementsNotEmptyBase64(tokens, field = "tokens") | ||
.validPastTimes(timestamp) | ||
} | ||
|
||
override val `object`: String | ||
get() = Objects.FEDERATION.`object` | ||
|
||
override val action: String | ||
get() = Action.TOKENS_EXCHANGE.action | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) { | ||
return true | ||
} | ||
if (other == null || javaClass != other.javaClass) { | ||
return false | ||
} | ||
val that = other as TokensExchange | ||
return laoId == that.laoId && | ||
rollCallId == that.rollCallId && | ||
tokens.contentEquals(that.tokens) && | ||
timestamp == that.timestamp | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return java.util.Objects.hash(laoId, rollCallId, tokens, timestamp) | ||
} | ||
|
||
override fun toString(): String { | ||
return "TokensExchange{lao_id='$laoId', roll_call_id='$rollCallId', " + | ||
"tokens='$tokens', timestamp='$timestamp'}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ import com.github.dedis.popstellar.ui.lao.event.LaoDetailAnimation.showIn | |
import com.github.dedis.popstellar.ui.lao.event.LaoDetailAnimation.showOut | ||
import com.github.dedis.popstellar.ui.qrcode.QrScannerFragment | ||
import com.github.dedis.popstellar.ui.qrcode.ScanningAction | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
/** | ||
* A simple [Fragment] subclass. Use the [LinkedOrganizationsFragment.newInstance] factory method to | ||
|
@@ -41,9 +44,6 @@ class LinkedOrganizationsFragment : Fragment() { | |
linkedOrganizationsViewModel = | ||
obtainLinkedOrganizationsViewModel(requireActivity(), laoViewModel.laoId) | ||
|
||
// Starts from a clean repository | ||
linkedOrganizationsViewModel.flushRepository() | ||
|
||
// Sets the text and the button depending on the user's role | ||
laoViewModel.role.observe(viewLifecycleOwner) { role: Role -> | ||
if (role == Role.ORGANIZER) { | ||
|
@@ -59,6 +59,19 @@ class LinkedOrganizationsFragment : Fragment() { | |
binding.inviteOtherOrganization.setOnClickListener(invitationPage) | ||
binding.joinOtherOrganizationInvitation.setOnClickListener(joinButton) | ||
|
||
// Displaying the linked organizations | ||
val laos = linkedOrganizationsViewModel.getLinkedLaosMap().keys | ||
displayLinkedOrganizations(laos) | ||
linkedOrganizationsViewModel.doWhenLinkedLaosIsUpdated { laoId, laoMap -> | ||
if (laoId == laoViewModel.laoId) { | ||
CoroutineScope(Dispatchers.Main).launch { | ||
val currentLaos = laoMap.keys | ||
displayLinkedOrganizations(currentLaos) | ||
} | ||
} | ||
} | ||
|
||
linkedOrganizationsViewModel.setLinkedLaosNotifyFunction() | ||
Comment on lines
+62
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why calling display first with the current list and then putting a custom and complex observer that uses coroutines and not directly using a simple observer? This relates to my previous comment on how to deal with modifications using observables and subjects |
||
handleBackNav() | ||
|
||
return binding.root | ||
|
@@ -97,13 +110,27 @@ class LinkedOrganizationsFragment : Fragment() { | |
|
||
private var joinButton = | ||
View.OnClickListener { | ||
linkedOrganizationsViewModel.flushRepository() | ||
laoViewModel.setIsTab(false) | ||
linkedOrganizationsViewModel.manager = parentFragmentManager | ||
LaoActivity.setCurrentFragment(parentFragmentManager, R.id.fragment_qr_scanner) { | ||
QrScannerFragment.newInstance(ScanningAction.FEDERATION_JOIN) | ||
} | ||
} | ||
|
||
private fun displayLinkedOrganizations(laos: Set<String>) { | ||
if (laos.isNotEmpty()) { | ||
val laosText = laos.joinToString(separator = "\n\n") | ||
val textToDisplay = context?.getString(R.string.list_organizations, laosText) | ||
binding.noOrganizationsText.visibility = View.GONE | ||
binding.listOrganizationsText.visibility = View.VISIBLE | ||
binding.listOrganizationsText.text = textToDisplay | ||
} else { | ||
binding.listOrganizationsText.visibility = View.GONE | ||
binding.noOrganizationsText.visibility = View.VISIBLE | ||
} | ||
} | ||
|
||
private fun handleBackNav() { | ||
LaoActivity.addBackNavigationCallbackToEvents(requireActivity(), viewLifecycleOwner, TAG) | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you take a look at other repos (any one, e.g. rollcallrepo) you'd see that in general this is not the preferred way to notify modifications on a given data structure, but that we use java rx constructs (subject, observables and so on)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the thing is that I tried using observables and for some reason I had many problems with the UI not updating or weird other issues... That's why in the end I changed to using callbacks, I know it's a bit more complex but at least it's working
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can keep it as is then