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

Method ProcessSessionCreate

libi2pd_client/SAM.cpp:339–485  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

337 }
338
339 void SAMSocket::ProcessSessionCreate (std::string_view buf)
340 {
341 LogPrint (eLogDebug, "SAM: Session create: ", buf);
342 auto params = ExtractParams (buf);
343 std::string_view style = params[SAM_PARAM_STYLE];
344 std::string_view id = params[SAM_PARAM_ID];
345 std::string_view destination = params[SAM_PARAM_DESTINATION];
346
347 if(!IsAcceptableSessionName(id))
348 {
349 // invalid session id
350 SendMessageReply (SAM_SESSION_CREATE_INVALID_ID, true);
351 return;
352 }
353 m_ID = id;
354 if (m_Owner.FindSession (id))
355 {
356 // session exists
357 SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, true);
358 return;
359 }
360
361 SAMSessionType type = SAMSessionType::eSAMSessionTypeUnknown;
362 i2p::datagram::DatagramVersion datagramVersion = i2p::datagram::eDatagramV1;
363 if (style == SAM_VALUE_STREAM) type = SAMSessionType::eSAMSessionTypeStream;
364#if __cplusplus >= 202002L // C++20
365 else if (style.starts_with (SAM_VALUE_DATAGRAM))
366#else
367 else if (style.substr (0, SAM_VALUE_DATAGRAM.size ()) == SAM_VALUE_DATAGRAM)
368#endif
369 {
370 // DATAGRAM, DATAGRAM1, DATAGRAM2, DATAGRAM3
371 type = SAMSessionType::eSAMSessionTypeDatagram;
372 if (style.size () > SAM_VALUE_DATAGRAM.size ())
373 {
374 switch (style[SAM_VALUE_DATAGRAM.size ()])
375 {
376 case '1': datagramVersion = i2p::datagram::eDatagramV1; break;
377 case '2': datagramVersion = i2p::datagram::eDatagramV2; break;
378 case '3': datagramVersion = i2p::datagram::eDatagramV3; break;
379 default: type = SAMSessionType::eSAMSessionTypeUnknown;
380 }
381 }
382 }
383 else if (style == SAM_VALUE_RAW) type = SAMSessionType::eSAMSessionTypeRaw;
384 else if (style == SAM_VALUE_MASTER)
385 {
386 if (m_Version < SAM_VERSION_33) // < SAM 3.3
387 {
388 SendSessionI2PError("MASTER session is not supported");
389 return;
390 }
391 type = SAMSessionType::eSAMSessionTypeMaster;
392 }
393 if (type == SAMSessionType::eSAMSessionTypeUnknown)
394 {
395 // unknown style
396 SendSessionI2PError("Unknown STYLE");

Callers

nothing calls this directly

Calls 11

LogPrintFunction · 0.85
IsAcceptableSessionNameFunction · 0.85
ContainsMethod · 0.80
FromBase64Method · 0.80
SetReceiverMethod · 0.80
SetRawReceiverMethod · 0.80
IsReadyMethod · 0.80
FindSessionMethod · 0.45
CreateSessionMethod · 0.45
GetLocalDestinationMethod · 0.45

Tested by

no test coverage detected