| 524 | } |
| 525 | |
| 526 | void SAMSocket::ProcessStreamConnect (char * buf, size_t len, size_t rem) |
| 527 | { |
| 528 | LogPrint (eLogDebug, "SAM: Stream connect: ", buf); |
| 529 | if ( m_SocketType != SAMSocketType::eSAMSocketTypeUnknown) |
| 530 | { |
| 531 | SendSessionI2PError ("Socket already in use"); |
| 532 | return; |
| 533 | } |
| 534 | auto params = ExtractParams (buf); |
| 535 | std::string_view id = params[SAM_PARAM_ID]; |
| 536 | std::string_view destination = params[SAM_PARAM_DESTINATION]; |
| 537 | std::string_view silent = params[SAM_PARAM_SILENT]; |
| 538 | if (silent == SAM_VALUE_TRUE) m_IsSilent = true; |
| 539 | m_ID = id; |
| 540 | auto session = m_Owner.FindSession (id); |
| 541 | if (session) |
| 542 | { |
| 543 | if (rem > 0) // handle follow on data |
| 544 | { |
| 545 | memmove (m_Buffer, buf + len + 1, rem); // buf is a pointer to m_Buffer's content |
| 546 | m_BufferOffset = rem; |
| 547 | } |
| 548 | else |
| 549 | m_BufferOffset = 0; |
| 550 | |
| 551 | std::shared_ptr<const Address> addr; |
| 552 | if (destination.find(".i2p") != std::string::npos) |
| 553 | addr = context.GetAddressBook().GetAddress (destination); |
| 554 | else |
| 555 | { |
| 556 | auto dest = std::make_shared<i2p::data::IdentityEx> (); |
| 557 | size_t l = dest->FromBase64(destination); |
| 558 | if (l > 0) |
| 559 | { |
| 560 | context.GetAddressBook().InsertFullAddress(dest); |
| 561 | addr = std::make_shared<Address>(dest->GetIdentHash ()); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | if (addr && addr->IsValid ()) |
| 566 | { |
| 567 | if (addr->IsIdentHash ()) |
| 568 | { |
| 569 | if (session->GetLocalDestination ()->GetIdentHash () != addr->identHash) |
| 570 | { |
| 571 | auto leaseSet = session->GetLocalDestination ()->FindLeaseSet(addr->identHash); |
| 572 | if (leaseSet) |
| 573 | Connect(leaseSet, session); |
| 574 | else |
| 575 | { |
| 576 | session->GetLocalDestination ()->RequestDestination(addr->identHash, |
| 577 | std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete, |
| 578 | shared_from_this(), std::placeholders::_1)); |
| 579 | } |
| 580 | } |
| 581 | else |
| 582 | SendStreamCantReachPeer ("Can't connect to myself"); |
| 583 | } |
nothing calls this directly
no test coverage detected