int main(void)
{
  printf("%.2lf\n", interest(1000, 0.05, 25));
  printf("%.2lf\n", interest(10000, 0.04, -12));
  printf("%lf\n", powerindian(1.0000000001, 1000000000));
  printf("%lf\n", powerindian_loop(1.0000000001, 2000000000));

  return 0;
}
inline lp::Nack
makeNack(const Name& name, uint32_t nonce, lp::NackReason reason)
{
  Interest interest(name);
  interest.setNonce(nonce);
  return makeNack(interest, reason);
}
示例#3
0
void generator_node_t::do_calc_defined( const render::context_t& context)
{
    //if( crop_to_format())
    set_defined( ImathExt::intersect( bounds(), interest()));
    //else
    //set_defined( interest()); // infinite images
}
示例#4
0
void set_matte_node_t::do_calc_defined( const render::render_context_t& context)
{
    if( get_value<bool>( param( "premultiply")))
	set_defined( intersect( input(0)->defined(), intersect( input(1)->defined(), interest())));
    else
	set_defined( input(0)->defined());
}
示例#5
0
void lens_distort_node_t::do_calc_inputs_interest( const render::context_t& context)
{
	image_node_t *in = input_as<image_node_t>();	 
	Imath::Box2i roi = ImathExt::intersect( interest(), bounds());

	switch( get_value<int>( param( "model")))
	{
		case syntheyes_model:
		{
			if( get_value<int>( param( "mode")) == undistort)
				roi = undistort_box( roi);
			else
				roi = redistort_box( roi);
		}
		break;
	};
	
	// add a small margin for filtering
	roi.min.x -= 1;
	roi.min.y -= 1;
	
	if( get_value<int>( param( "filter")) == bilinear)
	{
		roi.max.x += 1;
		roi.max.y += 1;
	}
	else
	{
		roi.max.x += 3;
		roi.max.y += 3;
	}

	in->add_interest( roi);
}
示例#6
0
void
MulticastDiscovery::requestHubData()
{
  Interest interest(LOCALHOP_HUB_DISCOVERY_PREFIX);
  interest.setInterestLifetime(time::milliseconds(4000)); // 4 seconds
  interest.setMustBeFresh(true);

  m_face.expressInterest(interest,
                         bind(&MulticastDiscovery::onSuccess, this, _2),
                         bind(m_nextStageOnFailure, "Timeout"));
}
示例#7
0
 void
 fetchFibEnumerationInformation()
 {
   Name interestName("/localhost/nfd/fib/list");
   Interest interest(interestName);
   interest.setChildSelector(1);
   interest.setMustBeFresh(true);
   m_face.expressInterest(
     interest,
     func_lib::bind(&NfdStatus::onData, this, _1, _2, "FIBDataRequest"),
     func_lib::bind(&NfdStatus::onTimeout, this, _1, "FIBDataRequest"));
 }
示例#8
0
    //------------------------------------------------------------------------
    RiskyFloatingBond::RiskyFloatingBond(
                            std::string name,
                            Currency ccy,
                            Real recoveryRate,
                            Handle<DefaultProbabilityTermStructure> defaultTS,
                            Schedule schedule,
                            boost::shared_ptr<IborIndex> index,
                            Integer fixingDays,
                            Real spread,
                            std::vector<Real> notionals,
                            Handle<YieldTermStructure> yieldTS,
                            Natural settlementDays)
    : RiskyBond(name, ccy, recoveryRate, defaultTS, yieldTS,
                settlementDays, schedule.calendar()),
          schedule_(schedule),
          index_(index),
          fixingDays_(fixingDays),
          spread_(spread),
          notionals_(notionals) {

        // FIXME: Take paymentConvention into account
        std::vector<Date> dates = schedule_.dates();
        Real previousNotional = notionals_.front();
        for (Size i = 1; i < dates.size(); i++) {
            Real currentNotional = (i < notionals_.size() ?
                             notionals_[i] :
                             notionals_.back());
            boost::shared_ptr<CashFlow> interest (new
                   IborCoupon(dates[i], previousNotional, dates[i-1], dates[i],
                              fixingDays_, index_, 1.0, spread_));
            boost::shared_ptr<CashFlow> amortization(new
                 AmortizingPayment(previousNotional - currentNotional, dates[i]));
            previousNotional = currentNotional;

            leg_.push_back(interest);
            interestLeg_.push_back(interest);
            if (amortization->amount() != 0){
                leg_.push_back(amortization);
                redemptionLeg_.push_back(amortization);
            }
        }

        boost::shared_ptr<CashFlow> redemption(new
                 Redemption(previousNotional, schedule_.dates().back()));
        leg_.push_back(redemption);
        redemptionLeg_.push_back(redemption);

        boost::shared_ptr<IborCouponPricer>
            fictitiousPricer(new
                BlackIborCouponPricer(Handle<OptionletVolatilityStructure>()));
        setCouponPricer(leg_,fictitiousPricer);
    }
