10 #include "../face.hpp"
11 #include "../security/signature-sha256-with-rsa.hpp"
12 #include "../util/random.hpp"
34 if (m_filterRequests.empty())
37 bind(&Controller::onNdnidFetched,
this, _1, _2),
38 bind(onFail,
"NDNDID fetching timed out"));
40 m_filterRequests.push_back(FilterRequest(prefixToRegister, onSuccess, onFail));
44 bind(&Controller::recordSelfRegisteredFaceId,
this, _1, onSuccess),
54 if (!m_ndndId.
hasValue() || m_faceId == -1)
56 if (static_cast<bool>(onFail))
57 onFail(
"NDNID is not available (must have been present after a successful registration operation)");
62 bind(onSuccess), onFail);
67 Controller::onNdnidFetched(
const Interest& interest,
Data& data)
75 for (FilterRequestList::iterator i = m_filterRequests.begin();
76 i != m_filterRequests.end();
79 if (static_cast<bool>(i->m_onFailure))
80 i->m_onFailure(
"Fetched unrecognized NDNID");
86 for (FilterRequestList::iterator i = m_filterRequests.begin();
87 i != m_filterRequests.end();
91 bind(&Controller::recordSelfRegisteredFaceId,
this, _1, i->m_onSuccess),
97 for (FilterRequestList::iterator i = m_filterRequests.begin();
98 i != m_filterRequests.end();
101 if (static_cast<bool>(i->m_onFailure))
102 i->m_onFailure(
"NDNID cannot be fetched");
105 m_filterRequests.clear();
110 const SuccessCallback& onSuccess)
112 m_faceId = entry.getFaceId();
113 if (static_cast<bool>(onSuccess))
135 interestName.
append(
"ndnx");
146 bind(&Controller::processFaceActionResponse,
this, _2, onSuccess, onFail),
147 bind(onFail,
"Command Interest failed"));
168 interestName.
append(
"ndnx");
179 bind(&Controller::processPrefixActionResponse,
this, _2, onSuccess, onFail),
180 bind(onFail,
"Command Interest timed out"));
184 Controller::processFaceActionResponse(
Data& data,
185 const FaceOperationSucceedCallback& onSuccess,
186 const FailCallback& onFail)
193 if (static_cast<bool>(onFail))
194 onFail(
"Empty response");
205 entry.wireDecode(*val);
207 if (static_cast<bool>(onSuccess))
214 resp.wireDecode(*val);
216 if (static_cast<bool>(onFail))
217 onFail(resp.getInfo());
222 if (static_cast<bool>(onFail))
223 onFail(
"Invalid response");
230 Controller::processPrefixActionResponse(
Data& data,
231 const PrefixOperationSucceedCallback& onSuccess,
232 const FailCallback& onFail)
234 Block content = data.getContent();
237 if (content.elements().empty())
239 if (static_cast<bool>(onFail))
240 onFail(
"Empty response");
251 entry.wireDecode(*val);
253 if (static_cast<bool>(onSuccess))
260 resp.wireDecode(*val);
264 if (static_cast<bool>(onFail))
265 onFail(resp.getInfo());
270 if (static_cast<bool>(onFail))
271 onFail(
"Invalid response");
Representing of SHA256-with-RSA signature in a data packet.
const Name & getName() const
bool hasValue() const
Check if the Block has value block (no type and length are encoded)
virtual void selfDeregisterPrefix(const Name &prefixToRegister, const SuccessCallback &onSuccess, const FailCallback &onFail)
const std::string & getAction() const
Interest & setMustBeFresh(bool mustBeFresh)
const std::string & getAction() const
function< void(const FaceInstance &)> FaceOperationSucceedCallback
Interest & setScope(int scope)
const element_container & elements() const
Get all subelements.
function< void()> SuccessCallback
Class representing wire element of the NDN packet.
An Interest holds a Name and other fields for an interest.
Controller(Face &face)
Construct ndnd::Control object.
Buffer::const_iterator value_begin() const
Buffer::const_iterator value_end() const
void startFaceAction(const FaceInstance &entry, const FaceOperationSucceedCallback &onSuccess, const FailCallback &onFailure)
size_t wireEncode(EncodingImpl< T > &block, bool unsignedPortion=false) const
Fast encoding or block size estimation.
const Name & getName() const
void startPrefixAction(const ForwardingEntry &entry, const PrefixOperationSucceedCallback &onSuccess, const FailCallback &onFailure)
element_const_iterator elements_begin() const
uint32_t generateWord32()
virtual void selfRegisterPrefix(const Name &prefixToRegister, const SuccessCallback &onSuccess, const FailCallback &onFail)
void setValue(const Block &value)
void setContent(const uint8_t *content, size_t contentLength)
Set the content to a copy of the data in the vector.
function< void(const std::string &)> FailCallback
An ForwardingEntry holds an action and Name prefix and other fields for an forwarding entry...
Abstraction to communicate with local or remote NDN forwarder.
const Block & wireEncode() const
An FaceInstance holds an action and Name prefix and other fields for an forwarding entry...
function< void(const ForwardingEntry &)> PrefixOperationSucceedCallback
element_container::const_iterator element_const_iterator
size_t size() const
Get the number of components.
A Name holds an array of Name::Component and represents an NDN name.
const PendingInterestId * expressInterest(const Interest &interest, const OnData &onData, const OnTimeout &onTimeout=OnTimeout())
Express Interest.
const Block & wireEncode() const
size_t value_size() const
void parse() const
Parse wire buffer into subblocks.
const Block & getContent() const
Get content Block.
Name & append(const uint8_t *value, size_t valueLength)
Append a new component, copying from value of length valueLength.
void setName(const Name &name)
Set name to a copy of the given Name.
Interest & setInterestLifetime(const time::milliseconds &interestLifetime)
void setSignature(const Signature &signature)
Set the signature to a copy of the given signature.