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

Method HandleRelayIntro

libi2pd/SSU2Session.cpp:2255–2360  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2253 }
2254
2255 void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len, int attempts)
2256 {
2257 // we are Charlie
2258 if (len < 47) return;
2259 SSU2RelayResponseCode code = eSSU2RelayResponseCodeAccept;
2260 boost::asio::ip::udp::endpoint ep;
2261 std::shared_ptr<const i2p::data::RouterInfo::Address> addr;
2262 auto r = i2p::data::netdb.FindRouter (buf + 1); // Alice
2263 if (r)
2264 {
2265 SignedData<128> s;
2266 s.Insert ((const uint8_t *)"RelayRequestData", 16); // prologue
2267 s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
2268 s.Insert (i2p::context.GetIdentHash (), 32); // chash
2269 s.Insert (buf + 33, 14); // nonce, relay tag, timestamp, ver, asz
2270 uint8_t asz = buf[46];
2271 if (asz + 47 + r->GetIdentity ()->GetSignatureLen () > len)
2272 {
2273 LogPrint (eLogWarning, "SSU2: Malformed RelayIntro len=", len);
2274 return;
2275 }
2276 s.Insert (buf + 47, asz); // Alice Port, Alice IP
2277 if (s.Verify (r->GetIdentity (), buf + 47 + asz))
2278 {
2279 // obtain and check endpoint and address for HolePunch
2280 if (ExtractEndpoint (buf + 47, asz, ep))
2281 {
2282 if (!ep.address ().is_unspecified () && ep.port ())
2283 {
2284 if (m_Server.IsSupported (ep.address ()))
2285 {
2286 addr = ep.address ().is_v6 () ? r->GetSSU2V6Address () : r->GetSSU2V4Address ();
2287 if (!addr)
2288 {
2289 LogPrint (eLogWarning, "SSU2: RelayIntro address for endpoint not found");
2290 code = eSSU2RelayResponseCodeCharlieAliceIsUnknown;
2291 }
2292 }
2293 else
2294 {
2295 LogPrint (eLogWarning, "SSU2: RelayIntro unsupported address");
2296 code = eSSU2RelayResponseCodeCharlieUnsupportedAddress;
2297 }
2298 }
2299 else
2300 {
2301 LogPrint (eLogWarning, "SSU2: RelayIntro invalid endpoint");
2302 code = eSSU2RelayResponseCodeCharlieAliceIsUnknown;
2303 }
2304 }
2305 else
2306 {
2307 LogPrint (eLogWarning, "SSU2: RelayIntro can't extract endpoint");
2308 code = eSSU2RelayResponseCodeCharlieAliceIsUnknown;
2309 }
2310 }
2311 else
2312 {

Callers

nothing calls this directly

Calls 15

LogPrintFunction · 0.85
bufbe32tohFunction · 0.85
FindRouterMethod · 0.80
IsSupportedMethod · 0.80
GetSSU2V6AddressMethod · 0.80
GetSSU2V4AddressMethod · 0.80
AcquireSharedMethod · 0.80
GetIncomingTokenMethod · 0.80
SendHolePunchMethod · 0.80
InsertMethod · 0.45
GetSignatureLenMethod · 0.45

Tested by

no test coverage detected