示例#9
0
void my_routing::show_strategy()
{
    ndn::Interest interest("/localhost/nfd/strategy-choice/list");
    interest.setChildSelector(1);
    interest.setMustBeFresh(true);

    ndn::util::SegmentFetcher::fetch(m_face, interest,
                                     m_validator,
                                     std::bind(&my_routing::show_strategy_data, this, _1),
                                     std::bind(&my_routing::on_timeout, this, _1, interest));

    m_face.processEvents();
}
示例#10
0
void
SegmentFetcher::fetchFirstSegment(const Interest& baseInterest, bool isRetransmission)
{
  Interest interest(baseInterest);
  interest.setCanBePrefix(true);
  interest.setMustBeFresh(true);
  interest.setInterestLifetime(m_options.interestLifetime);
  if (isRetransmission) {
    interest.refreshNonce();
  }

  sendInterest(0, interest, isRetransmission);
}
  void
  delayedInterest()
  {
    std::cout << "One more Interest, delayed by the scheduler" << std::endl;

    Interest interest(Name("/example/testApp/randomData"));
    interest.setInterestLifetime(time::milliseconds(1000));
    interest.setMustBeFresh(true);

    m_face.expressInterest(interest,
                           bind(&ConsumerWithTimer::onData, this, _1, _2),
                           bind(&ConsumerWithTimer::onTimeout, this, _1));

    std::cout << "Sending " << interest << std::endl;
  }
示例#12
0
void
RibManager::fetchActiveFaces()
{
  NFD_LOG_DEBUG("Fetching active faces");

  Interest interest(FACES_LIST_DATASET_PREFIX);
  interest.setChildSelector(1);
  interest.setMustBeFresh(true);

  shared_ptr<ndn::OBufferStream> buffer = make_shared<ndn::OBufferStream>();

  m_face.expressInterest(interest,
                         bind(&RibManager::fetchSegments, this, _2, buffer),
                         bind(&RibManager::onFetchFaceStatusTimeout, this));
}
示例#13
0
void my_routing::show_interfaces()
{
    ndn::Interest interest("/localhost/nfd/faces/list");
    interest.setChildSelector(1);
    interest.setMustBeFresh(true);

    ndn::util::SegmentFetcher::fetch(m_face, interest,
                                     m_validator,
                                     std::bind(&my_routing::show_interfaces_data, this, _1),
                                     //std::bind(&my_routing::on_timeout, this, _1, interest));
                                     std::bind(&my_routing::on_error, this, _1, _2, "/localhost/nfd/faces/list"));

//void my_routing::on_error(uint32_t error_code, const std::string& error, const std::string& message)
    m_face.processEvents();
}
示例#14
0
  void
  run()
  {
    Interest interest(Name("/runner/1")); ///example/testApp/randomData   /nist/antd/img/1
    interest.setInterestLifetime(ndn::time::milliseconds(2000));
    interest.setMustBeFresh(true);

    m_face.expressInterest(interest,
                           bind(&User::onData, this,  _1, _2),
                           bind(&User::onTimeout, this, _1));

    std::cout << "Sending " << interest << std::endl;

    // processEvents will block until the requested data received or timeout occurs
    m_face.processEvents();
  }
