Example #1
0
ptr_lib::shared_ptr<DataBlock>
FrameBuffer::acquireData(const ndn::Interest& interest, ndn::Name& nalType )
{
    lock_guard<recursive_mutex> scopedLock(syncMutex_);

    ptr_lib::shared_ptr<DataBlock> data;
    std::map<ndn::Name, ptr_lib::shared_ptr<DataBlock> >::reverse_iterator re_iter;
    //iter = activeSlots_.find(interest.getName());

    ndn::Name name;
    for( re_iter = activeSlots_.rbegin(); re_iter != activeSlots_.rend(); ++re_iter )
    {
        name = re_iter->first;
        if( interest.getName().equals(name.getPrefix(interest.getName().size())))
        {
            nalType = name.getSubName(-2);
            break;
        }
    }
    if (re_iter!=activeSlots_.rend())   //if found
    {
        data = re_iter->second;
        //cout << "********** size:" << segBlock->size() << " &data=" << (void*)(segBlock->dataPtr()) <<  endl;
    }
    return data;
}
void
EdgeStrategy::onDataDenied
( const ndn::Data& data,
  const ndn::Interest& interest,
  ns3::Time& delay,
  const std::string& why )
{
    // if the denied data isn't leaving the network
    // then we just do the normal router stuff
    auto in_face = getFaceTable().get( data.getIncomingFaceId() );
    auto out_face = getFaceTable().get( interest.getIncomingFaceId() );
    bool coming_from_network = !in_face->isEdge();
    bool going_to_network = !out_face->isEdge();
    
    if( coming_from_network == going_to_network )
    {
        RouterStrategy::onDataDenied( data, interest, delay, why );
        return;
    }
    
    if( going_to_network )
    {
        BOOST_ASSERT( data.getCurrentNetwork()
                    == ndn::RouteTracker::INTERNET_NETWORK );
        RouterStrategy::onDataDenied( data, interest, delay, why );
        return;
    }
    
    // if the data is denied then we add the
    // tag used to retrieve it to the negative
    // cache; however we only want to do this
    // when the data is leaving the internet
    // and going into the client network
    // and the data's access level > 0
    BOOST_ASSERT( data.getCurrentNetwork()
                == ndn::RouteTracker::ENTRY_NETWORK );
    if( data.getAccessLevel() > 0 )
    {
        BOOST_ASSERT( interest.hasAuthTag() );
        tracers::edge->bloom_insert
        ( interest.getAuthTag(), s_edge_bloom_delay );
        delay += s_edge_bloom_delay;
        m_negative_cache.insert( interest.getAuthTag() );
    }

    // do whatever a normal router would do
    RouterStrategy::onDataDenied( data, interest, delay, why );
}
Example #3
0
void
HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
{
  /* interest name: /<neighbor>/NLSR/INFO/<router> */
  const ndn::Name interestName(interest.getName());
  _LOG_DEBUG("Interest timed out for Name: " << interestName);
  if (interestName.get(-2).toUri() != INFO_COMPONENT) {
    return;
  }
  ndn::Name neighbor = interestName.getPrefix(-3);
  _LOG_DEBUG("Neighbor: " << neighbor);
  m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);

  Adjacent::Status status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);

  uint32_t infoIntTimedOutCount =
    m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
  _LOG_DEBUG("Status: " << status);
  _LOG_DEBUG("Info Interest Timed out: " << infoIntTimedOutCount);
  if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber())) {
    /* interest name: /<neighbor>/NLSR/INFO/<router> */
    ndn::Name interestName(neighbor);
    interestName.append(NLSR_COMPONENT);
    interestName.append(INFO_COMPONENT);
    interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
    expressInterest(interestName,
                    m_nlsr.getConfParameter().getInterestResendTime());
  }
  else if ((status == Adjacent::STATUS_ACTIVE) &&
           (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) {
    m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, Adjacent::STATUS_INACTIVE);

    m_nlsr.getLsdb().scheduleAdjLsaBuild();
  }
}
Example #4
0
 void
 respondToAnyInterest(const ndn::Interest& interest)
 {
   auto data = std::make_shared<ndn::Data>(interest.getName());
   m_keyChain.sign(*data);
   m_faceProducer.put(*data);
 }
