| 2204 | } |
| 2205 | |
| 2206 | void SSU2Session::HandleRelayRequest (const uint8_t * buf, size_t len) |
| 2207 | { |
| 2208 | // we are Bob |
| 2209 | if (len < 9) return; |
| 2210 | auto mts = i2p::util::GetMillisecondsSinceEpoch (); |
| 2211 | uint32_t nonce = bufbe32toh (buf + 1); // nonce |
| 2212 | uint32_t relayTag = bufbe32toh (buf + 5); // relay tag |
| 2213 | auto session = m_Server.FindRelaySession (relayTag); |
| 2214 | if (!session) |
| 2215 | { |
| 2216 | LogPrint (eLogWarning, "SSU2: RelayRequest session with relay tag ", relayTag, " not found"); |
| 2217 | // send relay response back to Alice |
| 2218 | auto packet = m_Server.GetSentPacketsPool ().AcquireShared (); |
| 2219 | packet->payloadSize = CreateAckBlock (packet->payload, m_MaxPayloadSize); |
| 2220 | packet->payloadSize += CreateRelayResponseBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize, |
| 2221 | eSSU2RelayResponseCodeBobRelayTagNotFound, nonce, 0, false); |
| 2222 | packet->payloadSize += CreatePaddingBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize); |
| 2223 | uint32_t packetNum = SendData (packet->payload, packet->payloadSize); |
| 2224 | if (m_RemoteVersion >= SSU2_MIN_RELAY_RESPONSE_RESEND_VERSION) |
| 2225 | { |
| 2226 | // sometimes Alice doesn't ack this RelayResponse in older versions |
| 2227 | packet->sendTime = mts; |
| 2228 | m_SentPackets.emplace (packetNum, packet); |
| 2229 | } |
| 2230 | return; |
| 2231 | } |
| 2232 | if (session->m_RelaySessions.emplace (nonce, std::make_pair (shared_from_this (), mts/1000)).second) |
| 2233 | { |
| 2234 | // send relay intro to Charlie |
| 2235 | auto r = i2p::data::netdb.FindRouter (GetRemoteIdentity ()->GetIdentHash ()); // Alice's RI |
| 2236 | if (r && (r->IsUnreachable () || !i2p::data::netdb.PopulateRouterInfoBuffer (r))) r = nullptr; |
| 2237 | if (!r) LogPrint (eLogWarning, "SSU2: RelayRequest Alice's router info not found"); |
| 2238 | |
| 2239 | auto packet = m_Server.GetSentPacketsPool ().AcquireShared (); |
| 2240 | packet->payloadSize = r ? CreateRouterInfoBlock (packet->payload, m_MaxPayloadSize - len - 32, r) : 0; |
| 2241 | if (!packet->payloadSize && r) |
| 2242 | session->SendFragmentedMessage (CreateDatabaseStoreMsg (r)); |
| 2243 | packet->payloadSize += CreateRelayIntroBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize, buf + 1, len - 1); |
| 2244 | if (packet->payloadSize < m_MaxPayloadSize) |
| 2245 | packet->payloadSize += CreatePaddingBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize); |
| 2246 | uint32_t packetNum = session->SendData (packet->payload, packet->payloadSize); |
| 2247 | packet->sendTime = mts; |
| 2248 | // Charlie always responds with RelayResponse |
| 2249 | session->m_SentPackets.emplace (packetNum, packet); |
| 2250 | } |
| 2251 | else |
| 2252 | LogPrint (eLogInfo, "SSU2: Relay request nonce ", nonce, " already exists. Ignore"); |
| 2253 | } |
| 2254 | |
| 2255 | void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len, int attempts) |
| 2256 | { |
nothing calls this directly
no test coverage detected