| 536 | } |
| 537 | |
| 538 | void SSU2Server::AddSessionByRouterHash (std::shared_ptr<SSU2Session> session) |
| 539 | { |
| 540 | if (session) |
| 541 | { |
| 542 | auto ident = session->GetRemoteIdentity (); |
| 543 | if (ident) |
| 544 | { |
| 545 | std::shared_ptr<SSU2Session> oldSession; |
| 546 | { |
| 547 | std::lock_guard<std::mutex> l(m_SessionsByRouterHashMutex); |
| 548 | auto ret = m_SessionsByRouterHash.emplace (ident->GetIdentHash (), session); |
| 549 | if (!ret.second) |
| 550 | { |
| 551 | oldSession = ret.first->second.lock (); |
| 552 | // update session |
| 553 | ret.first->second = session; |
| 554 | } |
| 555 | } |
| 556 | if (oldSession && oldSession != session) |
| 557 | { |
| 558 | // session already exists |
| 559 | LogPrint (eLogWarning, "SSU2: Session to ", ident->GetIdentHash ().ToBase64 (), " already exists"); |
| 560 | // move unsent msgs to new session |
| 561 | oldSession->MoveSendQueue (session); |
| 562 | // terminate existing |
| 563 | boost::asio::post (GetService (), std::bind (&SSU2Session::RequestTermination, oldSession, eSSU2TerminationReasonReplacedByNewSession)); |
| 564 | } |
| 565 | } |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | bool SSU2Server::AddPendingOutgoingSession (std::shared_ptr<SSU2Session> session) |
| 570 | { |
no test coverage detected