-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MessagePayload: derive signed from signedBy
- Loading branch information
1 parent
dd85b79
commit 142c518
Showing
1 changed file
with
30 additions
and
30 deletions.
There are no files selected for viewing
60 changes: 30 additions & 30 deletions
60
simulator/src/main/java/byzzbench/simulator/transport/MessagePayload.java
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 |
---|---|---|
@@ -1,40 +1,40 @@ | ||
package byzzbench.simulator.transport; | ||
|
||
import java.io.Serializable; | ||
|
||
import lombok.Getter; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* Interface for the payload of a {@link MessageEvent}. | ||
*/ | ||
@Getter | ||
public abstract class MessagePayload implements Serializable { | ||
// Could be removed as we can just check | ||
// signedBy != null | ||
private boolean signed; | ||
private String signedBy; | ||
|
||
/** | ||
* A string representation of the message type. | ||
*/ | ||
public abstract String getType(); | ||
|
||
|
||
/* | ||
* Dummy function to validate the signature of the | ||
* message instance. Returns true if the message was | ||
* signed by @param id. | ||
*/ | ||
public boolean isSignedBy(String id) { | ||
return this.signed && this.signedBy.equals(id); | ||
} | ||
|
||
/* | ||
* Dummy function to sign the message with the public | ||
* key of the @param sender. | ||
*/ | ||
public void sign(String sender) { | ||
this.signed = true; | ||
this.signedBy = sender; | ||
} | ||
private String signedBy; | ||
|
||
/** | ||
* A string representation of the message type. | ||
*/ | ||
public abstract String getType(); | ||
|
||
|
||
/* | ||
* Dummy function to validate the signature of the | ||
* message instance. Returns true if the message was | ||
* signed by @param id. | ||
*/ | ||
public boolean isSignedBy(String id) { | ||
return this.isSigned() && this.signedBy.equals(id); | ||
} | ||
|
||
/* | ||
* Dummy function to sign the message with the public | ||
* key of the @param sender. | ||
*/ | ||
public void sign(String sender) { | ||
this.signedBy = sender; | ||
} | ||
|
||
public boolean isSigned() { | ||
return this.signedBy != null; | ||
} | ||
} |