|
|
@ -4,6 +4,7 @@ |
|
|
|
#include <inttypes.h> |
|
|
|
#include <inttypes.h> |
|
|
|
#include <sstream> |
|
|
|
#include <sstream> |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
#include <memory> |
|
|
|
#include "aes.h" |
|
|
|
#include "aes.h" |
|
|
|
#include "RouterInfo.h" |
|
|
|
#include "RouterInfo.h" |
|
|
|
#include "RouterContext.h" |
|
|
|
#include "RouterContext.h" |
|
|
@ -14,7 +15,7 @@ namespace tunnel |
|
|
|
{ |
|
|
|
{ |
|
|
|
struct TunnelHopConfig |
|
|
|
struct TunnelHopConfig |
|
|
|
{ |
|
|
|
{ |
|
|
|
const i2p::data::RouterInfo * router, * nextRouter; |
|
|
|
std::shared_ptr<const i2p::data::RouterInfo> router, nextRouter; |
|
|
|
uint32_t tunnelID, nextTunnelID; |
|
|
|
uint32_t tunnelID, nextTunnelID; |
|
|
|
uint8_t layerKey[32]; |
|
|
|
uint8_t layerKey[32]; |
|
|
|
uint8_t ivKey[32]; |
|
|
|
uint8_t ivKey[32]; |
|
|
@ -26,7 +27,7 @@ namespace tunnel |
|
|
|
i2p::crypto::TunnelDecryption decryption; |
|
|
|
i2p::crypto::TunnelDecryption decryption; |
|
|
|
int recordIndex; // record # in tunnel build message
|
|
|
|
int recordIndex; // record # in tunnel build message
|
|
|
|
|
|
|
|
|
|
|
|
TunnelHopConfig (const i2p::data::RouterInfo * r) |
|
|
|
TunnelHopConfig (std::shared_ptr<const i2p::data::RouterInfo> r) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); |
|
|
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); |
|
|
|
rnd.GenerateBlock (layerKey, 32); |
|
|
|
rnd.GenerateBlock (layerKey, 32); |
|
|
@ -36,14 +37,14 @@ namespace tunnel |
|
|
|
isGateway = true; |
|
|
|
isGateway = true; |
|
|
|
isEndpoint = true; |
|
|
|
isEndpoint = true; |
|
|
|
router = r; |
|
|
|
router = r; |
|
|
|
nextRouter = 0; |
|
|
|
//nextRouter = nullptr;
|
|
|
|
nextTunnelID = 0; |
|
|
|
nextTunnelID = 0; |
|
|
|
|
|
|
|
|
|
|
|
next = 0; |
|
|
|
next = nullptr; |
|
|
|
prev = 0; |
|
|
|
prev = nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SetNextRouter (const i2p::data::RouterInfo * r) |
|
|
|
void SetNextRouter (std::shared_ptr<const i2p::data::RouterInfo> r) |
|
|
|
{ |
|
|
|
{ |
|
|
|
nextRouter = r; |
|
|
|
nextRouter = r; |
|
|
|
isEndpoint = false; |
|
|
|
isEndpoint = false; |
|
|
@ -88,7 +89,7 @@ namespace tunnel |
|
|
|
public: |
|
|
|
public: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TunnelConfig (std::vector<const i2p::data::RouterInfo *> peers, |
|
|
|
TunnelConfig (std::vector<std::shared_ptr<const i2p::data::RouterInfo> > peers, |
|
|
|
const TunnelConfig * replyTunnelConfig = nullptr) // replyTunnelConfig=nullptr means inbound
|
|
|
|
const TunnelConfig * replyTunnelConfig = nullptr) // replyTunnelConfig=nullptr means inbound
|
|
|
|
{ |
|
|
|
{ |
|
|
|
TunnelHopConfig * prev = nullptr; |
|
|
|
TunnelHopConfig * prev = nullptr; |
|
|
@ -109,7 +110,7 @@ namespace tunnel |
|
|
|
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ()); |
|
|
|
m_LastHop->SetReplyHop (replyTunnelConfig->GetFirstHop ()); |
|
|
|
} |
|
|
|
} |
|
|
|
else // inbound
|
|
|
|
else // inbound
|
|
|
|
m_LastHop->SetNextRouter (&i2p::context.GetRouterInfo ()); |
|
|
|
m_LastHop->SetNextRouter (i2p::context.GetSharedRouterInfo ()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
~TunnelConfig () |
|
|
|
~TunnelConfig () |
|
|
@ -184,7 +185,7 @@ namespace tunnel |
|
|
|
if (hop->isGateway) // inbound tunnel
|
|
|
|
if (hop->isGateway) // inbound tunnel
|
|
|
|
newHop->SetReplyHop (m_FirstHop); // use it as reply tunnel
|
|
|
|
newHop->SetReplyHop (m_FirstHop); // use it as reply tunnel
|
|
|
|
else |
|
|
|
else |
|
|
|
newHop->SetNextRouter (&i2p::context.GetRouterInfo ()); |
|
|
|
newHop->SetNextRouter (i2p::context.GetSharedRouterInfo ()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!hop->next) newConfig->m_FirstHop = newHop; // last hop
|
|
|
|
if (!hop->next) newConfig->m_FirstHop = newHop; // last hop
|
|
|
|
|
|
|
|
|
|
|
@ -195,7 +196,7 @@ namespace tunnel |
|
|
|
|
|
|
|
|
|
|
|
TunnelConfig * Clone (const TunnelConfig * replyTunnelConfig = nullptr) const |
|
|
|
TunnelConfig * Clone (const TunnelConfig * replyTunnelConfig = nullptr) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::vector<const i2p::data::RouterInfo *> peers; |
|
|
|
std::vector<std::shared_ptr<const i2p::data::RouterInfo> > peers; |
|
|
|
TunnelHopConfig * hop = m_FirstHop; |
|
|
|
TunnelHopConfig * hop = m_FirstHop; |
|
|
|
while (hop) |
|
|
|
while (hop) |
|
|
|
{ |
|
|
|
{ |
|
|
|