From 91199a905358b62de147d5ddffca6e637d9e319f Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 20 Jan 2014 09:36:20 -0500 Subject: [PATCH 1/3] fixed compilation error --- I2NPProtocol.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 48e31986..502a2e40 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -1,5 +1,5 @@ #include -#include +#include "I2PEndian.h" #include #include #include From 30ecf1ef8ce2022604e010a5400496c8f637a039 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 20 Jan 2014 18:37:51 -0500 Subject: [PATCH 2/3] send multiple messages --- Tunnel.cpp | 26 +++++++++++++++++++++----- Tunnel.h | 5 +++-- TunnelBase.h | 3 ++- TunnelEndpoint.cpp | 4 ++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Tunnel.cpp b/Tunnel.cpp index c5f9730f..f92337f7 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -138,13 +138,29 @@ namespace tunnel { m_Gateway.SendTunnelDataMsg (gwHash, gwTunnel, msg); } - - void OutboundTunnel::SendTunnelDataMsg (i2p::I2NPMessage * msg) + + void OutboundTunnel::SendTunnelDataMsg (std::vector msgs) { - SendTunnelDataMsg (nullptr, 0, msg); + for (auto& it : msgs) + { + switch (it.deliveryType) + { + case eDeliveryTypeLocal: + m_Gateway.SendTunnelDataMsg (nullptr, 0, it.data); + break; + case eDeliveryTypeTunnel: + m_Gateway.SendTunnelDataMsg (it.hash, it.tunnelID, it.data); + break; + case eDeliveryTypeRouter: + m_Gateway.SendTunnelDataMsg (it.hash, 0, it.data); + break; + default: + LogPrint ("Unexpected delivery type ", (int)it.deliveryType); + } + } + m_Gateway.SendBuffer (); } - - + Tunnels tunnels; Tunnels::Tunnels (): m_IsRunning (false), m_IsTunnelCreated (false), diff --git a/Tunnel.h b/Tunnel.h index 3f94d787..6c4b7d30 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -64,9 +65,9 @@ namespace tunnel OutboundTunnel (TunnelConfig * config): Tunnel (config), m_Gateway (this) {}; - void SendTunnelDataMsg (i2p::I2NPMessage * msg); //local void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg); - + void SendTunnelDataMsg (std::vector msgs); // multiple messages + TunnelGateway& GetTunnelGateway () { return m_Gateway; }; size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); }; diff --git a/TunnelBase.h b/TunnelBase.h index 49be29de..f59d995f 100644 --- a/TunnelBase.h +++ b/TunnelBase.h @@ -4,6 +4,7 @@ #include #include "Timestamp.h" #include "I2NPProtocol.h" +#include "Identity.h" namespace i2p { @@ -23,7 +24,7 @@ namespace tunnel { TunnelDeliveryType deliveryType; uint32_t tunnelID; - uint8_t hash[32]; + i2p::data::IdentHash hash; I2NPMessage * data; }; diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 45aa4373..0e23a837 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -41,12 +41,12 @@ namespace tunnel LogPrint ("Delivery type tunnel"); m.tunnelID = be32toh (*(uint32_t *)fragment); fragment += 4; // tunnelID - memcpy (m.hash, fragment, 32); + m.hash = i2p::data::IdentHash (fragment); fragment += 32; // hash break; case eDeliveryTypeRouter: // 2 LogPrint ("Delivery type router"); - memcpy (m.hash, fragment, 32); + m.hash = i2p::data::IdentHash (fragment); fragment += 32; // to hash break; default: From 0b079f472365f3c7ddd8bbd5e928d18a1759cdff Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 20 Jan 2014 19:12:59 -0500 Subject: [PATCH 3/3] send multiple messages --- NetDb.cpp | 48 +++++++++++++++++++++++++++++++++++------------- Tunnel.h | 1 - TunnelBase.h | 2 +- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index cf1d6382..9b454598 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -1,5 +1,6 @@ #include "I2PEndian.h" #include +#include #include #include #include "base64.h" @@ -313,7 +314,8 @@ namespace data { i2p::tunnel::OutboundTunnel * outbound = dest->GetLastOutboundTunnel (); const i2p::tunnel::InboundTunnel * inbound = dest->GetLastReplyTunnel (); - + std::vector msgs; + for (int i = 0; i < num; i++) { uint8_t * router = buf + 33 + i*32; @@ -332,7 +334,11 @@ namespace data RequestedDestination * d1 = CreateRequestedDestination (router, false, false); d1->SetLastOutboundTunnel (outbound); auto msg = d1->CreateRequestMessage (dest->GetLastRouter (), dest->GetLastReplyTunnel ()); - outbound->GetTunnelGateway ().PutTunnelDataMsg (dest->GetLastRouter ()->GetIdentHash (), 0, msg); + msgs.push_back (i2p::tunnel::TunnelMessageBlock + { + i2p::tunnel::eDeliveryTypeRouter, + dest->GetLastRouter ()->GetIdentHash (), 0, msg + }); } } else @@ -351,7 +357,11 @@ namespace data { // request destination auto msg = dest->CreateRequestMessage (r, dest->GetLastReplyTunnel ()); - outbound->GetTunnelGateway ().PutTunnelDataMsg (r->GetIdentHash (), 0, msg); + msgs.push_back (i2p::tunnel::TunnelMessageBlock + { + i2p::tunnel::eDeliveryTypeRouter, + r->GetIdentHash (), 0, msg + }); } } else @@ -361,15 +371,18 @@ namespace data RequestedDestination * d2 = CreateRequestedDestination (router, false, false); d2->SetLastOutboundTunnel (outbound); I2NPMessage * msg = d2->CreateRequestMessage (dest->GetLastRouter (), inbound); - outbound->GetTunnelGateway ().PutTunnelDataMsg ( - dest->GetLastRouter ()->GetIdentHash (), 0, msg); + msgs.push_back (i2p::tunnel::TunnelMessageBlock + { + i2p::tunnel::eDeliveryTypeRouter, + dest->GetLastRouter ()->GetIdentHash (), 0, msg + }); } } } } - if (outbound) - outbound->GetTunnelGateway ().SendBuffer (); + if (msgs.size () > 0) + outbound->SendTunnelDataMsg (msgs); } else { @@ -398,12 +411,21 @@ namespace data rnd.GenerateBlock (randomHash, 32); RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true); dest->SetLastOutboundTunnel (outbound); - - outbound->GetTunnelGateway ().PutTunnelDataMsg (floodfill->GetIdentHash (), 0, - CreateDatabaseStoreMsg ()); // tell floodfill about us - outbound->GetTunnelGateway ().PutTunnelDataMsg (floodfill->GetIdentHash (), 0, - dest->CreateRequestMessage (floodfill, inbound)); // explore - outbound->GetTunnelGateway ().SendBuffer (); + + std::vector msgs; + msgs.push_back (i2p::tunnel::TunnelMessageBlock + { + i2p::tunnel::eDeliveryTypeRouter, + floodfill->GetIdentHash (), 0, + CreateDatabaseStoreMsg () // tell floodfill about us + }); + msgs.push_back (i2p::tunnel::TunnelMessageBlock + { + i2p::tunnel::eDeliveryTypeRouter, + floodfill->GetIdentHash (), 0, + dest->CreateRequestMessage (floodfill, inbound) // explore + }); + outbound->SendTunnelDataMsg (msgs); } } } diff --git a/Tunnel.h b/Tunnel.h index 6c4b7d30..a189da0d 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -68,7 +68,6 @@ namespace tunnel void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg); void SendTunnelDataMsg (std::vector msgs); // multiple messages - TunnelGateway& GetTunnelGateway () { return m_Gateway; }; size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); }; // implements TunnelBase diff --git a/TunnelBase.h b/TunnelBase.h index f59d995f..6be902ca 100644 --- a/TunnelBase.h +++ b/TunnelBase.h @@ -23,8 +23,8 @@ namespace tunnel struct TunnelMessageBlock { TunnelDeliveryType deliveryType; - uint32_t tunnelID; i2p::data::IdentHash hash; + uint32_t tunnelID; I2NPMessage * data; };