Module libp2p_core::upgrade
source · Expand description
Contains everything related to upgrading a connection or a substream to use a protocol.
After a connection with a remote has been successfully established or a substream successfully opened, the next step is to upgrade this connection or substream to use a protocol.
This is where the UpgradeInfo, InboundUpgrade and OutboundUpgrade traits come into play.
The InboundUpgrade and OutboundUpgrade traits are implemented on types that represent a
collection of one or more possible protocols for respectively an ingoing or outgoing
connection or substream.
Note: Multiple versions of the same protocol are treated as different protocols. For example,
/foo/1.0.0and/foo/1.1.0are totally unrelated as far as upgrading is concerned.
Upgrade process
An upgrade is performed in two steps:
-
A protocol negotiation step. The
UpgradeInfo::protocol_infomethod is called to determine which protocols are supported by the trait implementation. Themultistream-selectprotocol is used in order to agree on which protocol to use amongst the ones supported. -
A handshake. After a successful negotiation, the
InboundUpgrade::upgrade_inboundorOutboundUpgrade::upgrade_outboundmethod is called. This method will return aFuturethat performs a handshake. This handshake is considered mandatory, however in practice it is possible for the trait implementation to return a dummyFuturethat doesn’t perform any action and immediately succeeds.
After an upgrade is successful, an object of type InboundUpgrade::Output or
OutboundUpgrade::Output is returned. The actual object depends on the implementation and
there is no constraint on the traits that it should implement, however it is expected that it
can be used by the user to control the behaviour of the protocol.
Note: You can use the
apply_inboundorapply_outboundmethods to try upgrade a connection or substream. However if you use the recommendedSwarmorConnectionHandlerAPIs, the upgrade is automatically handled for you and you don’t need to use these methods.
Re-exports
pub use crate::Negotiated;Structs
UpgradeInfo/InboundUpgrade/OutboundUpgrade that doesn’t support
any protocol.UpgradeInfo, InboundUpgrade and OutboundUpgrade traits.apply_inbound. Drives the upgrade process.Future that waits on the completion of protocol negotiation.apply_outbound. Drives the upgrade process.UpgradeInfo, InboundUpgrade and OutboundUpgrade that always
returns a pending upgrade.UpgradeInfo, InboundUpgrade and OutboundUpgrade that directly yields the substream.Enums
Traits
InboundUpgrade. Automatically implemented on all types that implement
InboundUpgrade.OutboundUpgrade. Automatically implemented on all types that implement
OutboundUpgrade.Functions
FromFnUpgrade.socket.socket.