Exemple #1
0
int MediaThread::lookupPrefixInPit(const ndn::Name &prefix,
                                   SegmentData::SegmentMetaInfo &metaInfo)
{
    lock_guard<mutex> scopedLock(pitMutex_);
    
    std::map<Name, PitEntry>::iterator pitHit = pit_.find(prefix);
    
    // check for rightmost prefixes
    if (pitHit == pit_.end())
    {
        ndn::Name testPrefix(prefix);
        
        NdnRtcNamespace::trimPacketNumber(prefix, testPrefix);
        pitHit = pit_.find(testPrefix);
    }
    
    if (pitHit != pit_.end())
    {
        int64_t currentTime = NdnRtcUtils::millisecondTimestamp();
        
        shared_ptr<const Interest> pendingInterest = pitHit->second.interest_;
        
        metaInfo.interestNonce_ =
        NdnRtcUtils::blobToNonce(pendingInterest->getNonce());
        metaInfo.interestArrivalMs_ = pitHit->second.arrivalTimestamp_;
        metaInfo.generationDelayMs_ = (uint32_t)(currentTime - pitHit->second.arrivalTimestamp_);
        
        pit_.erase(pitHit);
        
        LogTraceC
        << "pit hit [" << prefix.toUri() << "] -> ["
        << pendingInterest->getName().toUri() << " (size "
        << pit_.size()  << ")]" << std::endl;
        
        return 1;
    }
    else
    {
        LogTraceC << "no pit entry " << prefix.toUri() << std::endl;
    }
    
    return 0;
}
bool NdnRtcNamespace::isDeltaFramesPrefix(const ndn::Name &prefix)
{
    std::string prefixString = prefix.toUri();
    
    int n1 = prefixString.find(NameComponentUserStreams);
    int n2 = prefixString.find(NameComponentStreamFrames);
    int n3 = prefixString.find(NameComponentStreamFramesDelta);
  
    return !(n1 == n2 == n3) &&
            n1 >= 0 && n1 < n2 && n2 < n3;
}
bool NdnRtcNamespace::hasComponent(const ndn::Name &prefix,
                                   const std::string &componentString,
                                   bool isClosed)
{
    string prefixStr = prefix.toUri();
    string searchStr(componentString);
    
    if (searchStr[0] != '/')
        searchStr.insert(0, "/");
    
    if (isClosed &&
        searchStr[searchStr.size()-1] != '/')
        searchStr.append("/");

    return prefixStr.find(searchStr) != std::string::npos;
}
    void
    runScripts(ndn::Name& interestName)
    {
        std::string result, tmpString;
        std::string prefix = "./";
        FILE* pipe;
        const char* cmd;
        char buf[BUF_SIZE];

        while (!m_scriptsList.empty())
        {
            tmpString = prefix + m_scriptsList.front() + ' ' + interestName.toUri();
            cmd = tmpString.c_str();

            if(DEBUG) std::cout << "running " << cmd << std::endl;

            pipe = popen(cmd, "r");
            if (!pipe)
                std::cerr << "Unable to run " << cmd << " - is the script in the nfdDataCollection directory?" << std::endl;

            result = "";
            while(!feof(pipe))
            {
                if(fgets(buf, BUF_SIZE, pipe) != NULL)
                    result += buf;
            }
            pclose(pipe);
            m_scriptsList.pop_front();

            if(DEBUG) std::cout <<  "Got data: " << result << std::endl;

            // generate data packet containing script data
            ScriptReply script_reply;
            script_reply.setData(result);
            ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>(interestName);
            data->setContent(script_reply.wireEncode());
            data->setFreshnessPeriod(time::seconds(0));

            m_keyChain.sign(*data);
            m_face.put(*data);
        }
    }
bool NdnRtcNamespace::trimmedLookupPrefix(const ndn::Name &prefix,
                                          ndn::Name &trimmedPrefix)
{
    trimmedPrefix = prefix;
    
    bool res = false;
    std::string prefixString = prefix.toUri();
    int n1 = prefixString.find(NameComponentUserStreams);
    int n2 = prefixString.find(NameComponentStreamFrames);
    int n3 = prefixString.find(NameComponentStreamFramesKey);
    int n4 = prefixString.find(NameComponentStreamFramesDelta);
    
    if (!(n1 == n2 == n3 == n4) &&
        n1 >= 0 && n1 < n2 &&
        (n2 < n3 || n2 < n4))
    {
        int p1 = prefixString.find(NameComponentFrameSegmentData);
        int p2 = prefixString.find(NameComponentFrameSegmentParity);
        
        if (!(p1 == p2))
        {
            int p = -1;
            
            if (p1 == std::string::npos)
                p = findComponent(prefix, NameComponentFrameSegmentParity);
            else
                p = findComponent(prefix, NameComponentFrameSegmentData);
            
            trimmedPrefix = prefix.getSubName(0, p);
        }
        
        res = true;
    }
    
    return res;
}