Skip to content

Commit

Permalink
Update clang format rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Jan 6, 2025
1 parent a856323 commit 2a77ee3
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 62 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BasedOnStyle: Mozilla
AllowShortFunctionsOnASingleLine: Empty
IndentWidth: 2
ColumnLimit: 100
ColumnLimit: 110
10 changes: 4 additions & 6 deletions examples/chat-pubsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class Program
// Subscribe to all data packets with prefix /chat (the "topic")
m_svsps->subscribe(ndn::Name("/chat"), [](const auto& subData) {
std::string content(reinterpret_cast<const char*>(subData.data.data()), subData.data.size());
std::cout << subData.producerPrefix << " [" << subData.seqNo << "] : " << subData.name
<< " : ";
std::cout << subData.producerPrefix << " [" << subData.seqNo << "] : " << subData.name << " : ";
if (content.length() > 200) {
std::cout << "[LONG] " << content.length() << " bytes"
<< " [" << std::hash<std::string>{}(content) << "]";
Expand Down Expand Up @@ -125,8 +124,8 @@ class Program
for (auto& c : content)
c = std::rand() % 26 + 'a';

std::cout << "> Sending random message with hash [" << std::hash<std::string>{}(content)
<< "]" << std::endl;
std::cout << "> Sending random message with hash [" << std::hash<std::string>{}(content) << "]"
<< std::endl;
}

// Note that unlike SVSync, names can be arbitrary,
Expand All @@ -135,8 +134,7 @@ class Program
name.append(m_options.m_id); // who sent this
name.appendTimestamp(); // and when

m_svsps->publish(
name, ndn::make_span(reinterpret_cast<const uint8_t*>(content.data()), content.size()));
m_svsps->publish(name, ndn::make_span(reinterpret_cast<const uint8_t*>(content.data()), content.size()));
}

private:
Expand Down
3 changes: 1 addition & 2 deletions examples/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class Program
// Use HMAC signing for Sync Interests
// Note: this is not generally recommended, but is used here for simplicity
ndn::svs::SecurityOptions securityOptions(m_keyChain);
securityOptions.interestSigner->signingInfo.setSigningHmacKey(
"dGhpcyBpcyBhIHNlY3JldCBtZXNzYWdl");
securityOptions.interestSigner->signingInfo.setSigningHmacKey("dGhpcyBpcyBhIHNlY3JldCBtZXNzYWdl");

// Create the SVSync instance
m_svs = std::make_shared<ndn::svs::SVSync>(
Expand Down
3 changes: 1 addition & 2 deletions ndn-svs/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ SVSyncCore::retxSyncInterest(bool send, unsigned int delay)
// Store the scheduled time
m_nextSyncInterest = getCurrentTime() + 1000 * delay;

m_retxEvent =
m_scheduler.schedule(time::milliseconds(delay), [this] { retxSyncInterest(true, 0); });
m_retxEvent = m_scheduler.schedule(time::milliseconds(delay), [this] { retxSyncInterest(true, 0); });
}
}

Expand Down
20 changes: 16 additions & 4 deletions ndn-svs/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ class SVSyncCore : noncopyable
*
* @param prefix prefix of the node
*/
const NodeID& getNodeId() { return m_id; }
const NodeID& getNodeId()
{
return m_id;
}

