Interface P2PService
- All Superinterfaces:
BesuService
Service to enable and disable P2P service.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceConsumer of network connection events.static interfaceConsumer of network disconnection events.static interfaceConsumer of network message events. -
Method Summary
Modifier and TypeMethodDescriptionvoidDisables P2P discovery.voiddisconnect(org.apache.tuweni.bytes.Bytes peerId) Disconnect from a specific peer.voidEnables P2P discovery.Collection<? extends Peer> Get all maintained connection peers.Collection<? extends PeerConnection> Get all connected peer connections.intGet the number of connected peers.voidsend(String protocol, org.apache.tuweni.bytes.Bytes peerId, org.hyperledger.besu.datatypes.p2p.MessageData messageData) Send a message to a specific peer.voidsubscribeConnect(P2PService.ConnectionListener networkSubscriber) Subscribe to connection events.voidsubscribeDisconnect(P2PService.DisconnectionListener networkSubscriber) Subscribe to disconnection events.voidsubscribeMessage(Capability capability, P2PService.MessageListener networkSubscriber) Subscribe to messages on a specific capability.
-
Method Details
-
enableDiscovery
void enableDiscovery()Enables P2P discovery. -
disableDiscovery
void disableDiscovery()Disables P2P discovery. -
getPeerCount
int getPeerCount()Get the number of connected peers.- Returns:
- the number of connected peers
-
getPeerConnections
Collection<? extends PeerConnection> getPeerConnections()Get all connected peer connections.- Returns:
- list of connected peer connections
-
getMaintainedConnectionPeers
Collection<? extends Peer> getMaintainedConnectionPeers()Get all maintained connection peers.- Returns:
- list of maintained connection peers
-
subscribeConnect
Subscribe to connection events.- Parameters:
networkSubscriber- the subscriber to receive connection events
-
subscribeDisconnect
Subscribe to disconnection events.- Parameters:
networkSubscriber- the subscriber to receive disconnection events
-
subscribeMessage
Subscribe to messages on a specific capability.- Parameters:
capability- the capability to subscribe tonetworkSubscriber- the subscriber to receive messages for the specified capability
-
send
void send(String protocol, org.apache.tuweni.bytes.Bytes peerId, org.hyperledger.besu.datatypes.p2p.MessageData messageData) throws PeerConnection.PeerNotConnected Send a message to a specific peer.- Parameters:
protocol- the protocol to usepeerId- the peer id to send the message tomessageData- the message data to send- Throws:
PeerConnection.PeerNotConnected- if the peer is not connected
-
disconnect
void disconnect(org.apache.tuweni.bytes.Bytes peerId) Disconnect from a specific peer.- Parameters:
peerId- the peer id to disconnect from
-