-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1943 from dedis/work-fe2-johan-federation
Federation Data Exchange for FE2
- Loading branch information
Showing
31 changed files
with
915 additions
and
83 deletions.
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
Oops, something went wrong.