void
EdgeStrategy::onDataSatisfied
( const ndn::Data& data,
  const ndn::Interest& interest,
  ns3::Time& delay )
{
    // if the satisfied data isn't leaving the network
    // then we just do the normal router stuff
    auto in_face = getFaceTable().get( data.getIncomingFaceId() );
    auto out_face = getFaceTable().get( interest.getIncomingFaceId() );
    bool coming_from_network = !in_face->isEdge();
    bool going_to_network = !out_face->isEdge();
    
    if( coming_from_network == going_to_network )
    {
        RouterStrategy::onDataSatisfied( data, interest, delay );
        return;
    }
    
    if( going_to_network )
    {
        BOOST_ASSERT( data.getCurrentNetwork()
                    == ndn::RouteTracker::INTERNET_NETWORK );
        RouterStrategy::onDataSatisfied( data, interest, delay );
        return;
    }
    
    // if the data is satisfied then we add it to
    // the positive cache if it isn't marked with
    // the no recache flag and if its access level > 0
    BOOST_ASSERT( data.getCurrentNetwork()
                == ndn::RouteTracker::ENTRY_NETWORK );
    if( !data.getNoReCacheFlag()
      && data.getAccessLevel() > 0 )
    {
        BOOST_ASSERT( interest.hasAuthTag() );
        tracers::edge->bloom_insert
        ( interest.getAuthTag(), s_edge_bloom_delay );
        delay += s_edge_bloom_delay;
        m_positive_cache.insert( interest.getAuthTag() );
    }
    
    RouterStrategy::onDataSatisfied( data, interest, delay );
}
Example #6
0
void
HelloProtocol::processInterest(const ndn::Name& name,
                               const ndn::Interest& interest)
{
  /* interest name: /<neighbor>/NLSR/INFO/<router> */
  const ndn::Name interestName = interest.getName();
  _LOG_DEBUG("Interest Received for Name: " << interestName);
  if (interestName.get(-2).toUri() != INFO_COMPONENT) {
    return;
  }
  ndn::Name neighbor;
  neighbor.wireDecode(interestName.get(-1).blockFromValue());
  _LOG_DEBUG("Neighbor: " << neighbor);
  if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) {
    ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
    data->setName(ndn::Name(interest.getName()).appendVersion());
    data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
    data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
                    INFO_COMPONENT.size());
    m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
    _LOG_DEBUG("Sending out data for name: " << interest.getName());
    m_nlsr.getNlsrFace().put(*data);
    Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
    // If this neighbor was previously inactive, send our own hello interest, too
    if (adjacent->getStatus() == Adjacent::STATUS_INACTIVE) {
      // We can only do that if the neighbor currently has a face.
      if(adjacent->getFaceId() != 0){
        /* interest name: /<neighbor>/NLSR/INFO/<router> */
        ndn::Name interestName(neighbor);
        interestName.append(NLSR_COMPONENT);
        interestName.append(INFO_COMPONENT);
        interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
        expressInterest(interestName,
                        m_nlsr.getConfParameter().getInterestResendTime());
      }
      // If the originator of the Interest currently lacks a Face, we
      // need to give it one.
      else {
        registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(),
                         adjacent->getLinkCost(), ndn::time::milliseconds::max());
      }
    }
  }
}
Example #7
0
void
PrefixUpdateProcessor::sendNack(const ndn::Interest& request)
{
  ndn::MetaInfo metaInfo;
  metaInfo.setType(ndn::tlv::ContentType_Nack);

  shared_ptr<ndn::Data> responseData = std::make_shared<ndn::Data>(request.getName());
  responseData->setMetaInfo(metaInfo);

  m_keyChain.sign(*responseData);
  m_face.put(*responseData);
}
 void
 onData( ndn::Face &face,
         const ndn::Interest& interest,
         ndn::Data& data,
         int globalReference,
         int localReference,
         int patternId,
         boost::posix_time::ptime sentTime )
 {
   double roundTripTime;
   int receivedContentLength;
   std::string receivedContent;
   std::string logLine;
   logLine = "";
   logLine += "Data Received      - PatternType="+toString(patternId+1);
   logLine += ", GlobalID="+toString(globalReference);
   logLine += ", LocalID="+toString(localReference);
   logLine += ", Name="+interest.getName().toUri();
   boost::posix_time::time_duration roundTripDuration;
   totalInterestReceived_++;
   trafficPattern_[patternId].totalInterestReceived++;
   if (trafficPattern_[patternId].expectedContent != "")
   {
     receivedContent = (char*)(data.getContent().value());
     receivedContentLength = data.getContent().value_size();
     receivedContent = receivedContent.substr(0, receivedContentLength);
     if (receivedContent != trafficPattern_[patternId].expectedContent)
     {
       contentInconsistencies_++;
       trafficPattern_[patternId].contentInconsistencies++;
       logLine += ", IsConsistent=No";
     }
     else
       logLine += ", IsConsistent=Yes";
   }
   else
     logLine += ", IsConsistent=NotChecked";
   m_logger.log(logLine, true, false);
   roundTripDuration = boost::posix_time::microsec_clock::local_time() - sentTime;
   roundTripTime = roundTripDuration.total_microseconds()/1000.0;
   if (minimumInterestRoundTripTime_ > roundTripTime)
     minimumInterestRoundTripTime_ = roundTripTime;
   if (maximumInterestRoundTripTime_ < roundTripTime)
     maximumInterestRoundTripTime_ = roundTripTime;
   if (trafficPattern_[patternId].minimumInterestRoundTripTime > roundTripTime)
     trafficPattern_[patternId].minimumInterestRoundTripTime = roundTripTime;
   if (trafficPattern_[patternId].maximumInterestRoundTripTime < roundTripTime)
     trafficPattern_[patternId].maximumInterestRoundTripTime = roundTripTime;
   totalInterestRoundTripTime_ += roundTripTime;
   trafficPattern_[patternId].totalInterestRoundTripTime += roundTripTime;
   if (totalInterestSent_ == interestCount_)
     signalHandler();
 }
