Merge pull request #3 from orignal/master

update
This commit is contained in:
mikhail4021 2014-01-21 01:34:51 -08:00
commit ca288fb3ef
6 changed files with 64 additions and 25 deletions

View file

@ -1,5 +1,5 @@
#include <string.h> #include <string.h>
#include <I2PEndian.h> #include "I2PEndian.h"
#include <cryptopp/sha.h> #include <cryptopp/sha.h>
#include <cryptopp/modes.h> #include <cryptopp/modes.h>
#include <cryptopp/aes.h> #include <cryptopp/aes.h>

View file

@ -1,5 +1,6 @@
#include "I2PEndian.h" #include "I2PEndian.h"
#include <fstream> #include <fstream>
#include <vector>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <cryptopp/gzip.h> #include <cryptopp/gzip.h>
#include "base64.h" #include "base64.h"
@ -313,6 +314,7 @@ namespace data
{ {
i2p::tunnel::OutboundTunnel * outbound = dest->GetLastOutboundTunnel (); i2p::tunnel::OutboundTunnel * outbound = dest->GetLastOutboundTunnel ();
const i2p::tunnel::InboundTunnel * inbound = dest->GetLastReplyTunnel (); const i2p::tunnel::InboundTunnel * inbound = dest->GetLastReplyTunnel ();
std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
for (int i = 0; i < num; i++) for (int i = 0; i < num; i++)
{ {
@ -332,7 +334,11 @@ namespace data
RequestedDestination * d1 = CreateRequestedDestination (router, false, false); RequestedDestination * d1 = CreateRequestedDestination (router, false, false);
d1->SetLastOutboundTunnel (outbound); d1->SetLastOutboundTunnel (outbound);
auto msg = d1->CreateRequestMessage (dest->GetLastRouter (), dest->GetLastReplyTunnel ()); 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 else
@ -351,7 +357,11 @@ namespace data
{ {
// request destination // request destination
auto msg = dest->CreateRequestMessage (r, dest->GetLastReplyTunnel ()); 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 else
@ -361,15 +371,18 @@ namespace data
RequestedDestination * d2 = CreateRequestedDestination (router, false, false); RequestedDestination * d2 = CreateRequestedDestination (router, false, false);
d2->SetLastOutboundTunnel (outbound); d2->SetLastOutboundTunnel (outbound);
I2NPMessage * msg = d2->CreateRequestMessage (dest->GetLastRouter (), inbound); I2NPMessage * msg = d2->CreateRequestMessage (dest->GetLastRouter (), inbound);
outbound->GetTunnelGateway ().PutTunnelDataMsg ( msgs.push_back (i2p::tunnel::TunnelMessageBlock
dest->GetLastRouter ()->GetIdentHash (), 0, msg); {
i2p::tunnel::eDeliveryTypeRouter,
dest->GetLastRouter ()->GetIdentHash (), 0, msg
});
} }
} }
} }
} }
if (outbound) if (msgs.size () > 0)
outbound->GetTunnelGateway ().SendBuffer (); outbound->SendTunnelDataMsg (msgs);
} }
else else
{ {
@ -399,11 +412,20 @@ namespace data
RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true); RequestedDestination * dest = CreateRequestedDestination (IdentHash (randomHash), false, true);
dest->SetLastOutboundTunnel (outbound); dest->SetLastOutboundTunnel (outbound);
outbound->GetTunnelGateway ().PutTunnelDataMsg (floodfill->GetIdentHash (), 0, std::vector<i2p::tunnel::TunnelMessageBlock> msgs;
CreateDatabaseStoreMsg ()); // tell floodfill about us msgs.push_back (i2p::tunnel::TunnelMessageBlock
outbound->GetTunnelGateway ().PutTunnelDataMsg (floodfill->GetIdentHash (), 0, {
dest->CreateRequestMessage (floodfill, inbound)); // explore i2p::tunnel::eDeliveryTypeRouter,
outbound->GetTunnelGateway ().SendBuffer (); 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);
} }
} }
} }

View file

@ -139,12 +139,28 @@ namespace tunnel
m_Gateway.SendTunnelDataMsg (gwHash, gwTunnel, msg); m_Gateway.SendTunnelDataMsg (gwHash, gwTunnel, msg);
} }
void OutboundTunnel::SendTunnelDataMsg (i2p::I2NPMessage * msg) void OutboundTunnel::SendTunnelDataMsg (std::vector<TunnelMessageBlock> 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;
Tunnels::Tunnels (): m_IsRunning (false), m_IsTunnelCreated (false), Tunnels::Tunnels (): m_IsRunning (false), m_IsTunnelCreated (false),

View file

@ -4,6 +4,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <map> #include <map>
#include <list> #include <list>
#include <vector>
#include <string> #include <string>
#include <thread> #include <thread>
#include <cryptopp/modes.h> #include <cryptopp/modes.h>
@ -64,10 +65,9 @@ namespace tunnel
OutboundTunnel (TunnelConfig * config): Tunnel (config), m_Gateway (this) {}; 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 (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg);
void SendTunnelDataMsg (std::vector<TunnelMessageBlock> msgs); // multiple messages
TunnelGateway& GetTunnelGateway () { return m_Gateway; };
size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); }; size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); };
// implements TunnelBase // implements TunnelBase

View file

@ -4,6 +4,7 @@
#include <inttypes.h> #include <inttypes.h>
#include "Timestamp.h" #include "Timestamp.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Identity.h"
namespace i2p namespace i2p
{ {
@ -22,8 +23,8 @@ namespace tunnel
struct TunnelMessageBlock struct TunnelMessageBlock
{ {
TunnelDeliveryType deliveryType; TunnelDeliveryType deliveryType;
i2p::data::IdentHash hash;
uint32_t tunnelID; uint32_t tunnelID;
uint8_t hash[32];
I2NPMessage * data; I2NPMessage * data;
}; };

View file

@ -41,12 +41,12 @@ namespace tunnel
LogPrint ("Delivery type tunnel"); LogPrint ("Delivery type tunnel");
m.tunnelID = be32toh (*(uint32_t *)fragment); m.tunnelID = be32toh (*(uint32_t *)fragment);
fragment += 4; // tunnelID fragment += 4; // tunnelID
memcpy (m.hash, fragment, 32); m.hash = i2p::data::IdentHash (fragment);
fragment += 32; // hash fragment += 32; // hash
break; break;
case eDeliveryTypeRouter: // 2 case eDeliveryTypeRouter: // 2
LogPrint ("Delivery type router"); LogPrint ("Delivery type router");
memcpy (m.hash, fragment, 32); m.hash = i2p::data::IdentHash (fragment);
fragment += 32; // to hash fragment += 32; // to hash
break; break;
default: default: