-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds an abstraction for a data store. LMDB is included as an implementation. A block store is built on the data store abstraction. Blocks are chunks data addressed by a CID (content identifier).
- Loading branch information
Showing
28 changed files
with
1,667 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Team Kodi | ||
* This file is part of Kodi - https://kodi.tv | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* See LICENSES/README.md for more information. | ||
*/ | ||
|
||
#include "Block.h" | ||
|
||
using namespace KODI; | ||
using namespace DATASTORE; | ||
|
||
CBlock::CBlock(CCID cid, std::vector<uint8_t> data) : m_cid(std::move(cid)), m_data(std::move(data)) | ||
{ | ||
} | ||
|
||
std::vector<uint8_t> CBlock::Serialize() const | ||
{ | ||
std::vector<uint8_t> data; | ||
|
||
//! @todo | ||
|
||
return data; | ||
} | ||
|
||
void CBlock::Deserialize(const std::vector<uint8_t>& data) | ||
{ | ||
//! @todo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Team Kodi | ||
* This file is part of Kodi - https://kodi.tv | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* See LICENSES/README.md for more information. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "CID.h" | ||
|
||
#include <stdint.h> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace KODI | ||
{ | ||
namespace DATASTORE | ||
{ | ||
/*! | ||
* \brief Container of raw data with a CID identifier | ||
*/ | ||
class CBlock | ||
{ | ||
public: | ||
/*! | ||
* \brief Construct an empty block | ||
*/ | ||
CBlock() = default; | ||
|
||
/*! | ||
* \brief Construct a block from parameters | ||
* | ||
* \param cid The block CID | ||
* \param data The block data | ||
*/ | ||
CBlock(CCID cid, std::vector<uint8_t> data); | ||
|
||
/*! | ||
* \brief Get the CID | ||
*/ | ||
const CCID& CID() const { return m_cid; } | ||
|
||
/*! | ||
* \brief Set the CID | ||
*/ | ||
void SetCID(CCID cid) { m_cid = std::move(cid); } | ||
|
||
/*! | ||
* \brief Get the data (const) | ||
*/ | ||
const std::vector<uint8_t>& Data() const { return m_data; } | ||
|
||
/*! | ||
* \brief Get the data (mutable) | ||
*/ | ||
std::vector<uint8_t>& Data() { return m_data; } | ||
|
||
/*! | ||
* \brief Set the data | ||
*/ | ||
void SetData(std::vector<uint8_t> data) { m_data = std::move(data); } | ||
|
||
/*! | ||
* \brief Serialize as an array of bytes | ||
*/ | ||
std::vector<uint8_t> Serialize() const; | ||
|
||
/*! | ||
* \brief Deserialize an array of bytes | ||
*/ | ||
void Deserialize(const std::vector<uint8_t>& data); | ||
|
||
private: | ||
// Block parameters | ||
CCID m_cid; | ||
std::vector<uint8_t> m_data; | ||
}; | ||
} // namespace DATASTORE | ||
} // namespace KODI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Team Kodi | ||
* This file is part of Kodi - https://kodi.tv | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* See LICENSES/README.md for more information. | ||
*/ | ||
|
||
#include "BlockStore.h" | ||
|
||
#include "Block.h" | ||
#include "CID.h" | ||
#include "DataStore.h" | ||
|
||
using namespace KODI; | ||
using namespace DATASTORE; | ||
|
||
CBlockStore::CBlockStore(CDataStore& dataStore) : m_dataStore(dataStore) | ||
{ | ||
} | ||
|
||
bool CBlockStore::Has(const CCID& cid) | ||
{ | ||
std::vector<uint8_t> key = cid.Serialize(); | ||
|
||
if (m_dataStore.Has(key.data(), key.size())) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
bool CBlockStore::Get(const CCID& cid, CBlock& block) | ||
{ | ||
std::vector<uint8_t> key = cid.Serialize(); | ||
|
||
if (m_dataStore.Get(key.data(), key.size(), block.Data())) | ||
{ | ||
block.SetCID(cid); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool CBlockStore::Put(const CBlock& block) | ||
{ | ||
std::vector<uint8_t> key = block.CID().Serialize(); | ||
|
||
if (m_dataStore.Put(key.data(), key.size(), block.Data().data(), block.Data().size())) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
bool CBlockStore::Delete(const CCID& cid) | ||
{ | ||
std::vector<uint8_t> key = cid.Serialize(); | ||
|
||
if (m_dataStore.Delete(key.data(), key.size())) | ||
return true; | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Team Kodi | ||
* This file is part of Kodi - https://kodi.tv | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* See LICENSES/README.md for more information. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace KODI | ||
{ | ||
namespace DATASTORE | ||
{ | ||
class CBlock; | ||
class CCID; | ||
class CDataStore; | ||
|
||
/*! | ||
* \brief Thin wrapper over a data store for getting and putting block | ||
* objects | ||
*/ | ||
class CBlockStore | ||
{ | ||
public: | ||
/*! | ||
* \brief Construct a block store | ||
* | ||
* \param dataStore The underlying data store | ||
*/ | ||
CBlockStore(CDataStore& dataStore); | ||
~CBlockStore() = default; | ||
|
||
/*! | ||
* \brief Determine if the CID can be found | ||
* | ||
* \param CID The CID to look for | ||
* | ||
* \return True if a block with the given CID was found, false otherwise | ||
*/ | ||
bool Has(const CCID& cid); | ||
|
||
/*! | ||
* \brief Find a block based on its CID | ||
* | ||
* \param cid The CID to look for | ||
* \param block The block, or unmodified if this returns false | ||
* | ||
* \return True if the block was retrieved, false for missing CID or error | ||
*/ | ||
bool Get(const CCID& cid, CBlock& block); | ||
|
||
/*! | ||
* \brief Add a block to the block store, replacing any existing block | ||
* | ||
* \param block The block to store | ||
* | ||
* \return True if the block was added, false on error | ||
*/ | ||
bool Put(const CBlock& block); | ||
|
||
/*! | ||
* \brief Delete a block based on its CID | ||
* | ||
* \param CID The CID to look for | ||
* | ||
* \return True on success, false on error | ||
*/ | ||
bool Delete(const CCID& cid); | ||
|
||
private: | ||
// Construction parameters | ||
CDataStore& m_dataStore; | ||
}; | ||
} // namespace DATASTORE | ||
} // namespace KODI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2018-2020 Team Kodi | ||
* This file is part of Kodi - https://kodi.tv | ||
* | ||
* SPDX-License-Identifier: GPL-2.0-or-later | ||
* See LICENSES/README.md for more information. | ||
*/ | ||
|
||
#include "CID.h" | ||
|
||
using namespace KODI; | ||
using namespace DATASTORE; | ||
|
||
CCID::CCID(CIDCodec codec, std::vector<uint8_t> multihash) | ||
: m_codec(codec), m_multihash(std::move(multihash)) | ||
{ | ||
} | ||
|
||
std::vector<uint8_t> CCID::Serialize() const | ||
{ | ||
std::vector<uint8_t> data; | ||
|
||
//! @todo | ||
|
||
return data; | ||
} | ||
|
||
void CCID::Deserialize(const std::vector<uint8_t>& data) | ||
{ | ||
//! @todo | ||
} |
Oops, something went wrong.