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

Method SendMsgTo

libi2pd_client/I2CP.cpp:248–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246 }
247
248 void I2CPDestination::SendMsgTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint32_t nonce)
249 {
250 auto msg = m_I2NPMsgsPool.AcquireSharedMt ();
251 uint8_t * buf = msg->GetPayload ();
252 htobe32buf (buf, len);
253 memcpy (buf + 4, payload, len);
254 msg->len += len + 4;
255 msg->FillI2NPMessageHeader (eI2NPData);
256 auto remote = FindLeaseSet (ident);
257 if (remote)
258 {
259 if (m_IsSameThread)
260 {
261 // send right a way
262 bool sent = SendMsg (msg, remote);
263 if (m_Owner)
264 m_Owner->SendMessageStatusMessage (nonce, sent ? eI2CPMessageStatusGuaranteedSuccess : eI2CPMessageStatusGuaranteedFailure);
265 }
266 else
267 {
268 // send in destination's thread
269 auto s = GetSharedFromThis ();
270 boost::asio::post (GetService (),
271 [s, msg, remote, nonce]()
272 {
273 bool sent = s->SendMsg (msg, remote);
274 if (s->m_Owner)
275 s->m_Owner->SendMessageStatusMessage (nonce, sent ? eI2CPMessageStatusGuaranteedSuccess : eI2CPMessageStatusGuaranteedFailure);
276 });
277 }
278 }
279 else
280 {
281 auto s = GetSharedFromThis ();
282 RequestDestination (ident,
283 [s, msg, nonce](std::shared_ptr<i2p::data::LeaseSet> ls)
284 {
285 if (ls)
286 {
287 bool sent = s->SendMsg (msg, ls);
288 if (s->m_Owner)
289 s->m_Owner->SendMessageStatusMessage (nonce, sent ? eI2CPMessageStatusGuaranteedSuccess : eI2CPMessageStatusGuaranteedFailure);
290 }
291 else if (s->m_Owner)
292 s->m_Owner->SendMessageStatusMessage (nonce, eI2CPMessageStatusNoLeaseSet);
293 });
294 }
295 }
296
297 bool I2CPDestination::SendMsg (std::shared_ptr<I2NPMessage> msg, std::shared_ptr<const i2p::data::LeaseSet> remote)
298 {

Callers 1

Calls 6

htobe32bufFunction · 0.85
AcquireSharedMtMethod · 0.80
FillI2NPMessageHeaderMethod · 0.80
GetPayloadMethod · 0.45
SendMsgMethod · 0.45

Tested by

no test coverage detected