| 668 | } |
| 669 | |
| 670 | void I2CPSession::CreateSessionMessageHandler (const uint8_t * buf, size_t len) |
| 671 | { |
| 672 | RAND_bytes ((uint8_t *)&m_SessionID, 2); |
| 673 | auto identity = std::make_shared<i2p::data::IdentityEx>(); |
| 674 | size_t offset = identity->FromBuffer (buf, len); |
| 675 | if (!offset) |
| 676 | { |
| 677 | LogPrint (eLogError, "I2CP: Create session malformed identity"); |
| 678 | SendSessionStatusMessage (eI2CPSessionStatusInvalid); // invalid |
| 679 | return; |
| 680 | } |
| 681 | if (m_Owner.FindSessionByIdentHash (identity->GetIdentHash ())) |
| 682 | { |
| 683 | LogPrint (eLogError, "I2CP: Create session duplicate address ", identity->GetIdentHash ().ToBase32 ()); |
| 684 | SendSessionStatusMessage (eI2CPSessionStatusInvalid); // invalid |
| 685 | return; |
| 686 | } |
| 687 | uint16_t optionsSize = bufbe16toh (buf + offset); |
| 688 | offset += 2; |
| 689 | if (optionsSize > len - offset) |
| 690 | { |
| 691 | LogPrint (eLogError, "I2CP: Options size ", optionsSize, "exceeds message size"); |
| 692 | SendSessionStatusMessage (eI2CPSessionStatusInvalid); // invalid |
| 693 | return; |
| 694 | } |
| 695 | i2p::util::Mapping params; |
| 696 | params.FromBuffer (optionsSize, buf + offset, len - offset); |
| 697 | offset += optionsSize; // options |
| 698 | if (params[I2CP_PARAM_MESSAGE_RELIABILITY] == "none") m_IsSendAccepted = false; |
| 699 | |
| 700 | offset += 8; // date |
| 701 | if (identity->Verify (buf, offset, buf + offset)) // signature |
| 702 | { |
| 703 | if (!m_Destination) |
| 704 | { |
| 705 | m_Destination = m_Owner.IsSingleThread () ? |
| 706 | std::make_shared<I2CPDestination>(m_Owner.GetService (), shared_from_this (), identity, true, true, params): |
| 707 | std::make_shared<RunnableI2CPDestination>(shared_from_this (), identity, true, params); |
| 708 | if (m_Owner.InsertSession (shared_from_this ())) |
| 709 | { |
| 710 | LogPrint (eLogDebug, "I2CP: Session ", m_SessionID, " created"); |
| 711 | m_Destination->Start (); |
| 712 | SendSessionStatusMessage (eI2CPSessionStatusCreated); // created |
| 713 | } |
| 714 | else |
| 715 | { |
| 716 | LogPrint (eLogError, "I2CP: Session already exists"); |
| 717 | SendSessionStatusMessage (eI2CPSessionStatusRefused); |
| 718 | } |
| 719 | } |
| 720 | else |
| 721 | { |
| 722 | LogPrint (eLogError, "I2CP: Session already exists"); |
| 723 | SendSessionStatusMessage (eI2CPSessionStatusRefused); // refused |
| 724 | } |
| 725 | } |
| 726 | else |
| 727 | { |
nothing calls this directly
no test coverage detected