This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The IbftRound is responsible for sequencing the transmission of network packets based on received data.
- Loading branch information
Showing
10 changed files
with
679 additions
and
26 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
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
103 changes: 103 additions & 0 deletions
103
...c/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftMessageTransmitter.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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright 2018 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.consensus.ibft.statemachine; | ||
|
||
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.CommitMessage; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.NewRoundMessage; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.PrepareMessage; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.ProposalMessage; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.RoundChangeMessage; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.CommitPayload; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.MessageFactory; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.NewRoundPayload; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.PreparePayload; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.PreparedCertificate; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.ProposalPayload; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.RoundChangeCertificate; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.RoundChangePayload; | ||
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData; | ||
import tech.pegasys.pantheon.consensus.ibft.network.IbftNetworkPeers; | ||
import tech.pegasys.pantheon.crypto.SECP256K1.Signature; | ||
import tech.pegasys.pantheon.ethereum.core.Block; | ||
import tech.pegasys.pantheon.ethereum.core.Hash; | ||
|
||
import java.util.Optional; | ||
|
||
public class IbftMessageTransmitter { | ||
|
||
private final MessageFactory messageFactory; | ||
private final IbftNetworkPeers networkPeers; | ||
|
||
public IbftMessageTransmitter( | ||
final MessageFactory messageFactory, final IbftNetworkPeers networkPeers) { | ||
this.messageFactory = messageFactory; | ||
this.networkPeers = networkPeers; | ||
} | ||
|
||
public void multicastProposal(final ConsensusRoundIdentifier roundIdentifier, final Block block) { | ||
final SignedData<ProposalPayload> signedPayload = | ||
messageFactory.createSignedProposalPayload(roundIdentifier, block); | ||
|
||
final ProposalMessage message = ProposalMessage.create(signedPayload); | ||
|
||
networkPeers.multicastToValidators(message); | ||
} | ||
|
||
public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) { | ||
final SignedData<PreparePayload> signedPayload = | ||
messageFactory.createSignedPreparePayload(roundIdentifier, digest); | ||
|
||
final PrepareMessage message = PrepareMessage.create(signedPayload); | ||
|
||
networkPeers.multicastToValidators(message); | ||
} | ||
|
||
public void multicastCommit( | ||
final ConsensusRoundIdentifier roundIdentifier, | ||
final Hash digest, | ||
final Signature commitSeal) { | ||
final SignedData<CommitPayload> signedPayload = | ||
messageFactory.createSignedCommitPayload(roundIdentifier, digest, commitSeal); | ||
|
||
final CommitMessage message = CommitMessage.create(signedPayload); | ||
|
||
networkPeers.multicastToValidators(message); | ||
} | ||
|
||
public void multicastRoundChange( | ||
final ConsensusRoundIdentifier roundIdentifier, | ||
final Optional<PreparedCertificate> preparedCertificate) { | ||
|
||
final SignedData<RoundChangePayload> signedPayload = | ||
messageFactory.createSignedRoundChangePayload(roundIdentifier, preparedCertificate); | ||
|
||
final RoundChangeMessage message = RoundChangeMessage.create(signedPayload); | ||
|
||
networkPeers.multicastToValidators(message); | ||
} | ||
|
||
public void multicastNewRound( | ||
final ConsensusRoundIdentifier roundIdentifier, | ||
final RoundChangeCertificate roundChangeCertificate, | ||
final SignedData<ProposalPayload> proposalPayload) { | ||
|
||
final SignedData<NewRoundPayload> signedPayload = | ||
messageFactory.createSignedNewRoundPayload( | ||
roundIdentifier, roundChangeCertificate, proposalPayload); | ||
|
||
final NewRoundMessage message = NewRoundMessage.create(signedPayload); | ||
|
||
networkPeers.multicastToValidators(message); | ||
} | ||
} |
Oops, something went wrong.