Example #9
0
void
HelloProtocol::processInterest(const ndn::Name& name,
                               const ndn::Interest& interest)
{
  /* interest name: /<neighbor>/NLSR/INFO/<router> */
  const ndn::Name interestName = interest.getName();
  _LOG_DEBUG("Interest Received for Name: " << interestName);
  if (interestName.get(-2).toUri() != INFO_COMPONENT) {
    return;
  }
  ndn::Name neighbor;
  neighbor.wireDecode(interestName.get(-1).blockFromValue());
  _LOG_DEBUG("Neighbor: " << neighbor);
  if (m_nlsr.getAdjacencyList().isNeighbor(neighbor)) {
    ndn::shared_ptr<ndn::Data> data = ndn::make_shared<ndn::Data>();
    data->setName(ndn::Name(interest.getName()).appendVersion());
    data->setFreshnessPeriod(ndn::time::seconds(10)); // 10 sec
    data->setContent(reinterpret_cast<const uint8_t*>(INFO_COMPONENT.c_str()),
                    INFO_COMPONENT.size());
    m_nlsr.getKeyChain().sign(*data, m_nlsr.getDefaultCertName());
    _LOG_DEBUG("Sending out data for name: " << interest.getName());
    m_nlsr.getNlsrFace().put(*data);
    Adjacent *adjacent = m_nlsr.getAdjacencyList().findAdjacent(neighbor);
    if (adjacent->getStatus() == 0) {
      if(adjacent->getFaceId() != 0){
        /* interest name: /<neighbor>/NLSR/INFO/<router> */
        ndn::Name interestName(neighbor);
        interestName.append(NLSR_COMPONENT);
        interestName.append(INFO_COMPONENT);
        interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
        expressInterest(interestName,
                        m_nlsr.getConfParameter().getInterestResendTime());
      }
      else {
        registerPrefixes(adjacent->getName(), adjacent->getConnectingFaceUri(),
                         adjacent->getLinkCost(), ndn::time::milliseconds::max());
      }
    }
  }
}
    void
    onInterest(const ndn::Name& name, const ndn::Interest& interest)
    {
        ndn::Name interestName(interest.getName());

        if(DEBUG)
            std::cout << "received interest: " << interest.getName() << std::endl;

        //run scripts if requested by server
        ndn::Name cmpName(getFilter()+SCRIPT_SUFFIX);
        int num_components = cmpName.size();
        if(cmpName.isPrefixOf(interestName))
        {
            int numberOfComponents = interestName.size();
            for(int i = num_components; i < numberOfComponents; ++i)
            {
                m_scriptsList.push_front(interestName[i].toUri());
            }
            runScripts(interestName);
        }
        else
        {
            int numberOfComponents = interestName.size();
            if(!m_remoteLinks.empty())
            {
                std::cerr << "remote links list is not empty - check for a missing reports!!" << std::endl;
                m_remoteLinks.clear();
            }
            for(int i = name.size(); i < numberOfComponents; ++i)
            {
                m_remoteLinks.insert(interestName[i].toUri());
            }

            // ask for local status
            fetchFaceStatusInformation(interestName);
        }
    }
 void
 onTimeout( ndn::Face &face,
            const ndn::Interest& interest,
            int globalReference,
            int localReference,
            int patternId)
 {
   std::string logLine;
   logLine = "";
   logLine += "Interest Timed Out - PatternType="+toString(patternId+1);
   logLine += ", GlobalID="+toString(globalReference);
   logLine += ", LocalID="+toString(localReference);
   logLine += ", Name="+interest.getName().toUri();
   m_logger.log(logLine, true, false);
   if (totalInterestSent_ == interestCount_)
     signalHandler();
 }
