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

Method HandleRequest

libi2pd_client/AddressBook.cpp:1104–1128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1102 }
1103
1104 void AddressResolver::HandleRequest (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len)
1105 {
1106 if (len < 9 || len < buf[8] + 9U)
1107 {
1108 LogPrint (eLogError, "Addressbook: Address request is too short ", len);
1109 return;
1110 }
1111 // read requested address
1112 uint8_t l = buf[8];
1113 char address[255];
1114 memcpy (address, buf + 9, l);
1115 address[l] = 0;
1116 LogPrint (eLogDebug, "Addressbook: Address request ", address);
1117 // send response
1118 uint8_t response[44];
1119 memset (response, 0, 4); // reserved
1120 memcpy (response + 4, buf + 4, 4); // nonce
1121 auto it = m_LocalAddresses.find (address); // address lookup
1122 if (it != m_LocalAddresses.end ())
1123 memcpy (response + 8, it->second, 32); // ident
1124 else
1125 memset (response + 8, 0, 32); // not found
1126 memset (response + 40, 0, 4); // set expiration time to zero
1127 m_LocalDestination->GetDatagramDestination ()->SendDatagramTo (response, 44, from.GetIdentHash(), toPort, fromPort);
1128 }
1129
1130 void AddressResolver::AddAddress (const std::string& name, const i2p::data::IdentHash& ident)
1131 {

Callers

nothing calls this directly

Calls 3

LogPrintFunction · 0.85
SendDatagramToMethod · 0.80

Tested by

no test coverage detected