libp2p / cpp-libp2p

C++17 implementation of libp2p
Apache License 2.0
364 stars 99 forks source link

Cannot connect two machines in the same network with rendezvous chat example #180

Closed AVassilev98 closed 2 years ago

AVassilev98 commented 2 years ago

Running two instances of the rendezvous_chat with cmd-line arg /ip4/127.0.0.1/tcp/0 on two different machines under the same network leads to them not connecting. Running two instances of rendezvous_chat on the same machine works fine.

The description stated that finding peers can take a while. But I have left the machines for ~30 minutes and they still do not discover eachother. Am I simply not waiting long enough? On one of the machines I see "outgoing connection failed: Connection refused", so I believe there is an attempt to connect, but it is being refused for some reason.

Looking through the source code I see that this error is being returned from the dialer_impl.cpp

I would really appreciate some insight from someone who is familiar with this code since I have spent a few days looking through the source trying to understand/fix this with no success, and this is a blocker for my project. Thank you very much in advance!

Here is the relevant callstack:

`#0 handleOutgoingStream (stream_res=...) at /home/anton/git/cpp-libp2p/example/02-kademlia/rendezvous_chat.cpp:141

1 0x000055555561b198 in std::_Function_handler<void (boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >), void (*)(boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >)>::_M_invoke(std::_Any_data const&, boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >&&) (functor=..., args#0=...) at /usr/include/c++/9/bits/std_function.h:300

2 0x0000555555784939 in std::function<void (boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >)>::operator()(boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >) const (this=0x555556c63450, __args#0=...) at /usr/include/c++/9/bits/std_function.h:688

3 0x0000555555879486 in libp2p::network::DialerImpl::<lambda(libp2p::outcome::result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >)>::operator()(libp2p::outcome::result) (__closure=0x555556c63440, rconn=...) at /home/anton/git/cpp-libp2p/src/network/impl/dialer_impl.cpp:165

4 0x000055555587bb78 in std::_Function_handler<void(boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >), libp2p::network::DialerImpl::newStream(const libp2p::peer::PeerInfo&, const Protocol&, libp2p::network::Dialer::StreamResultFunc, std::chrono::milliseconds)::<lambda(libp2p::outcome::result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >)> >::_M_invoke(const std::_Any_data &, boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> > &&) (functor=..., args#0=...) at /usr/include/c++/9/bits/std_function.h:300

--Type for more, q to quit, c to continue without paging--

5 0x000055555574347d in std::function<void (boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >)>::operator()(boost::outcome_v2::basic_result<std::shared_ptr, std::error_code, boost::outcome_v2::policy::error_code_throw_as_system_error<std::shared_ptr, std::error_code, void> >) const (this=0x555556a53b78, __args#0=...) at /usr/include/c++/9/bits/std_function.h:688

6 0x0000555555879020 in libp2p::network::DialerImpl::<lambda()>::operator()(void) const (__closure=0x555556a53b50) at /home/anton/git/cpp-libp2p/src/network/impl/dialer_impl.cpp:147

7 0x000055555587b86a in std::_Function_handler<void(), libp2p::network::DialerImpl::completeDial(const libp2p::peer::PeerId&, const DialResult&)::<lambda()> >::_M_invoke(const std::_Any_data &) (__functor=...)

at /usr/include/c++/9/bits/std_function.h:300

8 0x000055555561385e in std::function<void ()>::operator()() const (this=0x5555561c10f8) at /usr/include/c++/9/bits/std_function.h:688

9 0x00005555558fbdd3 in libp2p::basic::SchedulerImpl::DeferredCallbacks::processNonCancellableItems (items=..., owner=std::shared_ptr (use count 102, weak count 292) = {...})

at /home/anton/git/cpp-libp2p/src/basic/scheduler/scheduler_impl.cpp:185

10 0x00005555558fc250 in libp2p::basic::SchedulerImpl::DeferredCallbacks::<lambda()>::operator()(void) const (__closure=0x7fffffffbf80) at /home/anton/git/cpp-libp2p/src/basic/scheduler/scheduler_impl.cpp:269

11 0x00005555558fc42c in libp2p::basic::SchedulerImpl::DeferredCallbacks::onTimer (this=0x5555561b64d8, owner=std::shared_ptr (empty) = {...})

at /home/anton/git/cpp-libp2p/src/basic/scheduler/scheduler_impl.cpp:286

12 0x00005555558fb621 in libp2p::basic::SchedulerImpl::pulse (this=0x5555561b64a0, current_clock=...) at /home/anton/git/cpp-libp2p/src/basic/scheduler/scheduler_impl.cpp:84

13 0x00005555558dfdf9 in libp2p::basic::AsioSchedulerBackend::<lambda()>::operator()(void) const (__closure=0x7fffffffc1a0) at /home/anton/git/cpp-libp2p/src/basic/scheduler/asio_scheduler_backend.cpp:26

14 0x00005555558e1613 in boost::asio::asio_handler_invoke<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr)::<lambda()> >(libp2p::basic::AsioSchedulerBackend::<lambda()> &, ...) (function=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/handler_invoke_hook.hpp:69

15 0x00005555558e1336 in boost_asio_handler_invoke_helpers::invoke<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr)::<lambda()>, libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr)::<lambda()> >(libp2p::basic::AsioSchedulerBackend::<lambda()> &, libp2p::basic::AsioSchedulerBackend::<lambda()> &)

(function=..., context=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/handler_invoke_helpers.hpp:37

16 0x00005555558e0e7f in boost::asio::detail::handler_work<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr)::<lambda()>, boost::asio::system_executor, boost::asio::system_executor>::complete<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr)::<lambda()> >(libp2p::basic::AsioSchedulerBackend::<lambda()> &, libp2p::basic::AsioSchedulerBackend::<lambda()> &) (this=0x7fffffffc196, function=..., handler=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/handler_work.hpp:100

17 0x00005555558e0bab in boost::asio::detail::completion_handler<libp2p::basic::AsioSchedulerBackend::setTimer(std::chrono::milliseconds, std::weak_ptr)::<lambda()> >::do_complete(void , boost::asio::detail::operation , const boost::system::error_code &, std::size_t) (owner=0x5555561b6f40, base=0x555556b6ad50)

at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/completion_handler.hpp:70

18 0x00005555555fe1e8 in boost::asio::detail::scheduler_operation::complete (this=0x555556b6ad50, owner=0x5555561b6f40, ec=..., bytes_transferred=0)

at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/scheduler_operation.hpp:40

19 0x00005555556033f0 in boost::asio::detail::scheduler::do_run_one (this=0x5555561b6f40, lock=..., this_thread=..., ec=...)

at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/impl/scheduler.ipp:447

20 0x0000555555602d10 in boost::asio::detail::scheduler::run (this=0x5555561b6f40, ec=...) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/detail/impl/scheduler.ipp:200

21 0x0000555555603f9a in boost::asio::io_context::run (this=0x5555561b94b0) at /home/anton/.hunter/_Base/64a1180/1720112/8459457/Install/include/boost/asio/impl/io_context.ipp:63

22 0x00005555555e8625 in main (argc=2, argv=0x7fffffffda08) at /home/anton/git/cpp-libp2p/example/02-kademlia/rendezvous_chat.cpp:388`