use Name everywhere
diff --git a/src/ccnx-tunnel.cpp b/src/ccnx-tunnel.cpp
index 037bd8a..49e28af 100644
--- a/src/ccnx-tunnel.cpp
+++ b/src/ccnx-tunnel.cpp
@@ -18,8 +18,8 @@
void
CcnxTunnel::refreshLocalPrefix()
{
- string newPrefix = getLocalPrefix();
- if (!newPrefix.empty() && m_localPrefix != newPrefix)
+ Name newPrefix = getLocalPrefix();
+ if (!newPrefix.toString().empty() && m_localPrefix != newPrefix)
{
CcnxWrapper::clearInterestFilter(m_localPrefix);
CcnxWrapper::setInterestFilter(newPrefix, bind(&CcnxTunnel::handleTunneledInterest, this, _1));
@@ -28,23 +28,22 @@
}
int
-CcnxTunnel::sendInterest (const string &interest, Closure *closure)
+CcnxTunnel::sendInterest (const Name &interest, Closure *closure, const Selectors &selectors)
{
- string strInterest = interest;
- string tunneledInterest = queryRoutableName(strInterest);
- Closure *cp = new TunnelClosure(closure, this, strInterest);
- sendInterest(tunneledInterest, cp);
+ Name tunneledInterest = queryRoutableName(interest);
+ Closure *cp = new TunnelClosure(closure, this, interest);
+ sendInterest(tunneledInterest, cp, selectors);
}
void
-CcnxTunnel::handleTunneledData(const string &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback)
+CcnxTunnel::handleTunneledData(const Name &name, const Bytes &tunneledData, const Closure::DataCallback &originalDataCallback)
{
ParsedContentObject pco(tunneledData);
originalDataCallback(pco.name(), pco.content());
}
int
-CcnxTunnel::publishData(const string &name, const unsigned char *buf, size_t len, int freshness)
+CcnxTunnel::publishData(const Name &name, const unsigned char *buf, size_t len, int freshness)
{
Bytes content = createContentObject(name, buf, len, freshness);
storeContentObject(name, content);
@@ -53,20 +52,18 @@
}
int
-CcnxTunnel::publishContentObject(const string &name, const Bytes &contentObject, int freshness)
+CcnxTunnel::publishContentObject(const Name &name, const Bytes &contentObject, int freshness)
{
- string tunneledName = m_localPrefix + name;
+ Name tunneledName = m_localPrefix + name;
Bytes tunneledCo = createContentObject(tunneledName, head(contentObject), contentObject.size(), freshness);
return putToCcnd(tunneledCo);
}
void
-CcnxTunnel::handleTunneledInterest(const string &tunneledInterest)
+CcnxTunnel::handleTunneledInterest(const Name &tunneledInterest)
{
// The interest must have m_localPrefix as a prefix (component-wise), otherwise ccnd would not deliver it to us
- string interest = (m_localPrefix == "/")
- ? tunneledInterest
- : tunneledInterest.substr(m_localPrefix.size());
+ Name interest = tunneledInterest.getPartialName(m_localPrefix.size());
ReadLock(m_ritLock);
@@ -82,23 +79,27 @@
}
bool
-CcnxTunnel::isPrefix(const string &prefix, const string &name)
+CcnxTunnel::isPrefix(const Name &prefix, const Name &name)
{
- // prefix is literally prefix of name
- if (name.find(prefix) == 0)
+ if (prefix.size() > name.size())
{
- // name and prefix are exactly the same, or the next character in name
- // is '/'; in both case, prefix is the ccnx prefix of name (component-wise)
- if (name.size() == prefix.size() || name.at(prefix.size()) == '/')
+ return false;
+ }
+
+ int size = prefix.size();
+ for (int i = 0; i < size; i++)
+ {
+ if (prefix.getCompAsString(i) != name.getCompAsString(i))
{
- return true;
+ return false;
}
}
- return false;
+
+ return true;
}
int
-CcnxTunnel::setInterestFilter(const string &prefix, const InterestCallback &interestCallback)
+CcnxTunnel::setInterestFilter(const Name &prefix, const InterestCallback &interestCallback)
{
WriteLock(m_ritLock);
// make sure copy constructor for boost::function works properly
@@ -107,28 +108,28 @@
}
void
-CcnxTunnel::clearInterestFilter(const string &prefix)
+CcnxTunnel::clearInterestFilter(const Name &prefix)
{
WriteLock(m_ritLock);
// remove all
m_rit.erase(prefix);
}
-TunnelClosure::TunnelClosure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const string &originalInterest)
+TunnelClosure::TunnelClosure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback, CcnxTunnel *tunnel, const Name &originalInterest)
: Closure(retry, dataCallback, timeoutCallback)
, m_tunnel(tunnel)
, m_originalInterest(originalInterest)
{
}
-TunnelClosure::TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const string &originalInterest)
+TunnelClosure::TunnelClosure(const Closure *closure, CcnxTunnel *tunnel, const Name &originalInterest)
: Closure(*closure)
, m_tunnel(tunnel)
{
}
void
-TunnelClosure::runDataCallback(const string &name, const Bytes &content)
+TunnelClosure::runDataCallback(const Name &name, const Bytes &content)
{
if (m_tunnel != NULL)
{
@@ -137,7 +138,7 @@
}
Closure::TimeoutCallbackReturnValue
-TunnelClosure::runTimeoutCallback(const string &interest)
+TunnelClosure::runTimeoutCallback(const Name &interest)
{
return Closure::runTimeoutCallback(m_originalInterest);
}