示例#15
0
文件: nlsrc.cpp 项目: named-data/NLSR
void
Nlsrc::fetchFromLsdb(const ndn::Name::Component& datasetType,
                     const std::function<void(const T&)>& recordLsa)
{
    ndn::Name command = LSDB_PREFIX;
    command.append(datasetType);

    ndn::Interest interest(command);

    ndn::util::SegmentFetcher::fetch(m_face,
                                     interest,
                                     m_validator,
                                     std::bind(&Nlsrc::onFetchSuccess<T>,
                                             this, _1, recordLsa),
                                     std::bind(&Nlsrc::onTimeout, this, _1, _2));
}
    void
    fetchFaceStatusInformation(Name& remoteInterestName)
    {
        shared_ptr<OBufferStream> buffer = make_shared<OBufferStream>();

        Interest interest("/localhost/nfd/faces/list");
        interest.setChildSelector(0);
        interest.setMustBeFresh(true);

        m_face.expressInterest(interest,
                               bind(&NdnMapClient::fetchSegments, this, _2, buffer, remoteInterestName,
                                    &NdnMapClient::afterFetchedFaceStatusInformation),
                               bind(&NdnMapClient::onTimeout, this, _1));

        m_face.processEvents(time::milliseconds(100));
    }
示例#17
0
    //------------------------------------------------------------------------
    RiskyFixedBond::RiskyFixedBond(
                            const std::string& name,
                            const Currency& ccy,
                            Real recoveryRate,
                            const Handle<DefaultProbabilityTermStructure>& defaultTS,
                            const Schedule& schedule,
                            Real rate,
                            const DayCounter& dayCounter,
                            BusinessDayConvention paymentConvention,
                            const std::vector<Real>& notionals,
                            const Handle<YieldTermStructure>& yieldTS,
                            Natural settlementDays)
    : RiskyBond(name, ccy, recoveryRate, defaultTS, yieldTS,
                settlementDays, schedule.calendar()),
          schedule_(schedule),
          rate_(rate),
          dayCounter_(dayCounter),
          // paymentConvention_(paymentConvention),
          notionals_(notionals) {
        // FIXME: Take paymentConvention into account
        std::vector<Date> dates = schedule_.dates();
        Real previousNotional = notionals_.front();
        for (Size i = 1; i < dates.size(); i++) {
            Real currentNotional = (i < notionals_.size() ?
                             notionals_[i] :
                             notionals_.back());
            boost::shared_ptr<CashFlow> interest (new
                   FixedRateCoupon(dates[i], previousNotional,
                                   rate_, dayCounter_, dates[i-1], dates[i]));
            boost::shared_ptr<CashFlow> amortization(new
                 AmortizingPayment(previousNotional - currentNotional, dates[i]));
            previousNotional = currentNotional;

            leg_.push_back(interest);
            interestLeg_.push_back(interest);
            if (amortization->amount() != 0){
                leg_.push_back(amortization);
                redemptionLeg_.push_back(amortization);
            }
        }

        boost::shared_ptr<CashFlow> redemption(new
                 Redemption(previousNotional, schedule_.dates().back()));
        leg_.push_back(redemption);
        redemptionLeg_.push_back(redemption);
    }
