| 350 | } |
| 351 | |
| 352 | void Session::CreateIfNotCreatedAlready() |
| 353 | { |
| 354 | std::string errmsg; |
| 355 | if (m_control_sock->IsConnected(errmsg)) { |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | Log("Creating SAM session with %s", m_control_host.ToString()); |
| 360 | |
| 361 | auto sock = Hello(); |
| 362 | |
| 363 | const auto& [read_ok, data] = ReadBinaryFile(m_private_key_file); |
| 364 | if (read_ok) { |
| 365 | m_private_key.assign(data.begin(), data.end()); |
| 366 | } else { |
| 367 | GenerateAndSavePrivateKey(*sock); |
| 368 | } |
| 369 | |
| 370 | const std::string& session_id = GetRandHash().GetHex().substr(0, 10); // full is an overkill, too verbose in the logs |
| 371 | const std::string& private_key_b64 = SwapBase64(EncodeBase64(m_private_key)); |
| 372 | |
| 373 | SendRequestAndGetReply(*sock, strprintf("SESSION CREATE STYLE=STREAM ID=%s DESTINATION=%s", |
| 374 | session_id, private_key_b64)); |
| 375 | |
| 376 | m_my_addr = CService(DestBinToAddr(MyDestination()), I2P_SAM31_PORT); |
| 377 | m_session_id = session_id; |
| 378 | m_control_sock = std::move(sock); |
| 379 | |
| 380 | LogPrintf("I2P: SAM session created: session id=%s, my address=%s\n", m_session_id, |
| 381 | m_my_addr.ToString()); |
| 382 | } |
| 383 | |
| 384 | std::unique_ptr<Sock> Session::StreamAccept() |
| 385 | { |
nothing calls this directly
no test coverage detected