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

Method AddNTCP2Session

libi2pd/NTCP2.cpp:1851–1883  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1849 }
1850
1851 bool NTCP2Server::AddNTCP2Session (std::shared_ptr<NTCP2Session> session, bool incoming)
1852 {
1853 if (!session) return false;
1854 if (incoming)
1855 m_PendingIncomingSessions.erase (session->GetRemoteEndpoint ().address ());
1856 if (!session->GetRemoteIdentity ())
1857 {
1858 LogPrint (eLogWarning, "NTCP2: Unknown identity for ", session->GetRemoteEndpoint ());
1859 session->Terminate ();
1860 return false;
1861 }
1862 auto& ident = session->GetRemoteIdentity ()->GetIdentHash ();
1863 auto it = m_NTCP2Sessions.find (ident);
1864 if (it != m_NTCP2Sessions.end ())
1865 {
1866 LogPrint (eLogWarning, "NTCP2: Session with ", ident.ToBase64 (), " already exists. ", incoming ? "Replaced" : "Dropped");
1867 if (incoming)
1868 {
1869 // replace by new session
1870 auto s = it->second;
1871 s->MoveSendQueue (session);
1872 m_NTCP2Sessions.erase (it);
1873 s->Terminate ();
1874 }
1875 else
1876 {
1877 session->Terminate ();
1878 return false;
1879 }
1880 }
1881 m_NTCP2Sessions.emplace (ident, session);
1882 return true;
1883 }
1884
1885 void NTCP2Server::RemoveNTCP2Session (std::shared_ptr<NTCP2Session> session)
1886 {

Callers 3

ConnectMethod · 0.95
ConnectWithProxyMethod · 0.95

Calls 5

LogPrintFunction · 0.85
ToBase64Method · 0.80
GetRemoteIdentityMethod · 0.45
TerminateMethod · 0.45
MoveSendQueueMethod · 0.45

Tested by

no test coverage detected