From 6df2efdac9800499cf43b190f31b3fa728d9d43b Mon Sep 17 00:00:00 2001 From: anonimal Date: Thu, 14 Jan 2016 15:18:24 +0000 Subject: [PATCH] Fix I2NP header default expiration time. * Correct NTCP/SSU priority costs * Style refactor - If function args newline break, ensure that *every* indent is 4 spaces and not 2. - enumerations: e -> e_ --- src/api/Datagram.cpp | 2 +- src/api/Streaming.cpp | 2 +- src/api/Streaming.h | 4 +- src/client/Destination.cpp | 26 +++--- src/client/Destination.h | 3 +- src/core/Garlic.cpp | 2 +- src/core/I2NPProtocol.cpp | 144 +++++++++++++++--------------- src/core/I2NPProtocol.h | 28 +++--- src/core/NetworkDatabase.cpp | 8 +- src/core/RouterInfo.cpp | 4 +- src/core/transport/SSUData.cpp | 4 +- src/core/tunnel/TransitTunnel.cpp | 2 +- src/core/tunnel/Tunnel.cpp | 20 ++--- src/core/tunnel/TunnelGateway.cpp | 2 +- 14 files changed, 128 insertions(+), 123 deletions(-) diff --git a/src/api/Datagram.cpp b/src/api/Datagram.cpp index 580c545b..dcdb28a9 100644 --- a/src/api/Datagram.cpp +++ b/src/api/Datagram.cpp @@ -192,7 +192,7 @@ I2NPMessage* DatagramDestination::CreateDataMessage( htobe16buf(buf + 6, toPort); // destination port buf[9] = i2p::client::PROTOCOL_TYPE_DATAGRAM; // datagram protocol msg->len += size + 4; - msg->FillI2NPMessageHeader(eI2NPData); + msg->FillI2NPMessageHeader(e_I2NPData); return msg; } diff --git a/src/api/Streaming.cpp b/src/api/Streaming.cpp index 089095ee..bc5150fd 100644 --- a/src/api/Streaming.cpp +++ b/src/api/Streaming.cpp @@ -838,7 +838,7 @@ std::shared_ptr Stream::CreateDataMessage( // streaming protocol buf[9] = i2p::client::PROTOCOL_TYPE_STREAMING; msg->len += size + 4; - msg->FillI2NPMessageHeader(eI2NPData); + msg->FillI2NPMessageHeader(e_I2NPData); return msg; } diff --git a/src/api/Streaming.h b/src/api/Streaming.h index 5b8fcea1..3ba37126 100644 --- a/src/api/Streaming.h +++ b/src/api/Streaming.h @@ -346,8 +346,8 @@ class StreamingDestination { StreamingDestination( i2p::client::ClientDestination& owner, uint16_t localPort = 0) - : m_Owner(owner), - m_LocalPort(localPort) {} + : m_Owner(owner), + m_LocalPort(localPort) {} ~StreamingDestination() {} void Start(); diff --git a/src/client/Destination.cpp b/src/client/Destination.cpp index 0604a085..e4461f6b 100644 --- a/src/client/Destination.cpp +++ b/src/client/Destination.cpp @@ -66,10 +66,10 @@ ClientDestination::ClientDestination( i2p::context.GetRandomNumberGenerator(), m_EncryptionPrivateKey, m_EncryptionPublicKey); - int inboundTunnelLen = DEFAULT_INBOUND_TUNNEL_LENGTH; - int outboundTunnelLen = DEFAULT_OUTBOUND_TUNNEL_LENGTH; - int inboundTunnelsQuantity = DEFAULT_INBOUND_TUNNELS_QUANTITY; - int outboundTunnelsQuantity = DEFAULT_OUTBOUND_TUNNELS_QUANTITY; + int inboundTunnelLen = DEFAULT_INBOUND_TUNNEL_LENGTH, + outboundTunnelLen = DEFAULT_OUTBOUND_TUNNEL_LENGTH, + inboundTunnelsQuantity = DEFAULT_INBOUND_TUNNELS_QUANTITY, + outboundTunnelsQuantity = DEFAULT_OUTBOUND_TUNNELS_QUANTITY; std::shared_ptr > explicitPeers; if (params) { auto it = params->find(I2CP_PARAM_INBOUND_TUNNEL_LENGTH); @@ -119,11 +119,11 @@ ClientDestination::ClientDestination( } m_Pool = i2p::tunnel::tunnels.CreateTunnelPool( - this, - inboundTunnelLen, - outboundTunnelLen, - inboundTunnelsQuantity, - outboundTunnelsQuantity); + this, + inboundTunnelLen, + outboundTunnelLen, + inboundTunnelsQuantity, + outboundTunnelsQuantity); if (explicitPeers) m_Pool->SetExplicitPeers(explicitPeers); if (m_IsPublic) @@ -275,13 +275,13 @@ void ClientDestination::HandleI2NPMessage( std::shared_ptr from) { uint8_t typeID = buf[I2NP_HEADER_TYPEID_OFFSET]; switch (typeID) { - case eI2NPData: + case e_I2NPData: HandleDataMessage( buf + I2NP_HEADER_SIZE, bufbe16toh( buf + I2NP_HEADER_SIZE_OFFSET)); break; - case eI2NPDeliveryStatus: + case e_I2NPDeliveryStatus: // we assume tunnel tests non-encrypted HandleDeliveryStatusMessage( CreateI2NPMessage( @@ -289,13 +289,13 @@ void ClientDestination::HandleI2NPMessage( GetI2NPMessageLength(buf), from)); break; - case eI2NPDatabaseStore: + case e_I2NPDatabaseStore: HandleDatabaseStoreMessage( buf + I2NP_HEADER_SIZE, bufbe16toh( buf + I2NP_HEADER_SIZE_OFFSET)); break; - case eI2NPDatabaseSearchReply: + case e_I2NPDatabaseSearchReply: HandleDatabaseSearchReplyMessage( buf + I2NP_HEADER_SIZE, bufbe16toh( diff --git a/src/client/Destination.h b/src/client/Destination.h index 469e98e4..e5a38cbb 100644 --- a/src/client/Destination.h +++ b/src/client/Destination.h @@ -174,7 +174,8 @@ class ClientDestination : public i2p::garlic::GarlicDestination { std::shared_ptr GetLeaseSet(); std::shared_ptr GetTunnelPool() const { - return m_Pool; } + return m_Pool; + } void HandleI2NPMessage( const uint8_t* buf, diff --git a/src/core/Garlic.cpp b/src/core/Garlic.cpp index 274cbf31..31fa8de8 100644 --- a/src/core/Garlic.cpp +++ b/src/core/Garlic.cpp @@ -191,7 +191,7 @@ std::shared_ptr GarlicRoutingSession::WrapSingleMessage( len += CreateAESBlock(buf, msg); htobe32buf(m->GetPayload(), len); m->len += len + 4; - m->FillI2NPMessageHeader(eI2NPGarlic); + m->FillI2NPMessageHeader(e_I2NPGarlic); return m; } diff --git a/src/core/I2NPProtocol.cpp b/src/core/I2NPProtocol.cpp index b07fda58..212ecf79 100644 --- a/src/core/I2NPProtocol.cpp +++ b/src/core/I2NPProtocol.cpp @@ -28,6 +28,8 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "I2NPProtocol.h" + #include #include @@ -37,7 +39,6 @@ #include #include "Garlic.h" -#include "I2NPProtocol.h" #include "NetworkDatabase.h" #include "RouterContext.h" #include "crypto/ElGamal.h" @@ -46,8 +47,6 @@ #include "util/I2PEndian.h" #include "util/Timestamp.h" -// TODO(anonimal): do not use namespace using-directives -using namespace i2p::transport; namespace i2p { I2NPMessage* NewI2NPMessage() { @@ -61,8 +60,8 @@ I2NPMessage* NewI2NPShortMessage() { I2NPMessage* NewI2NPMessage( size_t len) { return (len < I2NP_MAX_SHORT_MESSAGE_SIZE/2) ? - NewI2NPShortMessage() : - NewI2NPMessage(); + NewI2NPShortMessage() : + NewI2NPMessage(); } void DeleteI2NPMessage( @@ -83,15 +82,18 @@ void I2NPMessage::FillI2NPMessageHeader( SetMsgID(replyMsgID); else SetMsgID(i2p::context.GetRandomNumberGenerator().GenerateWord32()); - // TODO(unassigned): 5 secs is a magic number - SetExpiration(i2p::util::GetMillisecondsSinceEpoch() + 5000); + SetExpiration( + i2p::util::GetMillisecondsSinceEpoch() + + I2NP_HEADER_DEFAULT_EXPIRATION_TIME); UpdateSize(); UpdateChks(); } void I2NPMessage::RenewI2NPMessageHeader() { SetMsgID(i2p::context.GetRandomNumberGenerator().GenerateWord32()); - SetExpiration(i2p::util::GetMillisecondsSinceEpoch() + 5000); + SetExpiration( + i2p::util::GetMillisecondsSinceEpoch() + + I2NP_HEADER_DEFAULT_EXPIRATION_TIME); } I2NPMessage* CreateI2NPMessage( @@ -139,7 +141,7 @@ std::shared_ptr CreateDeliveryStatusMsg( htobe64buf(buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, 2); // netID = 2 } m->len += DELIVERY_STATUS_SIZE; - m->FillI2NPMessageHeader(eI2NPDeliveryStatus); + m->FillI2NPMessageHeader(e_I2NPDeliveryStatus); return ToSharedI2NPMessage(m); } @@ -180,7 +182,7 @@ std::shared_ptr CreateRouterInfoDatabaseLookupMsg( buf += 2; } m->len += (buf - m->GetPayload()); - m->FillI2NPMessageHeader(eI2NPDatabaseLookup); + m->FillI2NPMessageHeader(e_I2NPDatabaseLookup); return m; } @@ -218,7 +220,7 @@ std::shared_ptr CreateLeaseSetDatabaseLookupMsg( memcpy(buf + 33, replyTag, 32); buf += 65; m->len += (buf - m->GetPayload()); - m->FillI2NPMessageHeader(eI2NPDatabaseLookup); + m->FillI2NPMessageHeader(e_I2NPDatabaseLookup); return m; } @@ -239,7 +241,7 @@ std::shared_ptr CreateDatabaseSearchReply( memcpy(buf + len, i2p::context.GetRouterInfo().GetIdentHash(), 32); len += 32; m->len += len; - m->FillI2NPMessageHeader(eI2NPDatabaseSearchReply); + m->FillI2NPMessageHeader(e_I2NPDatabaseSearchReply); return m; } @@ -277,7 +279,7 @@ std::shared_ptr CreateDatabaseStoreMsg( } compressor.Get(buf, size); m->len += size; - m->FillI2NPMessageHeader(eI2NPDatabaseStore); + m->FillI2NPMessageHeader(e_I2NPDatabaseStore); return m; } @@ -306,7 +308,7 @@ std::shared_ptr CreateDatabaseStoreMsg( memcpy(payload + size, leaseSet->GetBuffer(), leaseSet->GetBufferLen()); size += leaseSet->GetBufferLen(); m->len += size; - m->FillI2NPMessageHeader(eI2NPDatabaseStore); + m->FillI2NPMessageHeader(e_I2NPDatabaseStore); return m; } @@ -317,9 +319,9 @@ bool HandleBuildRequestRecords( for (int i = 0; i < num; i++) { uint8_t * record = records + i*TUNNEL_BUILD_RECORD_SIZE; if (!memcmp( - record + BUILD_REQUEST_RECORD_TO_PEER_OFFSET, - (const uint8_t *)i2p::context.GetRouterInfo().GetIdentHash(), - 16)) { + record + BUILD_REQUEST_RECORD_TO_PEER_OFFSET, + (const uint8_t *)i2p::context.GetRouterInfo().GetIdentHash(), + 16)) { LogPrint("Record ", i, " is ours"); i2p::crypto::ElGamalDecrypt( i2p::context.GetEncryptionPrivateKey(), @@ -387,27 +389,27 @@ void HandleVariableTunnelBuildMsg( // we are endpoint of outboud tunnel if (clearText[BUILD_REQUEST_RECORD_FLAG_OFFSET] & 0x40) { // so we send it to reply tunnel - transports.SendMessage( + i2p::transport::transports.SendMessage( clearText + BUILD_REQUEST_RECORD_NEXT_IDENT_OFFSET, ToSharedI2NPMessage( - CreateTunnelGatewayMsg( - bufbe32toh( - clearText + BUILD_REQUEST_RECORD_NEXT_TUNNEL_OFFSET), - eI2NPVariableTunnelBuildReply, - buf, - len, - bufbe32toh( - clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET)))); + CreateTunnelGatewayMsg( + bufbe32toh( + clearText + BUILD_REQUEST_RECORD_NEXT_TUNNEL_OFFSET), + e_I2NPVariableTunnelBuildReply, + buf, + len, + bufbe32toh( + clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET)))); } else { - transports.SendMessage( + i2p::transport::transports.SendMessage( clearText + BUILD_REQUEST_RECORD_NEXT_IDENT_OFFSET, ToSharedI2NPMessage( - CreateI2NPMessage( - eI2NPVariableTunnelBuild, - buf, - len, - bufbe32toh( - clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET)))); + CreateI2NPMessage( + e_I2NPVariableTunnelBuild, + buf, + len, + bufbe32toh( + clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET)))); } } } @@ -421,27 +423,27 @@ void HandleTunnelBuildMsg( // we are endpoint of outbound tunnel if (clearText[BUILD_REQUEST_RECORD_FLAG_OFFSET] & 0x40) { // so we send it to reply tunnel - transports.SendMessage( + i2p::transport::transports.SendMessage( clearText + BUILD_REQUEST_RECORD_NEXT_IDENT_OFFSET, ToSharedI2NPMessage( - CreateTunnelGatewayMsg( - bufbe32toh( - clearText + BUILD_REQUEST_RECORD_NEXT_TUNNEL_OFFSET), - eI2NPTunnelBuildReply, - buf, - len, - bufbe32toh( - clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET)))); + CreateTunnelGatewayMsg( + bufbe32toh( + clearText + BUILD_REQUEST_RECORD_NEXT_TUNNEL_OFFSET), + e_I2NPTunnelBuildReply, + buf, + len, + bufbe32toh( + clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET)))); } else { - transports.SendMessage( + i2p::transport::transports.SendMessage( clearText + BUILD_REQUEST_RECORD_NEXT_IDENT_OFFSET, ToSharedI2NPMessage( - CreateI2NPMessage( - eI2NPTunnelBuild, - buf, - len, - bufbe32toh( - clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET)))); + CreateI2NPMessage( + e_I2NPTunnelBuild, + buf, + len, + bufbe32toh( + clearText + BUILD_REQUEST_RECORD_SEND_MSG_ID_OFFSET)))); } } } @@ -473,7 +475,7 @@ I2NPMessage* CreateTunnelDataMsg( I2NPMessage* msg = NewI2NPShortMessage(); memcpy(msg->GetPayload(), buf, i2p::tunnel::TUNNEL_DATA_MSG_SIZE); msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE; - msg->FillI2NPMessageHeader(eI2NPTunnelData); + msg->FillI2NPMessageHeader(e_I2NPTunnelData); return msg; } @@ -484,7 +486,7 @@ I2NPMessage* CreateTunnelDataMsg( memcpy(msg->GetPayload() + 4, payload, i2p::tunnel::TUNNEL_DATA_MSG_SIZE - 4); htobe32buf(msg->GetPayload(), tunnelID); msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE; - msg->FillI2NPMessageHeader(eI2NPTunnelData); + msg->FillI2NPMessageHeader(e_I2NPTunnelData); return msg; } @@ -504,7 +506,7 @@ I2NPMessage* CreateTunnelGatewayMsg( htobe16buf(payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len); memcpy(payload + TUNNEL_GATEWAY_HEADER_SIZE, buf, len); msg->len += TUNNEL_GATEWAY_HEADER_SIZE + len; - msg->FillI2NPMessageHeader(eI2NPTunnelGateway); + msg->FillI2NPMessageHeader(e_I2NPTunnelGateway); return msg; } @@ -519,7 +521,7 @@ std::shared_ptr CreateTunnelGatewayMsg( htobe16buf(payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len); msg->offset -= (I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE); msg->len = msg->offset + I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE +len; - msg->FillI2NPMessageHeader(eI2NPTunnelGateway); + msg->FillI2NPMessageHeader(e_I2NPTunnelGateway); return msg; } else { I2NPMessage* msg1 = CreateTunnelGatewayMsg( @@ -548,7 +550,7 @@ I2NPMessage* CreateTunnelGatewayMsg( uint8_t* payload = msg->GetPayload(); htobe32buf(payload + TUNNEL_GATEWAY_HEADER_TUNNELID_OFFSET, tunnelID); htobe16buf(payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET, len); - msg->FillI2NPMessageHeader(eI2NPTunnelGateway); // gateway message + msg->FillI2NPMessageHeader(e_I2NPTunnelGateway); // gateway message return msg; } @@ -568,19 +570,19 @@ void HandleI2NPMessage( uint8_t* buf = msg + I2NP_HEADER_SIZE; int size = bufbe16toh(msg + I2NP_HEADER_SIZE_OFFSET); switch (typeID) { - case eI2NPVariableTunnelBuild: + case e_I2NPVariableTunnelBuild: LogPrint("VariableTunnelBuild"); HandleVariableTunnelBuildMsg(msgID, buf, size); break; - case eI2NPVariableTunnelBuildReply: + case e_I2NPVariableTunnelBuildReply: LogPrint("VariableTunnelBuildReply"); HandleVariableTunnelBuildReplyMsg(msgID, buf, size); break; - case eI2NPTunnelBuild: + case e_I2NPTunnelBuild: LogPrint("TunnelBuild"); HandleTunnelBuildMsg(buf, size); break; - case eI2NPTunnelBuildReply: + case e_I2NPTunnelBuildReply: LogPrint("TunnelBuildReply"); // TODO(unassigned): ??? break; @@ -593,15 +595,15 @@ void HandleI2NPMessage( std::shared_ptr msg) { if (msg) { switch (msg->GetTypeID()) { - case eI2NPTunnelData: + case e_I2NPTunnelData: LogPrint("TunnelData"); i2p::tunnel::tunnels.PostTunnelData(msg); break; - case eI2NPTunnelGateway: + case e_I2NPTunnelGateway: LogPrint("TunnelGateway"); i2p::tunnel::tunnels.PostTunnelData(msg); break; - case eI2NPGarlic: { + case e_I2NPGarlic: { LogPrint("Garlic"); if (msg->from) { if (msg->from->GetTunnelPool()) @@ -614,13 +616,13 @@ void HandleI2NPMessage( } break; } - case eI2NPDatabaseStore: - case eI2NPDatabaseSearchReply: - case eI2NPDatabaseLookup: + case e_I2NPDatabaseStore: + case e_I2NPDatabaseSearchReply: + case e_I2NPDatabaseLookup: // forward to netDb i2p::data::netdb.PostI2NPMsg(msg); break; - case eI2NPDeliveryStatus: { + case e_I2NPDeliveryStatus: { LogPrint("DeliveryStatus"); if (msg->from && msg->from->GetTunnelPool()) msg->from->GetTunnelPool()->ProcessDeliveryStatus(msg); @@ -628,10 +630,10 @@ void HandleI2NPMessage( i2p::context.ProcessDeliveryStatusMessage(msg); break; } - case eI2NPVariableTunnelBuild: - case eI2NPVariableTunnelBuildReply: - case eI2NPTunnelBuild: - case eI2NPTunnelBuildReply: + case e_I2NPVariableTunnelBuild: + case e_I2NPVariableTunnelBuildReply: + case e_I2NPTunnelBuild: + case e_I2NPTunnelBuildReply: // forward to tunnel thread i2p::tunnel::tunnels.PostTunnelData(msg); break; @@ -649,10 +651,10 @@ void I2NPMessagesHandler::PutNextMessage( std::shared_ptr msg) { if (msg) { switch (msg->GetTypeID()) { - case eI2NPTunnelData: + case e_I2NPTunnelData: m_TunnelMsgs.push_back(msg); break; - case eI2NPTunnelGateway: + case e_I2NPTunnelGateway: m_TunnelGatewayMsgs.push_back(msg); break; default: diff --git a/src/core/I2NPProtocol.h b/src/core/I2NPProtocol.h index 14284146..918c14a0 100644 --- a/src/core/I2NPProtocol.h +++ b/src/core/I2NPProtocol.h @@ -103,21 +103,22 @@ const size_t BUILD_RESPONSE_RECORD_HASH_OFFSET = 0; const size_t BUILD_RESPONSE_RECORD_PADDING_OFFSET = 32; const size_t BUILD_RESPONSE_RECORD_PADDING_SIZE = 495; const size_t BUILD_RESPONSE_RECORD_RET_OFFSET = - BUILD_RESPONSE_RECORD_PADDING_OFFSET + BUILD_RESPONSE_RECORD_PADDING_SIZE; + BUILD_RESPONSE_RECORD_PADDING_OFFSET + + BUILD_RESPONSE_RECORD_PADDING_SIZE; enum I2NPMessageType { - eI2NPDatabaseStore = 1, - eI2NPDatabaseLookup = 2, - eI2NPDatabaseSearchReply = 3, - eI2NPDeliveryStatus = 10, - eI2NPGarlic = 11, - eI2NPTunnelData = 18, - eI2NPTunnelGateway = 19, - eI2NPData = 20, - eI2NPTunnelBuild = 21, - eI2NPTunnelBuildReply = 22, - eI2NPVariableTunnelBuild = 23, - eI2NPVariableTunnelBuildReply = 24 + e_I2NPDatabaseStore = 1, + e_I2NPDatabaseLookup = 2, + e_I2NPDatabaseSearchReply = 3, + e_I2NPDeliveryStatus = 10, + e_I2NPGarlic = 11, + e_I2NPTunnelData = 18, + e_I2NPTunnelGateway = 19, + e_I2NPData = 20, + e_I2NPTunnelBuild = 21, + e_I2NPTunnelBuildReply = 22, + e_I2NPVariableTunnelBuild = 23, + e_I2NPVariableTunnelBuildReply = 24 }; const int NUM_TUNNEL_BUILD_RECORDS = 8; @@ -140,6 +141,7 @@ class TunnelPool; const size_t I2NP_MAX_MESSAGE_SIZE = 32768; const size_t I2NP_MAX_SHORT_MESSAGE_SIZE = 4096; +const size_t I2NP_HEADER_DEFAULT_EXPIRATION_TIME = 1 * 60 * 1000; // 1 minute struct I2NPMessage { uint8_t* buf; size_t len, offset, maxLen; diff --git a/src/core/NetworkDatabase.cpp b/src/core/NetworkDatabase.cpp index 078b9a23..0b90b1eb 100644 --- a/src/core/NetworkDatabase.cpp +++ b/src/core/NetworkDatabase.cpp @@ -120,15 +120,15 @@ void NetDb::Run() { int numMsgs = 0; while (msg) { switch (msg->GetTypeID()) { - case eI2NPDatabaseStore: + case e_I2NPDatabaseStore: LogPrint("DatabaseStore"); HandleDatabaseStoreMsg(msg); break; - case eI2NPDatabaseSearchReply: + case e_I2NPDatabaseSearchReply: LogPrint("DatabaseSearchReply"); HandleDatabaseSearchReplyMsg(msg); break; - case eI2NPDatabaseLookup: + case e_I2NPDatabaseLookup: LogPrint("DatabaseLookup"); HandleDatabaseLookupMsg(msg); break; @@ -517,7 +517,7 @@ void NetDb::HandleDatabaseStoreMsg( htobe32buf(payload + DATABASE_STORE_REPLY_TOKEN_OFFSET, 0); memcpy(payload + DATABASE_STORE_HEADER_SIZE, buf + offset, len - offset); floodMsg->len += DATABASE_STORE_HEADER_SIZE + len -offset; - floodMsg->FillI2NPMessageHeader(eI2NPDatabaseStore); + floodMsg->FillI2NPMessageHeader(e_I2NPDatabaseStore); std::set excluded; for (int i = 0; i < 3; i++) { auto floodfill = GetClosestFloodfill(ident, excluded); diff --git a/src/core/RouterInfo.cpp b/src/core/RouterInfo.cpp index 7f1a8dab..6b6c644e 100644 --- a/src/core/RouterInfo.cpp +++ b/src/core/RouterInfo.cpp @@ -515,7 +515,7 @@ void RouterInfo::AddNTCPAddress( addr.host = boost::asio::ip::address::from_string(host); addr.port = port; addr.transportStyle = eTransportNTCP; - addr.cost = 2; + addr.cost = 10; // NTCP should have priority over SSU addr.date = 0; addr.mtu = 0; m_Addresses.push_back(addr); @@ -531,7 +531,7 @@ void RouterInfo::AddSSUAddress( addr.host = boost::asio::ip::address::from_string(host); addr.port = port; addr.transportStyle = eTransportSSU; - addr.cost = 10; // NTCP should have priority over SSU + addr.cost = 5; addr.date = 0; addr.mtu = mtu; memcpy(addr.key, key, 32); diff --git a/src/core/transport/SSUData.cpp b/src/core/transport/SSUData.cpp index 56ce2fea..a5e0cc5e 100644 --- a/src/core/transport/SSUData.cpp +++ b/src/core/transport/SSUData.cpp @@ -271,10 +271,10 @@ void SSUData::ProcessFragments( } else { auto i2np_type = msg->GetTypeID(); // we expect DeliveryStatus - if (i2np_type == eI2NPDeliveryStatus) { + if (i2np_type == e_I2NPDeliveryStatus) { LogPrint("SSU session established"); m_Session.Established(); - } else if (i2np_type == eI2NPDatabaseStore) { + } else if (i2np_type == e_I2NPDatabaseStore) { // we got a database store message LogPrint("Got DSM From SSU"); m_ReceivedMessages.insert(msgID); diff --git a/src/core/tunnel/TransitTunnel.cpp b/src/core/tunnel/TransitTunnel.cpp index bd525b95..b572deda 100644 --- a/src/core/tunnel/TransitTunnel.cpp +++ b/src/core/tunnel/TransitTunnel.cpp @@ -70,7 +70,7 @@ void TransitTunnelParticipant::HandleTunnelDataMsg( EncryptTunnelMsg(tunnelMsg, newMsg); m_NumTransmittedBytes += tunnelMsg->GetLength(); htobe32buf(newMsg->GetPayload(), GetNextTunnelID()); - newMsg->FillI2NPMessageHeader(eI2NPTunnelData); + newMsg->FillI2NPMessageHeader(e_I2NPTunnelData); m_TunnelDataMsgs.push_back(newMsg); } diff --git a/src/core/tunnel/Tunnel.cpp b/src/core/tunnel/Tunnel.cpp index 0e6632fd..0456b9f3 100644 --- a/src/core/tunnel/Tunnel.cpp +++ b/src/core/tunnel/Tunnel.cpp @@ -112,7 +112,7 @@ void Tunnel::Build( } hop = hop->prev; } - msg->FillI2NPMessageHeader(eI2NPVariableTunnelBuild); + msg->FillI2NPMessageHeader(e_I2NPVariableTunnelBuild); // send message if (outboundTunnel) outboundTunnel->SendTunnelDataMsg( @@ -409,19 +409,19 @@ void Tunnels::Run() { TunnelBase* tunnel = nullptr; uint8_t typeID = msg->GetTypeID(); switch (typeID) { - case eI2NPTunnelData: - case eI2NPTunnelGateway: { + case e_I2NPTunnelData: + case e_I2NPTunnelGateway: { tunnelID = bufbe32toh(msg->GetPayload()); if (tunnelID == prevTunnelID) tunnel = prevTunnel; else if (prevTunnel) prevTunnel->FlushTunnelDataMsgs(); - if (!tunnel && typeID == eI2NPTunnelData) + if (!tunnel && typeID == e_I2NPTunnelData) tunnel = GetInboundTunnel(tunnelID).get(); if (!tunnel) tunnel = GetTransitTunnel(tunnelID); if (tunnel) { - if (typeID == eI2NPTunnelData) + if (typeID == e_I2NPTunnelData) tunnel->HandleTunnelDataMsg(msg); else // tunnel gateway assumed HandleTunnelGatewayMsg(tunnel, msg); @@ -430,10 +430,10 @@ void Tunnels::Run() { } break; } - case eI2NPVariableTunnelBuild: - case eI2NPVariableTunnelBuildReply: - case eI2NPTunnelBuild: - case eI2NPTunnelBuildReply: + case e_I2NPVariableTunnelBuild: + case e_I2NPVariableTunnelBuildReply: + case e_I2NPTunnelBuild: + case e_I2NPTunnelBuildReply: HandleI2NPMessage(msg->GetBuffer(), msg->GetLength()); break; default: @@ -478,7 +478,7 @@ void Tunnels::HandleTunnelGatewayMsg( "TunnelGateway of ", static_cast(len), " bytes for tunnel ", tunnel->GetTunnelID(), ". Msg type ", static_cast(typeID)); - if (typeID == eI2NPDatabaseStore || typeID == eI2NPDatabaseSearchReply) + if (typeID == e_I2NPDatabaseStore || typeID == e_I2NPDatabaseSearchReply) // transit DatabaseStore my contain new/updated RI // or DatabaseSearchReply with new routers i2p::data::netdb.PostI2NPMsg(msg); diff --git a/src/core/tunnel/TunnelGateway.cpp b/src/core/tunnel/TunnelGateway.cpp index 2406f406..6b456e8e 100644 --- a/src/core/tunnel/TunnelGateway.cpp +++ b/src/core/tunnel/TunnelGateway.cpp @@ -237,7 +237,7 @@ void TunnelGateway::SendBuffer() { auto tunnelMsgs = m_Buffer.GetTunnelDataMsgs(); for (auto tunnelMsg : tunnelMsgs) { m_Tunnel->EncryptTunnelMsg(tunnelMsg, tunnelMsg); - tunnelMsg->FillI2NPMessageHeader(eI2NPTunnelData); + tunnelMsg->FillI2NPMessageHeader(e_I2NPTunnelData); m_NumSentBytes += TUNNEL_DATA_MSG_SIZE; } i2p::transport::transports.SendMessages(