| 284 | } |
| 285 | |
| 286 | void DatagramDestination::HandleDatagram3 (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len, |
| 287 | i2p::garlic::ECIESX25519AEADRatchetSession * from) |
| 288 | { |
| 289 | if (len < 34) |
| 290 | { |
| 291 | LogPrint (eLogWarning, "Datagram: datagram3 is too short ", len); |
| 292 | return; |
| 293 | } |
| 294 | if (from) |
| 295 | { |
| 296 | std::shared_ptr<const i2p::data::LeaseSet> ls; |
| 297 | i2p::data::IdentHash ident(buf); |
| 298 | auto session = FindSession (ident); |
| 299 | if (session) ls = session->GetRemoteLeaseSet (); |
| 300 | if (!ls) ls = m_Owner->FindLeaseSet (ident); |
| 301 | if (ls) |
| 302 | { |
| 303 | uint8_t staticKey[32]; |
| 304 | ls->Encrypt (nullptr, staticKey); |
| 305 | if (!memcmp (from->GetRemoteStaticKey (), staticKey, 32)) |
| 306 | { |
| 307 | if (!session) |
| 308 | { |
| 309 | session = ObtainSession (ident); |
| 310 | session->SetVersion (eDatagramV3); |
| 311 | } |
| 312 | session->SetRemoteLeaseSet (ls); |
| 313 | auto r = FindReceiver(toPort); |
| 314 | if (r) |
| 315 | { |
| 316 | const uint8_t * flags = buf + 32; |
| 317 | size_t offset = 34; |
| 318 | bool isOptions = false; |
| 319 | if (flags[1] & DATAGRAM3_FLAG_OPTIONS) |
| 320 | { |
| 321 | isOptions = true; |
| 322 | m_Options.CleanUp (); |
| 323 | auto optionsLen = m_Options.FromBuffer (buf + offset, len - offset); |
| 324 | if (optionsLen) |
| 325 | offset += optionsLen; |
| 326 | else |
| 327 | { |
| 328 | LogPrint (eLogWarning, "Datagram: datagram3 can't read options"); |
| 329 | return; |
| 330 | } |
| 331 | } |
| 332 | if (offset > len) |
| 333 | { |
| 334 | LogPrint (eLogWarning, "Datagram: datagram3 is too short ", len, " expected ", offset); |
| 335 | return; |
| 336 | } |
| 337 | r(*ls->GetIdentity (), fromPort, toPort, buf + offset, len - offset, isOptions ? &m_Options : nullptr); |
| 338 | } |
| 339 | else |
| 340 | LogPrint (eLogWarning, "Datagram: no receiver for port ", toPort); |
| 341 | session->Ack (); |
| 342 | } |
| 343 | else |
nothing calls this directly
no test coverage detected