Browse Source

generic tag introduced

pull/81/head
orignal 11 years ago
parent
commit
13fec9bdfc
  1. 5
      Garlic.cpp
  2. 3
      Garlic.h
  3. 5
      Identity.cpp
  4. 68
      Identity.h
  5. 15
      SSU.h

5
Garlic.cpp

@ -297,8 +297,7 @@ namespace garlic
uint8_t * buf = msg->GetPayload (); uint8_t * buf = msg->GetPayload ();
uint32_t length = be32toh (*(uint32_t *)buf); uint32_t length = be32toh (*(uint32_t *)buf);
buf += 4; buf += 4;
std::string sessionTag((const char *)buf, 32); auto it = m_SessionTags.find (SessionTag(buf));
auto it = m_SessionTags.find (sessionTag);
if (it != m_SessionTags.end ()) if (it != m_SessionTags.end ())
{ {
// existing session // existing session
@ -340,7 +339,7 @@ namespace garlic
uint16_t tagCount = be16toh (*(uint16_t *)buf); uint16_t tagCount = be16toh (*(uint16_t *)buf);
buf += 2; buf += 2;
for (int i = 0; i < tagCount; i++) for (int i = 0; i < tagCount; i++)
m_SessionTags[std::string ((const char *)(buf + i*32), 32)] = decryption; m_SessionTags[SessionTag(buf + i*32)] = decryption;
buf += tagCount*32; buf += tagCount*32;
uint32_t payloadSize = be32toh (*(uint32_t *)buf); uint32_t payloadSize = be32toh (*(uint32_t *)buf);
if (payloadSize > len) if (payloadSize > len)

3
Garlic.h

@ -98,6 +98,7 @@ namespace garlic
private: private:
typedef i2p::data::Tag<32> SessionTag;
bool m_IsRunning; bool m_IsRunning;
std::thread * m_Thread; std::thread * m_Thread;
i2p::util::Queue<I2NPMessage> m_Queue; i2p::util::Queue<I2NPMessage> m_Queue;
@ -106,7 +107,7 @@ namespace garlic
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
// incoming session // incoming session
std::list<i2p::crypto::CBCDecryption *> m_SessionDecryptions; // multiple tags refer to one decyption std::list<i2p::crypto::CBCDecryption *> m_SessionDecryptions; // multiple tags refer to one decyption
std::map<std::string, i2p::crypto::CBCDecryption *> m_SessionTags; // tag -> decryption std::map<SessionTag, i2p::crypto::CBCDecryption *> m_SessionTags; // tag -> decryption
}; };
extern GarlicRouting routing; extern GarlicRouting routing;

5
Identity.cpp

@ -40,11 +40,6 @@ namespace data
return *this; return *this;
} }
bool IdentHash::FromBase32(const std::string& s)
{
size_t count = Base32ToByteStream(s.c_str(), s.length(), m_Hash, sizeof(m_Hash));
return count == sizeof(m_Hash);
}
Keys CreateRandomKeys () Keys CreateRandomKeys ()
{ {

68
Identity.h

@ -9,7 +9,41 @@ namespace i2p
{ {
namespace data namespace data
{ {
class IdentHash; template<int sz>
class Tag
{
public:
Tag (const uint8_t * buf) { memcpy (m_Buf, buf, sz); };
Tag (const Tag<sz>& ) = default;
#ifndef _WIN32 // FIXME!!! msvs 2013 can't compile it
Tag (Tag<sz>&& ) = default;
#endif
Tag () = default;
Tag<sz>& operator= (const Tag<sz>& ) = default;
#ifndef _WIN32
Tag<sz>& operator= (Tag<sz>&& ) = default;
#endif
uint8_t * operator()() { return m_Buf; };
const uint8_t * operator()() const { return m_Buf; };
operator uint8_t * () { return m_Buf; };
operator const uint8_t * () const { return m_Buf; };
bool operator== (const Tag<sz>& other) const { return !memcmp (m_Buf, other.m_Buf, sz); };
bool operator< (const Tag<sz>& other) const { return memcmp (m_Buf, other.m_Buf, sz) < 0; };
private:
union // 8 bytes alignment
{
uint8_t m_Buf[sz];
uint64_t ll[sz/8];
};
};
typedef Tag<32> IdentHash;
#pragma pack(1) #pragma pack(1)
@ -53,38 +87,6 @@ namespace data
#pragma pack() #pragma pack()
class IdentHash
{
public:
IdentHash (const uint8_t * hash) { memcpy (m_Hash, hash, 32); };
IdentHash (const IdentHash& ) = default;
#ifndef _WIN32 // FIXME!!! msvs 2013 can't compile it
IdentHash (IdentHash&& ) = default;
#endif
IdentHash () = default;
IdentHash& operator= (const IdentHash& ) = default;
#ifndef _WIN32
IdentHash& operator= (IdentHash&& ) = default;
#endif
uint8_t * operator()() { return m_Hash; };
const uint8_t * operator()() const { return m_Hash; };
operator uint8_t * () { return m_Hash; };
operator const uint8_t * () const { return m_Hash; };
bool operator== (const IdentHash& other) const { return !memcmp (m_Hash, other.m_Hash, 32); };
bool operator< (const IdentHash& other) const { return memcmp (m_Hash, other.m_Hash, 32) < 0; };
bool FromBase32(const std::string&);
private:
uint8_t m_Hash[32];
};
Keys CreateRandomKeys (); Keys CreateRandomKeys ();
void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions void CreateRandomDHKeysPair (DHKeysPair * keys); // for transport sessions

15
SSU.h

@ -114,20 +114,7 @@ namespace ssu
private: private:
union IV typedef i2p::data::Tag<16> IV;
{
uint8_t buf[16];
uint64_t ll[2];
IV (const IV&) = default;
IV (const uint8_t * iv) { memcpy (buf, iv, 16); };
bool operator< (const IV& other) const
{
if (ll[0] != other.ll[0]) return ll[0] < other.ll[0];
return ll[1] < other.ll[1];
};
};
friend class SSUData; // TODO: change in later friend class SSUData; // TODO: change in later
SSUServer& m_Server; SSUServer& m_Server;
boost::asio::ip::udp::endpoint m_RemoteEndpoint; boost::asio::ip::udp::endpoint m_RemoteEndpoint;

Loading…
Cancel
Save