Browse Source

save b33 addresses

pull/1334/head
orignal 6 years ago
parent
commit
3fd9d5f641
  1. 15
      libi2pd/LeaseSet.cpp
  2. 1
      libi2pd/LeaseSet.h
  3. 9
      libi2pd_client/AddressBook.cpp

15
libi2pd/LeaseSet.cpp

@ -299,6 +299,21 @@ namespace data @@ -299,6 +299,21 @@ namespace data
LogPrint (eLogError, "LeaseSet2: unknown signature type ", (int)m_SigType, " in b33");
}
std::string BlindedPublicKey::ToB33 () const
{
if (m_PublicKey.size () > 32) return ""; // assume 25519
uint8_t addr[35]; char str[60]; // TODO: define actual length
addr[0] = 0; // flags
addr[1] = m_SigType; // sig type
addr[2] = m_BlindedSigType; // blinded sig type
memcpy (addr + 3, m_PublicKey.data (), m_PublicKey.size ());
uint32_t checksum = crc32 (0, addr + 3, m_PublicKey.size ());
// checksum is Little Endian
addr[0] ^= checksum; addr[1] ^= (checksum >> 8); addr[2] ^= (checksum >> 16);
auto l = ByteStreamToBase32 (addr, m_PublicKey.size () + 3, str, 60);
return std::string (str, str + l);
}
LeaseSet2::LeaseSet2 (uint8_t storeType, const uint8_t * buf, size_t len, bool storeLeases):
LeaseSet (storeLeases), m_StoreType (storeType)
{

1
libi2pd/LeaseSet.h

@ -134,6 +134,7 @@ namespace data @@ -134,6 +134,7 @@ namespace data
BlindedPublicKey (std::shared_ptr<const IdentityEx> identity, SigningKeyType blindedKeyType = i2p::data::SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519);
BlindedPublicKey (const std::string& b33); // from b33 without .b32.i2p
std::string ToB33 () const;
const uint8_t * GetPublicKey () const { return m_PublicKey.data (); };
size_t GetPublicKeyLen () const { return m_PublicKey.size (); };

9
libi2pd_client/AddressBook.cpp

@ -190,13 +190,14 @@ namespace client @@ -190,13 +190,14 @@ namespace client
for (const auto& it: addresses)
{
f << it.first << ",";
if (it.second->IsIdentHash ())
{
f << it.first << "," << it.second->identHash.ToBase32 () << std::endl;
f << it.second->identHash.ToBase32 ();
else
f << it.second->blindedPublicKey->ToB33 ();
f << std::endl;
num++;
}
// TODO: save blinded public key
}
LogPrint (eLogInfo, "Addressbook: ", num, " addresses saved");
return num;
}

Loading…
Cancel
Save