示例#18
0
void
SegmentFetcher::fetchSegmentsInWindow(const Interest& origInterest)
{
  if (checkAllSegmentsReceived()) {
    // All segments have been retrieved
    return finalizeFetch();
  }

  int64_t availableWindowSize = static_cast<int64_t>(m_cwnd) - m_nSegmentsInFlight;
  std::vector<std::pair<uint64_t, bool>> segmentsToRequest; // The boolean indicates whether a retx or not

  while (availableWindowSize > 0) {
    if (!m_retxQueue.empty()) {
      auto pendingSegmentIt = m_pendingSegments.find(m_retxQueue.front());
      m_retxQueue.pop();
      if (pendingSegmentIt == m_pendingSegments.end()) {
        // Skip re-requesting this segment, since it was received after RTO timeout
        continue;
      }
      BOOST_ASSERT(pendingSegmentIt->second.state == SegmentState::InRetxQueue);
      segmentsToRequest.emplace_back(pendingSegmentIt->first, true);
    }
    else if (m_nSegments == 0 || m_nextSegmentNum < static_cast<uint64_t>(m_nSegments)) {
      if (m_receivedSegments.count(m_nextSegmentNum) > 0) {
        // Don't request a segment a second time if received in response to first "discovery" Interest
        m_nextSegmentNum++;
        continue;
      }
      segmentsToRequest.emplace_back(m_nextSegmentNum++, false);
    }
    else {
      break;
    }
    availableWindowSize--;
  }

  for (const auto& segment : segmentsToRequest) {
    Interest interest(origInterest); // to preserve Interest elements
    interest.setName(Name(m_versionedDataName).appendSegment(segment.first));
    interest.setCanBePrefix(false);
    interest.setMustBeFresh(false);
    interest.setInterestLifetime(m_options.interestLifetime);
    interest.refreshNonce();
    sendInterest(segment.first, interest, segment.second);
  }
}
示例#19
0
  IdentityCertificate
  run(const Name &name)
  {
	    
    Interest interest(name);
    interest.setInterestLifetime(time::milliseconds(2000));
    interest.setMustBeFresh(true);

    m_face.expressInterest(interest,
                           bind(&CertificateFetcher::onData, this,  _1, _2),
                           bind(&CertificateFetcher::onTimeout, this, _1));

    std::cout << "Fetching certificate... " << interest << std::endl;

    // processEvents will block until the requested data received or timeout occurs
    m_face.processEvents();
    return certificate;
  }
