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

Method HandleDatagram2

libi2pd/Datagram.cpp:196–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194 }
195
196 void DatagramDestination::HandleDatagram2 (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len,
197 i2p::garlic::ECIESX25519AEADRatchetSession * from)
198 {
199 if (len < 433)
200 {
201 LogPrint (eLogWarning, "Datagram: datagram2 is too short ", len);
202 return;
203 }
204 i2p::data::IdentityEx identity;
205 size_t identityLen = identity.FromBuffer (buf, len);
206 if (!identityLen) return;
207 size_t signatureLen = identity.GetSignatureLen ();
208 if (signatureLen + identityLen > len) return;
209
210 std::shared_ptr<i2p::data::LeaseSet> ls;
211 bool verified = false;
212 if (from)
213 {
214 ls = m_Owner->FindLeaseSet (identity.GetIdentHash ());
215 if (ls)
216 {
217 uint8_t staticKey[32];
218 ls->Encrypt (nullptr, staticKey);
219 if (!memcmp (from->GetRemoteStaticKey (), staticKey, 32))
220 verified = true;
221 else
222 {
223 LogPrint (eLogError, "Datagram: Remote LeaseSet static key mismatch for datagram2 from ",
224 identity.GetIdentHash ().ToBase32 ());
225 return;
226 }
227 }
228 }
229 const uint8_t * flags = buf + identityLen;
230 size_t offset = identityLen + 2;
231 bool isOptions = false;
232 if (flags[1] & DATAGRAM2_FLAG_OPTIONS)
233 {
234 isOptions = true;
235 m_Options.CleanUp ();
236 auto optionsLen = m_Options.FromBuffer (buf + offset, len - offset);
237 if (optionsLen)
238 offset += optionsLen;
239 else
240 {
241 LogPrint (eLogWarning, "Datagram: datagram2 can't read options");
242 return;
243 }
244 }
245 if (offset > len)
246 {
247 LogPrint (eLogWarning, "Datagram: datagram2 is too short ", len, " expected ", offset);
248 return;
249 }
250 if (!verified)
251 {
252 std::shared_ptr<i2p::crypto::Verifier> transientVerifier;
253 if (flags[1] & DATAGRAM2_FLAG_OFFLINE_SIGNATURE)

Callers

nothing calls this directly

Calls 12

LogPrintFunction · 0.85
ProcessOfflineSignatureFunction · 0.85
GetRemoteStaticKeyMethod · 0.80
SetRemoteLeaseSetMethod · 0.80
AckMethod · 0.80
FromBufferMethod · 0.45
GetSignatureLenMethod · 0.45
FindLeaseSetMethod · 0.45
EncryptMethod · 0.45
CleanUpMethod · 0.45
VerifyMethod · 0.45
SetVersionMethod · 0.45

Tested by

no test coverage detected