MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / SendPing

Method SendPing

libi2pd_client/BOB.cpp:849–894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

847 }
848
849 void BOBCommandSession::SendPing (std::shared_ptr<const i2p::data::LeaseSet> ls)
850 {
851 if (!ls)
852 {
853 SendReplyError ("LeaseSet Not found");
854 return;
855 }
856 auto localDestination = (m_CurrentDestination && m_CurrentDestination->IsRunning ()) ?
857 m_CurrentDestination->GetLocalDestination () : i2p::client::context.GetSharedLocalDestination ();
858 if (!localDestination)
859 {
860 SendReplyError ("No local destination");
861 return;
862 }
863 auto streamingDestination = localDestination->GetStreamingDestination ();
864 if (!streamingDestination)
865 {
866 SendReplyError ("No streaming destination");
867 return;
868 }
869 auto timer = std::make_shared<boost::asio::steady_timer>(localDestination->GetService ());
870 timer->expires_after (std::chrono::milliseconds(BOB_PING_TIMEOUT));
871 timer->async_wait ([streamingDestination, s = shared_from_this ()](const boost::system::error_code& ecode)
872 {
873 if (ecode != boost::asio::error::operation_aborted)
874 {
875 LogPrint (eLogDebug, "BOB: Pong not received after ", BOB_PING_TIMEOUT, " millliseconds");
876 streamingDestination->ResetPongHandler ();
877 s->SendReplyError ("timeout");
878 }
879 });
880 auto ts = i2p::util::GetMillisecondsSinceEpoch ();
881 streamingDestination->SetPongHandler (
882 [streamingDestination, timer, ts, s = shared_from_this ()](const i2p::data::IdentHash * from)
883 {
884 int t = i2p::util::GetMillisecondsSinceEpoch () - ts;
885 if (t < 0) t = 0;
886 streamingDestination->ResetPongHandler ();
887 timer->cancel ();
888 if (from)
889 s->SendReplyOK ({"pong ", "from ", from->ToBase32(), ".b32.i2p: time=", std::to_string (t), " ms"});
890 else
891 s->SendReplyOK ({"pong: time=", std::to_string (t), " ms"});
892 });
893 streamingDestination->SendPing (ls);
894 }
895
896 void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len)
897 {

Callers 1

HandleKeepAliveTimerMethod · 0.45

Calls 11

LogPrintFunction · 0.85
to_stringFunction · 0.85
ResetPongHandlerMethod · 0.80
SendReplyErrorMethod · 0.80
SetPongHandlerMethod · 0.80
SendReplyOKMethod · 0.80
IsRunningMethod · 0.45
GetLocalDestinationMethod · 0.45

Tested by

no test coverage detected