示例#20
0
文件: nlsrc.cpp 项目: named-data/NLSR
void
Nlsrc::sendNamePrefixUpdate(const ndn::Name& name,
                            const ndn::Name::Component& verb,
                            const std::string& info)
{
    ndn::nfd::ControlParameters parameters;
    parameters.setName(name);

    ndn::Name commandName = NAME_UPDATE_PREFIX;
    commandName.append(verb);

    ndn::Interest interest(commandName.append(parameters.wireEncode()));
    interest.setMustBeFresh(true);
    m_keyChain.sign(interest);

    m_face.expressInterest(interest,
                           std::bind(&Nlsrc::onControlResponse, this, info, _2),
                           std::bind(&Nlsrc::onTimeout, this, ERROR_CODE_TIMEOUT, "Timeout"));
}
示例#21
0
void
Socket::fetchData(const Name& sessionName, const SeqNo& seqNo,
                  const ndn::OnDataValidated& dataCallback,
                  int nRetries)
{
  Name interestName;
  interestName.append(sessionName).appendNumber(seqNo);

  Interest interest(interestName);
  interest.setMustBeFresh(true);

  ndn::OnDataValidationFailed failureCallback =
    bind(&Socket::onDataValidationFailed, this, _1, _2);

  m_face.expressInterest(interest,
                         bind(&Socket::onData, this, _1, _2, dataCallback, failureCallback),
                         bind(&Socket::onDataTimeout, this, _1, nRetries,
                              dataCallback, failureCallback));
}
示例#22
0
void
ClientFace::receiveElement(const Block& block)
{
  if (block.type() == tlv::Interest) {
    Interest interest(block);

    Nack nack;
    if (nack.decode(interest)) {
      this->receiveNack(nack);
    }
    else {
      this->receiveInterest(interest);
    }
  }
  else if (block.type() == tlv::Data) {
    Data data(block);
    this->receiveData(data);
  }
}
示例#23
0
void
Socket::fetchData(const Name& sessionName, const SeqNo& seqNo,
                  const ndn::OnDataValidated& dataCallback,
                  const ndn::OnDataValidationFailed& failureCallback,
                  const ndn::OnTimeout& onTimeout,
                  int nRetries)
{
  _LOG_DEBUG(">> Socket::fetchData");
  Name interestName;
  interestName.append(sessionName).appendNumber(seqNo);

  Interest interest(interestName);
  interest.setMustBeFresh(true);

  m_face.expressInterest(interest,
                         bind(&Socket::onData, this, _1, _2, dataCallback, failureCallback),
                         onTimeout);

  _LOG_DEBUG("<< Socket::fetchData");
}
void
SimpleDataRetrieval::sendInterest()
{
  Name prefix;
  m_context->getContextOption(PREFIX, prefix);
  
  Name suffix;
  m_context->getContextOption(SUFFIX, suffix);
  
  if (!suffix.empty())
  {
    prefix.append(suffix);
  }

  Interest interest(prefix);
  
  int interestLifetime = 0;
  m_context->getContextOption(INTEREST_LIFETIME, interestLifetime);
  interest.setInterestLifetime(time::milliseconds(interestLifetime));
  
  SelectorHelper::applySelectors(interest, m_context);
  
  ConsumerInterestCallback onInterestToLeaveContext = EMPTY_CALLBACK;
  m_context->getContextOption(INTEREST_LEAVE_CNTX, onInterestToLeaveContext);
  if (onInterestToLeaveContext != EMPTY_CALLBACK)
  {
    onInterestToLeaveContext(*dynamic_cast<Consumer*>(m_context), interest);
  }
  
  m_face->expressInterest(interest,
                          bind(&SimpleDataRetrieval::onData, this, _1, _2),
                          bind(&SimpleDataRetrieval::onTimeout, this, _1));
  
  bool isAsync = false;
  m_context->getContextOption(ASYNC_MODE, isAsync);
  
  if (!isAsync)
  {
    m_face->processEvents();
  }
}
示例#25
0
void distortx_node_t::do_calc_inputs_interest( const render::context_t& context)
{
    Imath::V2f amplitude = get_value<Imath::V2f>( param( "amplitude"));

    Imath::Box2i roi( interest());
    
    if( input( 1))
        input_as<image_node_t>( 1)->add_interest( roi);

	image_node_t *in = input_as<image_node_t>( 0);
	
	if( get_value<int>( param( "borders")) == border_black)
	{
	    roi.min.x -= amplitude.x;
	    roi.min.y -= amplitude.y;
	    roi.max.x += amplitude.x;
	    roi.max.y += amplitude.y;
	    in->add_interest( roi);
	}
	else
		in->add_interest( in->format());
}
示例#26
0
void
WriteHandle::segInit(ProcessId processId, const RepoCommandParameter& parameter)
{
  // use SegmentFetcher to send fetch interest.
  ProcessInfo& process = m_processes[processId];
  Name name = parameter.getName();
  SegmentNo startBlockId = parameter.getStartBlockId();

  uint64_t initialCredit = m_credit;

  if (parameter.hasEndBlockId()) {
    initialCredit =
      std::min(initialCredit, parameter.getEndBlockId() - parameter.getStartBlockId() + 1);
  }
  else {
    // set noEndTimeout timer
    process.noEndTime = ndn::time::steady_clock::now() +
                        m_noEndTimeout;
  }

  Name fetchName = name;
  SegmentNo segment = startBlockId;
  fetchName.appendSegment(segment);
  Interest interest(fetchName);

  ndn::util::SegmentFetcher::Options options;
  options.initCwnd = initialCredit;
  options.interestLifetime = m_interestLifetime;
  options.maxTimeout = m_maxTimeout;
  auto fetcher = ndn::util::SegmentFetcher::start(face, interest, m_validator, options);
  fetcher->onError.connect([] (uint32_t errorCode, const std::string& errorMsg)
                           {NDN_LOG_ERROR("Error: " << errorMsg);});
  fetcher->afterSegmentValidated.connect([this, &fetcher, &processId] (const Data& data)
                                         {onSegmentData(*fetcher, data, processId);});
  fetcher->afterSegmentTimedOut.connect([this, &fetcher, &processId] ()
                                        {onSegmentTimeout(*fetcher, processId);});
}
void
PipelineInterests::sendFirstInterest()
{
  // get around the excluded segment
  if (m_nextSegmentNo == m_excludeSegmentNo)
    m_nextSegmentNo++;

  if (m_hasFinalBlockId && m_nextSegmentNo > m_lastSegmentNo)
    return;

  // Send the first interest to initialize RTT measurement
  if (m_options.isVerbose)
    std::cerr << "Requesting the first segment #" << m_nextSegmentNo << std::endl;

  Interest interest(Name(m_prefix).appendSegment(m_nextSegmentNo));
  interest.setInterestLifetime(m_options.interestLifetime);
  interest.setMustBeFresh(m_options.mustBeFresh);
  interest.setMaxSuffixComponents(1);

  auto interestId = m_face.expressInterest(interest,
                                           bind(&PipelineInterests::handleDataFirstSegment,
                                                this, _1, _2),
                                           bind(&PipelineInterests::handleNack, this, _1, _2),
                                           bind(&PipelineInterests::handleLifeTimeExpiration,
                                                this, _1));

  SegmentState state = firstTimeSent;
  auto segInfo = shared_ptr<SegmentInfo>(new SegmentInfo(interestId,
                                                         state,
                                                         m_options.initialRto,
                                                         time::steady_clock::now()));

  m_segmentInfoMap[m_nextSegmentNo] = segInfo;
  m_inFlight++;
  m_nextSegmentNo++;
}
  void
  run()
  {
    Interest interest(Name("/example/testApp/randomData"));
    interest.setInterestLifetime(time::seconds(1));
    interest.setMustBeFresh(true);

    m_face.expressInterest(interest,
                           bind(&ConsumerWithTimer::onData, this, _1, _2),
                           bind(&ConsumerWithTimer::onTimeout, this, _1));

    std::cout << "Sending " << interest << std::endl;

    // Schedule a new event
    m_scheduler.scheduleEvent(time::seconds(2),
                              bind(&ConsumerWithTimer::delayedInterest, this));

    // m_ioService.run() will block until all events finished or m_ioService.stop() is called
    m_ioService.run();

    // Alternatively, m_face.processEvents() can also be called.
    // processEvents will block until the requested data received or timeout occurs.
    // m_face.processEvents();
  }
