| 31 | } |
| 32 | |
| 33 | void SSU2Server::Start () |
| 34 | { |
| 35 | if (!IsRunning ()) |
| 36 | { |
| 37 | StartIOService (); |
| 38 | i2p::config::GetOption ("ssu2.published", m_IsPublished); |
| 39 | i2p::config::GetOption("nettime.frompeers", m_IsSyncClockFromPeers); |
| 40 | bool found = false; |
| 41 | auto addresses = i2p::context.GetRouterInfo ().GetAddresses (); |
| 42 | if (!addresses) return; |
| 43 | for (const auto& address: *addresses) |
| 44 | { |
| 45 | if (!address) continue; |
| 46 | if (address->transportStyle == i2p::data::RouterInfo::eTransportSSU2) |
| 47 | { |
| 48 | if (m_IsThroughProxy) |
| 49 | { |
| 50 | found = true; |
| 51 | if (address->IsV6 ()) |
| 52 | { |
| 53 | uint16_t mtu; i2p::config::GetOption ("ssu2.mtu6", mtu); |
| 54 | if (!mtu || mtu > SSU2_MAX_PACKET_SIZE - SOCKS5_UDP_IPV6_REQUEST_HEADER_SIZE) |
| 55 | mtu = SSU2_MAX_PACKET_SIZE - SOCKS5_UDP_IPV6_REQUEST_HEADER_SIZE; |
| 56 | i2p::context.SetMTU (mtu, false); |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | uint16_t mtu; i2p::config::GetOption ("ssu2.mtu4", mtu); |
| 61 | if (!mtu || mtu > SSU2_MAX_PACKET_SIZE - SOCKS5_UDP_IPV4_REQUEST_HEADER_SIZE) |
| 62 | mtu = SSU2_MAX_PACKET_SIZE - SOCKS5_UDP_IPV4_REQUEST_HEADER_SIZE; |
| 63 | i2p::context.SetMTU (mtu, true); |
| 64 | } |
| 65 | continue; // we don't need port for proxy |
| 66 | } |
| 67 | auto port = address->port; |
| 68 | if (!port) |
| 69 | { |
| 70 | uint16_t ssu2Port; i2p::config::GetOption ("ssu2.port", ssu2Port); |
| 71 | if (ssu2Port) port = ssu2Port; |
| 72 | else |
| 73 | { |
| 74 | uint16_t p; i2p::config::GetOption ("port", p); |
| 75 | if (p) port = p; |
| 76 | } |
| 77 | } |
| 78 | if (port) |
| 79 | { |
| 80 | if (address->IsV4 ()) |
| 81 | { |
| 82 | found = true; |
| 83 | i2p::config::GetOption ("ssu2.firewalled4", m_IsForcedFirewalled4); |
| 84 | LogPrint (eLogDebug, "SSU2: Opening IPv4 socket at Start"); |
| 85 | OpenSocket (boost::asio::ip::udp::endpoint (m_AddressV4, port)); |
| 86 | boost::asio::post (m_ReceiveService.GetService (), |
| 87 | [this]() |
| 88 | { |
| 89 | Receive (m_SocketV4); |
| 90 | }); |