/**
* @brief Get current seqNo of the local session.
Expand Down Expand Up @@ -141,10 +144,16 @@ class SVSyncCore : noncopyable
}

/// @brief Get current version vector
VersionVector& getState() { return m_vv; }
VersionVector& getState()
{
return m_vv;
}

/// @brief Get human-readable representation of version vector
std::string getStateStr() const { return m_vv.toStr(); }
std::string getStateStr() const
{
return m_vv.toStr();
}

NDN_SVS_PUBLIC_WITH_TESTS_ELSE_PRIVATE : void onSyncInterest(const Interest& interest);

Expand Down Expand Up @@ -206,7 +215,10 @@ class SVSyncCore : noncopyable
void enterSuppressionState(const VersionVector& vvOther);

/// @brief Reference to scheduler
ndn::Scheduler& getScheduler() { return m_scheduler; }
ndn::Scheduler& getScheduler()
{
return m_scheduler;
}

/// @brief Get the current time in microseconds with arbitrary reference
long getCurrentTime() const;
Expand Down
3 changes: 1 addition & 2 deletions ndn-svs/fetcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ Fetcher::onData(const Interest& interest, const Data& data, const QueuedInterest
auto onValidationFailed = [this, qi](const Data& data, const ValidationError& error) {
if (qi.nRetriesOnValidationFail > 0) {
this->m_scheduler.schedule(
ndn::time::milliseconds(this->m_securityOptions.millisBeforeRetryOnValidationFail),
[this, qi] {
ndn::time::milliseconds(this->m_securityOptions.millisBeforeRetryOnValidationFail), [this, qi] {
QueuedInterest qiNew(qi);
qiNew.nRetriesOnValidationFail--;
this->expressInterest(qiNew);
Expand Down
13 changes: 6 additions & 7 deletions ndn-svs/fetcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ class Fetcher
public:
Fetcher(Face& face, const SecurityOptions& securityOptions);

void expressInterest(
const ndn::Interest& interest,
const ndn::DataCallback& afterSatisfied,
const ndn::NackCallback& afterNacked,
const ndn::TimeoutCallback& afterTimeout,
int nRetries = 0,
const ndn::security::DataValidationFailureCallback& afterValidationFailed = nullptr);
void expressInterest(const ndn::Interest& interest,
const ndn::DataCallback& afterSatisfied,
const ndn::NackCallback& afterNacked,
const ndn::TimeoutCallback& afterTimeout,
int nRetries = 0,
const ndn::security::DataValidationFailureCallback& afterValidationFailed = nullptr);

private:
struct QueuedInterest;
Expand Down
11 changes: 4 additions & 7 deletions ndn-svs/mapping-provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,13 @@ MappingProvider::MappingProvider(const Name& syncPrefix,
, m_fetcher(face, securityOptions)
, m_securityOptions(securityOptions)
{
m_registeredPrefix =
m_face.setInterestFilter(Name(m_id).append(m_syncPrefix).append("MAPPING"),
std::bind(&MappingProvider::onMappingQuery, this, _2),
[](auto&&...) {});
m_registeredPrefix = m_face.setInterestFilter(Name(m_id).append(m_syncPrefix).append("MAPPING"),
std::bind(&MappingProvider::onMappingQuery, this, _2),
[](auto&&...) {});
}

void
MappingProvider::insertMapping(const NodeID& nodeId,
const SeqNo& seqNo,
const MappingEntryPair& entry)
MappingProvider::insertMapping(const NodeID& nodeId, const SeqNo& seqNo, const MappingEntryPair& entry)
{
m_map[Name(nodeId).appendNumber(seqNo)] = entry;
}
Expand Down
5 changes: 4 additions & 1 deletion ndn-svs/store-memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class MemoryDataStore : public DataStore
return m_ims.find(interest);
}

void insert(const Data& data) override { return m_ims.insert(data); }
void insert(const Data& data) override
{
return m_ims.insert(data);
}

private:
InMemoryStoragePersistent m_ims;
Expand Down
17 changes: 5 additions & 12 deletions ndn-svs/svspubsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,13 @@ SeqNo
SVSPubSub::publishPacket(const Data& data, const Name& nodePrefix, std::vector<Block> mappingBlocks)
{
NodeID nid = nodePrefix == EMPTY_NAME ? m_dataPrefix : nodePrefix;
SeqNo seqNo =
m_svsync.publishData(data.wireEncode(), data.getFreshnessPeriod(), nid, ndn::tlv::Data);
SeqNo seqNo = m_svsync.publishData(data.wireEncode(), data.getFreshnessPeriod(), nid, ndn::tlv::Data);
insertMapping(nid, seqNo, data.getName(), mappingBlocks);
return seqNo;
}

void
SVSPubSub::insertMapping(const NodeID& nid,
SeqNo seqNo,
const Name& name,
std::vector<Block> additional)
SVSPubSub::insertMapping(const NodeID& nid, SeqNo seqNo, const Name& name, std::vector<Block> additional)
{
// additional is a copy deliberately
// this way we can add well-known mappings to the list
Expand Down Expand Up @@ -186,8 +182,7 @@ SVSPubSub::updateCallbackInternal(const std::vector<MissingDataInfo>& info)

// Prefetch next available data
if (sub.prefetch)
m_svsync.fetchData(
stream.nodeId, stream.high + 1, [](auto&&...) {}); // do nothing with prefetch
m_svsync.fetchData(stream.nodeId, stream.high + 1, [](auto&&...) {}); // do nothing with prefetch
}
}

Expand Down Expand Up @@ -308,8 +303,7 @@ SVSPubSub::onSyncData(const Data& firstData, const std::pair<Name, SeqNo>& publi

// Return data to packet subscriptions
SubscriptionData subData = {
innerData.getName(), innerContent.value_bytes(), publication.first, publication.second,
innerData,
innerData.getName(), innerContent.value_bytes(), publication.first, publication.second, innerData,
};

// Function to return data to subscriptions
Expand All @@ -336,8 +330,7 @@ SVSPubSub::onSyncData(const Data& firstData, const std::pair<Name, SeqNo>& publi
fetcher->onComplete.connectSingleShot([this, publication](const ndn::ConstBufferPtr& data) {
try {
// Binary BLOB to return to app
auto finalBuffer =
std::make_shared<std::vector<uint8_t>>(std::vector<uint8_t>(data->size()));
auto finalBuffer = std::make_shared<std::vector<uint8_t>>(std::vector<uint8_t>(data->size()));
auto bufSize = std::make_shared<size_t>(0);
bool hasValidator = !!m_securityOptions.encapsulatedDataValidator;

Expand Down
14 changes: 6 additions & 8 deletions ndn-svs/svspubsub.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ class SVSPubSub : noncopyable
*
* @returns Handle to the subscription
*/
uint32_t subscribe(const Name& prefix,
const SubscriptionCallback& callback,
bool packets = false);
uint32_t subscribe(const Name& prefix, const SubscriptionCallback& callback, bool packets = false);