示例#29
0
void MyMoneyForecast::calculateAutoLoan(const MyMoneySchedule& schedule, MyMoneyTransaction& transaction, const QMap<QString, MyMoneyMoney>& balances)
{
  if (schedule.type() == MyMoneySchedule::TYPE_LOANPAYMENT) {

    //get amortization and interest autoCalc splits
    MyMoneySplit amortizationSplit = transaction.amortizationSplit();
    MyMoneySplit interestSplit = transaction.interestSplit();

    if(!amortizationSplit.id().isEmpty() && !interestSplit.id().isEmpty()) {
      MyMoneyAccountLoan acc(MyMoneyFile::instance()->account(amortizationSplit.accountId()));
      MyMoneyFinancialCalculator calc;
      QDate dueDate;

      // FIXME: setup dueDate according to when the interest should be calculated
      // current implementation: take the date of the next payment according to
      // the schedule. If the calculation is based on the payment reception, and
      // the payment is overdue then take the current date
      dueDate = schedule.nextDueDate();
      if(acc.interestCalculation() == MyMoneyAccountLoan::paymentReceived) {
        if(dueDate < QDate::currentDate())
          dueDate = QDate::currentDate();
      }

      // we need to calculate the balance at the time the payment is due

      MyMoneyMoney balance;
      if(balances.count() == 0)
        balance = MyMoneyFile::instance()->balance(acc.id(), dueDate.addDays(-1));
      else
        balance = balances[acc.id()];

      /*
         QValueList<MyMoneyTransaction> list;
         QValueList<MyMoneyTransaction>::ConstIterator it;
         MyMoneySplit split;
         MyMoneyTransactionFilter filter(acc.id());

         filter.setDateFilter(QDate(), dueDate.addDays(-1));
         list = MyMoneyFile::instance()->transactionList(filter);

         for(it = list.begin(); it != list.end(); ++it) {
         try {
         split = (*it).splitByAccount(acc.id());
         balance += split.value();

         } catch(MyMoneyException *e) {
      // account is not referenced within this transaction
      delete e;
      }
      }
      */

      // FIXME: for now, we only support interest calculation at the end of the period
      calc.setBep();
      // FIXME: for now, we only support periodic compounding
      calc.setDisc();

      calc.setPF(MyMoneySchedule::eventsPerYear(schedule.occurence()));
      MyMoneySchedule::occurenceE compoundingOccurence = static_cast<MyMoneySchedule::occurenceE>(acc.interestCompounding());
      if(compoundingOccurence == MyMoneySchedule::OCCUR_ANY)
        compoundingOccurence = schedule.occurence();

      calc.setCF(MyMoneySchedule::eventsPerYear(compoundingOccurence));

      calc.setPv(balance.toDouble());
      calc.setIr(static_cast<FCALC_DOUBLE> (acc.interestRate(dueDate).abs().toDouble()));
      calc.setPmt(acc.periodicPayment().toDouble());

      MyMoneyMoney interest(calc.interestDue()), amortization;
      interest = interest.abs();    // make sure it's positive for now
      amortization = acc.periodicPayment() - interest;

      if(acc.accountType() == MyMoneyAccount::AssetLoan) {
        interest = -interest;
        amortization = -amortization;
      }

      amortizationSplit.setShares(amortization);
      interestSplit.setShares(interest);

      // FIXME: for now we only assume loans to be in the currency of the transaction
      amortizationSplit.setValue(amortization);
      interestSplit.setValue(interest);

      transaction.modifySplit(amortizationSplit);
      transaction.modifySplit(interestSplit);
    }
  }
}
void
PipelineInterests::sendInterest(uint64_t segno, bool is_retransmission)
{
  // get around the excluded segment
  if (m_nextSegmentNo == m_excludeSegmentNo)
    m_nextSegmentNo++;

  if (m_hasFinalBlockId && m_nextSegmentNo > m_lastSegmentNo)
    return;

  if (m_options.isVerbose) {
    if (is_retransmission)
      std::cerr << "Retransmitting the segment #" << segno << std::endl;
    else
      std::cerr << "Requesting the segment #" << segno << std::endl;
  }

  if (is_retransmission) {
    auto it = m_retxCountMap.find(segno);
    if (it == m_retxCountMap.end()) { // not found, first retransmission
      m_retxCountMap[segno] = 1;
    } else {
      if (m_retxCountMap[segno] > m_options.maxRetriesOnTimeoutOrNack) {
        fail("Reached the maximum number of timeout retries (" +
             to_string(m_options.maxRetriesOnTimeoutOrNack) +
             ") while retrieving segment " + to_string(segno));
        return;
      }
      m_retxCountMap[segno] += 1;

      if (m_options.isVerbose) {
        std::cerr << "# of retries for the segment #" << segno
                  << " is "<< m_retxCountMap[segno] << std::endl;
      }
    }

    m_face.removePendingInterest(m_segmentInfoMap[segno]->interestId);
  }

  Interest interest(Name(m_prefix).appendSegment(segno));
  interest.setInterestLifetime(m_options.interestLifetime);
  interest.setMustBeFresh(m_options.mustBeFresh);
  interest.setMaxSuffixComponents(1);

  auto interestId = m_face.expressInterest(interest,
                                           bind(&PipelineInterests::handleData, this, _1, _2),
                                           bind(&PipelineInterests::handleNack, this, _1, _2),
                                           bind(&PipelineInterests::handleLifeTimeExpiration,
                                                this, _1));

  SegmentState state;
  if (is_retransmission) {
    m_segmentInfoMap[segno]->state = retransmitted;
    m_segmentInfoMap[segno]->rto = m_rttEstimator.estimatedRto();
    m_segmentInfoMap[segno]->timeSent = time::steady_clock::now();
    m_numOfSegmentRetransmitted++;
  }
  else {
    m_highInterest = segno;
    state = firstTimeSent;

    auto segInfo = shared_ptr<SegmentInfo>(new SegmentInfo(interestId,
                                                           state,
                                                           m_rttEstimator.estimatedRto(),
                                                           time::steady_clock::now()));
    m_segmentInfoMap[segno] = segInfo;
  }

  m_inFlight++;
}