Example #12
0
void
HelloProtocol::processInterestTimedOut(const ndn::Interest& interest)
{
  /* interest name: /<neighbor>/NLSR/INFO/<router> */
  const ndn::Name interestName(interest.getName());
  _LOG_DEBUG("Interest timed out for Name: " << interestName);
  if (interestName.get(-2).toUri() != INFO_COMPONENT) {
    return;
  }
  ndn::Name neighbor = interestName.getPrefix(-3);
  _LOG_DEBUG("Neighbor: " << neighbor);
  m_nlsr.getAdjacencyList().incrementTimedOutInterestCount(neighbor);
  int status = m_nlsr.getAdjacencyList().getStatusOfNeighbor(neighbor);
  uint32_t infoIntTimedOutCount =
    m_nlsr.getAdjacencyList().getTimedOutInterestCount(neighbor);
  _LOG_DEBUG("Status: " << status);
  _LOG_DEBUG("Info Interest Timed out: " << infoIntTimedOutCount);
  if ((infoIntTimedOutCount < m_nlsr.getConfParameter().getInterestRetryNumber())) {
    /* interest name: /<neighbor>/NLSR/INFO/<router> */
    ndn::Name interestName(neighbor);
    interestName.append(NLSR_COMPONENT);
    interestName.append(INFO_COMPONENT);
    interestName.append(m_nlsr.getConfParameter().getRouterPrefix().wireEncode());
    expressInterest(interestName,
                    m_nlsr.getConfParameter().getInterestResendTime());
  }
  else if ((status == 1) &&
           (infoIntTimedOutCount == m_nlsr.getConfParameter().getInterestRetryNumber())) {
    m_nlsr.getAdjacencyList().setStatusOfNeighbor(neighbor, 0);
    m_nlsr.incrementAdjBuildCount();
    if (m_nlsr.getIsBuildAdjLsaSheduled() == false) {
      _LOG_DEBUG("Scheduling scheduledAdjLsaBuild");
      m_nlsr.setIsBuildAdjLsaSheduled(true);
      // event here
      m_nlsr.getScheduler().scheduleEvent(ndn::time::seconds(5),
                                          ndn::bind(&Lsdb::scheduledAdjLsaBuild,
                                                    &m_nlsr.getLsdb()));
    }
  }
}
bool
EdgeStrategy::filterOutgoingInterest
( const nfd::Face& face,
  ndn::Interest& interest,
  ns3::Time& delay )
{
    auto in_face = getFaceTable().get( interest.getIncomingFaceId() );
    bool coming_from_network = !in_face->isEdge();
    bool going_to_network = !face.isEdge();
    
    // if the interest coming from and going to
    // the same network then we don't need to do
    // anything special
    if( coming_from_network == going_to_network )
    {
        return RouterStrategy::filterOutgoingInterest
               ( face, interest, delay );
    }
    
    // if the interest is leaving the network then just change
    // current network
    if( coming_from_network )
    {
        BOOST_ASSERT( interest.getCurrentNetwork()
                    == ndn::RouteTracker::INTERNET_NETWORK );
        tracers::edge->interest_left( interest );
        interest.setCurrentNetwork( ndn::RouteTracker::EXIT_NETWORK );
        return RouterStrategy::filterOutgoingInterest
               ( face, interest, delay );
    }
    
    // if the interest is entering the network then
    // we need to do some extra stuff
    BOOST_ASSERT( interest.getCurrentNetwork()
                == ndn::RouteTracker::ENTRY_NETWORK );
    tracers::edge->interest_entered( interest );
    interest.setCurrentNetwork( ndn::RouteTracker::INTERNET_NETWORK );
    
    // if the interest doesn't have an auth tag, or its auth level
    // is 0 then we don't do any authentication
    if( !interest.hasAuthTag()
      || interest.getAuthTag().getAccessLevel() == 0 )
    {
        return RouterStrategy::filterOutgoingInterest( face,
                                                        interest,
                                                        delay );
    }
    
    const ndn::AuthTag& auth = interest.getAuthTag();

    // if the auth tag provided by the interest is expired
    // then we can drop the interest
    if( auth.isExpired() )
    {
        tracers::edge->blocked_interest
        ( interest, tracers::BlockedExpired );
        onInterestDropped( interest, face, "Expired auth" );
        return false;
    }
    
    // if the interest and auth tag have different prefixes
    // then we drop the interest
    if( !auth.getPrefix().isPrefixOf( interest.getName() ) )
    {
        tracers::edge->blocked_interest
        ( interest, tracers::BlockedBadPrefix );
        onInterestDropped( interest, face, "Mismatched prefix" );
        return false;
    }
    
    // if the interest route hash doesn't match its auth tag
    // then we can drop it
    if( interest.getEntryRoute() != auth.getRouteHash() )
    {
        tracers::edge->blocked_interest
        ( interest, tracers::BlockedBadRoute );
        onInterestDropped( interest, face, "Bad route" );
        return false;
    }
    
    // if the interest auth is in the positive auth cache then
    // we set its auth validity probability
    tracers::edge->bloom_lookup( auth, s_edge_bloom_delay );
    delay += s_edge_bloom_delay;
    if( m_positive_cache.contains( auth ) )
    {
        double fpp = m_positive_cache.getEffectiveFPP();
        double prob = (double)1.0 - fpp;
        uint32_t iprob = prob*0xFFFFFFFF;
        interest.setAuthValidityProb( iprob );
        
    }
    else
    {
        // if it's in the negative cache then we validate
        // its signature manually
        tracers::edge->bloom_lookup( auth, s_edge_bloom_delay );
        delay += s_edge_bloom_delay;
        if( m_negative_cache.contains( auth ) )
        {
            // we simulate verification delay by incrementing
            // the processing delay
            tracers::edge->sigverif( auth, s_edge_signature_delay );
            delay += EdgeStrategy::s_edge_signature_delay;
            if( auth.getSignature().getValue().value_size() > 0
              && auth.getSignature().getValue().value()[0] != 0 )
            {
                // if signature is valid then set auth validity
                // and put auth into positive cache
                interest.setAuthValidityProb( 0xFFFFFFFF );
                tracers::edge->auth_cached
                ( auth, tracers::CachedPositiveMoved );
                m_positive_cache.insert( auth );
            }
            else
            {
                // otherwise we drop the interest
                onInterestDropped( interest, face, "negative cache, manual validation failed" );
                return false;
            }
        }
        else
        {
            // if the auth isn't in either cache then
            // we set validity probability to 0
            interest.setAuthValidityProb( 0 );
        }
    }
    
    return RouterStrategy::filterOutgoingInterest( face, interest,
                                                   delay );
}
  void
  onData(const ndn::Interest& interest, ndn::Data& data, std::string linkPrefix)
  {
    std::cout << "Data received for: " << interest.getName() << std::endl;
    CollectorData reply;

    reply.wireDecode(data.getContent().blockFromValue());

    if(reply.m_statusList.empty())
    {
      std::cerr << "received data is empty!!" << std::endl;
    }

    // get the list of the remote links requested for this prefix
    std::unordered_map<std::string,std::list<ndn::NdnMapServer::linkPair>>::const_iterator got = m_linksList.find(linkPrefix);

    if(got == m_linksList.end())
    {
      std::cerr << "failed to recognize the prefix: " << linkPrefix << std::endl;
    }
    else
    {
      std::list<ndn::NdnMapServer::linkPair> prefixList = got->second;

      for (unsigned i=0; i< reply.m_statusList.size(); i++)
      {
        int LinkId = 0;
        std::cout << "Reply: " << reply.m_statusList.at(i);

        // get the link id of the current IP
        for (auto pair = prefixList.cbegin(); pair != prefixList.cend(); ++pair)
        {
          if((*pair).linkIp == reply.m_statusList[i].getLinkIp())
          {
            if (DEBUG)
              std::cout << " Link ID for " << linkPrefix << " and " << reply.m_statusList[i].getLinkIp() << " is " << (*pair).linkId << std::endl;

            LinkId = (*pair).linkId;
          }
        }

        std::string cmdStr("http://");
        cmdStr += m_mapServerAddr;
        cmdStr += "/bw/";
        cmdStr += std::to_string(LinkId);
        cmdStr += "/" + reply.m_statusList[i].getTimestamp() + "/";
        cmdStr += std::to_string(reply.m_statusList[i].getTx() * 8) + "/";
        cmdStr += std::to_string(reply.m_statusList[i].getRx() * 8);

        if (DEBUG)
          std::cout << "cmd to pass to curl: " << cmdStr << std::endl;

        int status;
        // check for zombies
        waitpid(-1, &status, WNOHANG);
        int pid;
        if ((pid = fork()) < 0)
          printf("for failed for curl %s\n", cmdStr.c_str());
        else
        {
          if (pid == 0)
            execl("/usr/bin/curl","curl", "-s", "-L", cmdStr.c_str(), NULL);
        }
        // check for zombies again
        waitpid(-1, &status, WNOHANG);

      }
      reply.m_statusList.clear();
    }
  }
 void
 onTimeout(const ndn::Interest& interest)
 {
   std::cout << "onTimeout: " << interest.getName() << std::endl;
 }