/**
* @brief Subscribe to a data producer
Expand Down Expand Up @@ -169,7 +167,10 @@ class SVSPubSub : noncopyable
std::vector<Block> mappingBlocks = {});

/** @brief Get the underlying sync */
SVSync& getSVSync() { return m_svsync; }
SVSync& getSVSync()
{
return m_svsync;
}

private:
struct Subscription
Expand All @@ -190,10 +191,7 @@ class SVSPubSub : noncopyable
void onRecvExtraData(const Block& block);

/// @brief Insert a mapping entry into the store
void insertMapping(const NodeID& nid,
SeqNo seqNo,
const Name& name,
std::vector<Block> additional);
void insertMapping(const NodeID& nid, SeqNo seqNo, const Name& name, std::vector<Block> additional);

/**
* @brief Get and process mapping from store.
Expand Down
3 changes: 1 addition & 2 deletions ndn-svs/svsync-base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ SVSyncBase::publishData(const uint8_t* buf,
const ndn::time::milliseconds& freshness,
const NodeID& nid)
{
return publishData(
ndn::encoding::makeBinaryBlock(ndn::tlv::Content, { buf, len }), freshness, nid);
return publishData(ndn::encoding::makeBinaryBlock(ndn::tlv::Content, { buf, len }), freshness, nid);
}

SeqNo
Expand Down
15 changes: 12 additions & 3 deletions ndn-svs/svsync-base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,16 @@ class SVSyncBase : noncopyable
int nRetries = 0);

/** @brief Get the underlying data store */
DataStore& getDataStore() { return *m_dataStore; }
DataStore& getDataStore()
{
return *m_dataStore;
}

/** @brief Get the underlying SVS core */
SVSyncCore& getCore() { return m_core; }
SVSyncCore& getCore()
{
return m_core;
}

protected:
/**
Expand Down Expand Up @@ -180,7 +186,10 @@ class SVSyncBase : noncopyable
* Can be used to cache data packets from other nodes when
* using multicast data interests.
*/
virtual bool shouldCache(const Data& data) const { return false; }
virtual bool shouldCache(const Data& data) const
{
return false;
}

protected:
const Name m_syncPrefix;
Expand Down
10 changes: 8 additions & 2 deletions ndn-svs/svsync-shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ class SVSyncShared : public SVSyncBase
}

/** @brief Set whether data of other nodes is also cached and served */
void setCacheAll(bool val) { m_cacheAll = val; }
void setCacheAll(bool val)
{
m_cacheAll = val;
}

private:
bool shouldCache(const Data&) const override { return m_cacheAll; }
bool shouldCache(const Data&) const override
{
return m_cacheAll;
}

private:
bool m_cacheAll = false;
Expand Down
15 changes: 12 additions & 3 deletions ndn-svs/version-vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,20 @@ class VersionVector
return elem == m_lastUpdate.end() ? time::system_clock::time_point::min() : elem->second;
}

const_iterator begin() const noexcept { return m_map.begin(); }
const_iterator begin() const noexcept
{
return m_map.begin();
}

const_iterator end() const noexcept { return m_map.end(); }
const_iterator end() const noexcept
{
return m_map.end();
}

bool has(const NodeID& nid) const { return m_map.find(nid) != end(); }
bool has(const NodeID& nid) const
{
return m_map.find(nid) != end();
}

private:
std::map<NodeID, SeqNo> m_map;
Expand Down

0 comments on commit 2a77ee3

Please sign in to comment.