-
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.
769 implement beefy networking (#794)
# Description - Add all components needed to receive and send messages on the libp2p substream "/beefy/2" - Implement abstract classes for the network layer in order to reduce code duplication Fixes #769
- Loading branch information
1 parent
f4fed72
commit dd6b029
Showing
41 changed files
with
1,138 additions
and
432 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
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
2 changes: 1 addition & 1 deletion
2
src/main/java/com/limechain/network/dto/ProtocolStreamType.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,5 +1,5 @@ | ||
package com.limechain.network.dto; | ||
|
||
public enum ProtocolStreamType { | ||
GRANDPA, BLOCK_ANNOUNCE, TRANSACTIONS | ||
TRANSACTIONS, BLOCK_ANNOUNCE, GRANDPA, BEEFY | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/limechain/network/protocol/base/BaseController.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,24 @@ | ||
package com.limechain.network.protocol.base; | ||
|
||
import io.libp2p.core.Stream; | ||
|
||
/** | ||
* An abstract controller for sending message on a specific stream | ||
*/ | ||
public abstract class BaseController<E extends BaseEngine> { | ||
|
||
protected final Stream stream; | ||
protected final E engine; | ||
|
||
protected BaseController(Stream stream, E engine) { | ||
this.stream = stream; | ||
this.engine = engine; | ||
} | ||
|
||
/** | ||
* Sends a handshake message over the controller stream. | ||
*/ | ||
public void sendHandshake() { | ||
engine.writeHandshakeToStream(stream, stream.remotePeerId()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/limechain/network/protocol/base/BaseEngine.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,16 @@ | ||
package com.limechain.network.protocol.base; | ||
|
||
import io.libp2p.core.PeerId; | ||
import io.libp2p.core.Stream; | ||
|
||
/** | ||
* Abstract engine for handling transactions on specific streams | ||
*/ | ||
public interface BaseEngine { | ||
|
||
void handleHandshake(byte[] message, PeerId peerId, Stream stream); | ||
|
||
void receiveRequest(byte[] message, Stream stream); | ||
|
||
void writeHandshakeToStream(Stream stream, PeerId peerId); | ||
} |
Oops, something went wrong.