MCPcopy Create free account
hub / github.com/ElementsProject/elements / CreateIfNotCreatedAlready

Method CreateIfNotCreatedAlready

src/i2p.cpp:352–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350}
351
352void 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
384std::unique_ptr<Sock> Session::StreamAccept()
385{

Callers

nothing calls this directly

Calls 13

LogFunction · 0.85
ReadBinaryFileFunction · 0.85
GetRandHashFunction · 0.85
SwapBase64Function · 0.85
DestBinToAddrFunction · 0.85
CServiceClass · 0.70
EncodeBase64Function · 0.50
IsConnectedMethod · 0.45
ToStringMethod · 0.45
assignMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected