| 473 | } |
| 474 | |
| 475 | void RouterContext::PublishSSU2Address (int port, bool publish, bool v4, bool v6, int version) |
| 476 | { |
| 477 | if (!m_SSU2Keys) return; |
| 478 | auto addresses = m_RouterInfo.GetAddresses (); |
| 479 | if (!addresses) return; |
| 480 | int newPort = 0; |
| 481 | if (!port) |
| 482 | { |
| 483 | for (const auto& address : *addresses) |
| 484 | if (address && address->port) |
| 485 | { |
| 486 | newPort = address->port; |
| 487 | break; |
| 488 | } |
| 489 | if (!newPort) newPort = SelectRandomPort (); |
| 490 | } |
| 491 | bool updated = false; |
| 492 | for (auto& address : *addresses) |
| 493 | { |
| 494 | if (address && address->IsSSU2 () && (!address->port || address->port != port || |
| 495 | address->published != publish || address->v != version) && |
| 496 | ((v4 && address->IsV4 ()) || (v6 && address->IsV6 ()))) |
| 497 | { |
| 498 | if (port) address->port = port; |
| 499 | else if (!address->port) address->port = newPort; |
| 500 | address->published = publish; |
| 501 | address->v = version; |
| 502 | if (publish) |
| 503 | { |
| 504 | UpdateSSU2AddressCapsTesting (address, true); |
| 505 | UpdateSSU2AddressCapsIntroducer (address, !m_IsFloodfill); |
| 506 | } |
| 507 | else |
| 508 | { |
| 509 | UpdateSSU2AddressCapsTesting (address, false); |
| 510 | UpdateSSU2AddressCapsIntroducer (address, false); |
| 511 | } |
| 512 | updated = true; |
| 513 | } |
| 514 | } |
| 515 | if (updated) |
| 516 | UpdateRouterInfo (); |
| 517 | } |
| 518 | |
| 519 | void RouterContext::UpdateSSU2AddressCapsIntroducer (std::shared_ptr<i2p::data::RouterInfo::Address> address, bool isIntroducer) const |
| 520 | { |
no test coverage detected