Example #16
0
  virtual void
  onInterest(const ndn::InterestFilter& filter, const ndn::Interest& interest)
  {
   
    int dollarfound=0;
    int hashfound=0;
    printf("This doesn't work"); 
    std::cout << "Checking if this works " << interest.getName().size() << std::endl;
    int comp_size=interest.getName().size();
    string last_comp=interest.getName().get(comp_size-1).toUri();
    string check=UriDecode(last_comp);
    cout<<check<<endl;
    cout<<"Last component is "<<last_comp<<endl;
    std::size_t found = check.find("#");   
    if (found!=std::string::npos) 
    {
       hashfound=1;
    }
    found = check.find("$");
    if (found!=std::string::npos)
    {
       dollarfound=1;
    }
    printf("DollarFound:%d and HashFound:%d\n",dollarfound,hashfound);
    std::cout << "Received Interest " << interest << std::endl;

     
    //Creating the file name
    std::shared_ptr<ndn::Data> response(std::make_shared<ndn::Data>(interest.getName()));

 
    if(dollarfound==1)
    {

     int i=0;
     string filename;
     for(i=0;i<comp_size-1;i++)
     { 
        string mid=interest.getName().get(i).toUri();
        string checking=UriDecode(mid);
        filename = filename + '_' +mid;
    }
     char node_name[node_size];
     gethostname(node_name,node_size);
    string node_n=string(node_name);
    node_n.append("-");
    node_n=node_n + filename;
    cout<<node_n<<endl;

   // char data[1000];
    FILE *fp1=fopen(node_n.c_str(),"r+");
    fseek(fp1, 0L, SEEK_END);
    int number_of_segments=0;
    int size= ftell(fp1);



       if(size%MAX_SEG!=0)
      {
       	number_of_segments=(size/MAX_SEG)+1;
      }
      else
      {
       	number_of_segments=(size/MAX_SEG);
      }
      string data1=to_string(number_of_segments);
    //  string data2='$'+data1;
      printf("Number of Segments is =%d\n",number_of_segments);
      response->setContent(reinterpret_cast<const uint8_t*>(data1.c_str()),
                         data1.size());
      fclose(fp1);
     }
    if(hashfound==1){
     int i=0;
     string filename;
     for(i=0;i<comp_size-2;i++)
     {
        string mid=interest.getName().get(i).toUri();
        string checking=UriDecode(mid);
        filename = filename + '_' +mid;
     }
     char node_name[node_size];
     gethostname(node_name,node_size);
    string node_n=string(node_name);
    node_n.append("-");
    node_n=node_n + filename;
    cout<<node_n<<endl;

    char data[1000];
  //  char data[32];
    FILE *fp1=fopen(node_n.c_str(),"r+");
    fseek(fp1, 0L, SEEK_END);
  //  int number_of_segments=0;
    //int size= ftell(fp1);
    int start=0;
    start=stoi(check.substr(1))*MAX_SEG;
    fseek(fp1,start,SEEK_SET);
    memset(&data,0,sizeof(data));
    size_t check=fread(data,MAX_SEG,1,fp1);
    
    if(check==0)
     printf("Error\n");
 //   printf("Data: %s\n",data);
    string msg=string(data);
    response->setContent(reinterpret_cast<const uint8_t*>(data),
                         MAX_SEG);
  //  printf("Size of the outgoing message is:%d",msg.size());
    cout<<msg.c_str()<<endl;
   }
    m_keyChain.sign(*response);
    m_face.put(*response);
  }
Example #17
0
void my_routing::on_timeout( uint32_t error_code, const ndn::Interest& interest)
{
    std::cout << "Request timed out (ErrorCode: " << error_code  << "): " << interest.getName().toUri() << std::endl;
    m_has_error = true;
}