55 */
66
77#include < libp2p/protocol/identify/identify.hpp>
8-
98#include < string>
109#include < tuple>
1110
1211#include < boost/assert.hpp>
1312
14- namespace {
15- const std::string kIdentifyProto = " /ipfs/id/1.0.0" ;
16- } // namespace
17-
1813namespace libp2p ::protocol {
19- Identify::Identify (Host &host,
14+ Identify::Identify (const IdentifyConfig &config,
15+ Host &host,
2016 std::shared_ptr<IdentifyMessageProcessor> msg_processor,
2117 event::Bus &event_bus)
22- : host_{host}, msg_processor_{std::move (msg_processor)}, bus_{event_bus} {
18+ : host_{host},
19+ msg_processor_{std::move (msg_processor)},
20+ bus_{event_bus},
21+ protocols_{config.protocols } {
2322 BOOST_ASSERT (msg_processor_);
2423 }
2524
@@ -38,7 +37,7 @@ namespace libp2p::protocol {
3837 }
3938
4039 peer::ProtocolName Identify::getProtocolId () const {
41- return kIdentifyProto ;
40+ return protocols_. empty () ? peer::ProtocolName{} : protocols_. front () ;
4241 }
4342
4443 void Identify::handle (StreamAndProtocol stream) {
@@ -50,7 +49,7 @@ namespace libp2p::protocol {
5049 BOOST_ASSERT (!started_);
5150 started_ = true ;
5251
53- host_.setProtocolHandler ({ kIdentifyProto } ,
52+ host_.setProtocolHandler (protocols_ ,
5453 [wp = weak_from_this ()](StreamAndProtocol stream) {
5554 if (auto self = wp.lock ()) {
5655 self->handle (std::move (stream));
@@ -86,9 +85,7 @@ namespace libp2p::protocol {
8685 std::move (remote_peer_addr_res.value ())}};
8786
8887 msg_processor_->getHost ().newStream (
89- peer_info,
90- {kIdentifyProto },
91- [self{shared_from_this ()}](auto &&stream_res) {
88+ peer_info, protocols_, [self{shared_from_this ()}](auto &&stream_res) {
9289 if (!stream_res) {
9390 return ;
9491 }
0 commit comments