Kagome
Polkadot Runtime Engine in C++17
protocol_base.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_NETWORK_PROTOCOLBASE
7 #define KAGOME_NETWORK_PROTOCOLBASE
8 
9 #include "outcome/outcome.hpp"
10 
11 #include <libp2p/connection/stream.hpp>
12 #include <libp2p/peer/peer_info.hpp>
13 #include <libp2p/peer/stream_protocols.hpp>
14 
15 namespace kagome::network {
16 
21  using Protocols = libp2p::StreamProtocols;
22 
23  using namespace std::string_literals;
24 
25  class ProtocolBase {
26  public:
27  ProtocolBase() = default;
28  ProtocolBase(ProtocolBase &&) noexcept = delete;
29  ProtocolBase(const ProtocolBase &) = delete;
30  virtual ~ProtocolBase() = default;
31  ProtocolBase &operator=(ProtocolBase &&) noexcept = delete;
32  ProtocolBase &operator=(ProtocolBase const &) = delete;
33 
34  virtual const std::string &protocolName() const = 0;
35 
36  virtual bool start() = 0;
37  virtual bool stop() = 0;
38 
39  virtual void onIncomingStream(std::shared_ptr<Stream> stream) = 0;
40  virtual void newOutgoingStream(
41  const PeerInfo &peer_info,
42  std::function<void(outcome::result<std::shared_ptr<Stream>>)> &&cb) = 0;
43  };
44 
45 } // namespace kagome::network
46 
47 #endif // KAGOME_NETWORK_PEERING_CONFIG
libp2p::peer::PeerInfo PeerInfo
libp2p::peer::Protocol Protocol
libp2p::StreamProtocols Protocols
libp2p::peer::PeerId PeerId
libp2p::connection::Stream Stream