当前位置: 首页>>代码示例>>C++>>正文


C++ Link::addDelegation方法代码示例

本文整理汇总了C++中Link::addDelegation方法的典型用法代码示例。如果您正苦于以下问题:C++ Link::addDelegation方法的具体用法?C++ Link::addDelegation怎么用?C++ Link::addDelegation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Link的用法示例。


在下文中一共展示了Link::addDelegation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Name

TEST_F(TestLink, InsertDelegation)
{
  Link link;
  link.setName(Name("test"));
  link.addDelegation(10,  Name("/test1"));
  link.addDelegation(20,  Name("/test2"));
  link.addDelegation(100, Name("/test3"));

  link.addDelegation(30, Name("/test4"));
  const DelegationSet& delegations = link.getDelegations();
  for (size_t i = 0; i < delegations.size(); ++i) {
    if (i == 0) {
      ASSERT_EQ(10, delegations.get(i).getPreference());
      ASSERT_EQ(Name("/test1"), delegations.get(i).getName());
    }
    if (i == 1) {
      ASSERT_EQ(20, delegations.get(i).getPreference());
      ASSERT_EQ(Name("/test2"), delegations.get(i).getName());
    }
    if (i == 2) {
      ASSERT_EQ(30, delegations.get(i).getPreference());
      ASSERT_EQ(Name("/test4"), delegations.get(i).getName());
    }
    if (i == 3) {
      ASSERT_EQ(100, delegations.get(i).getPreference());
      ASSERT_EQ(Name("/test3"), delegations.get(i).getName());
    }
  }
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例2: prefix

TEST_F(TestProducer, ProducerWithLink)
{
  Name prefix("/prefix");
  Name suffix("/suffix");
  Name expectedInterest = prefix;
  expectedInterest.append(Encryptor::getNAME_COMPONENT_READ());
  expectedInterest.append(suffix);
  expectedInterest.append(Encryptor::getNAME_COMPONENT_E_KEY());

  MillisecondsSince1970 testTime = fromIsoString("20150101T100001");

  int timeoutCount = 0;

  // Prepare a TestFace to instantly answer calls to expressInterest.
  class TestFace : public Face {
  public:
    TestFace(const Name& expectedInterest, int* timeoutCount)
    : Face("localhost"),
      expectedInterest_(expectedInterest),
      timeoutCount_(timeoutCount)
    {}

    virtual uint64_t
    expressInterest
      (const Interest& interest, const OnData& onData,
       const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
       WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
    {
      if (expectedInterest_ != interest.getName())
        throw runtime_error("TestFace::expressInterest: Not the expectedInterest_");
      if (interest.getLink()->getDelegations().size() != 3)
        throw runtime_error
          ("TestFace::expressInterest: The Interest link does not the expected number of delegates");
      ++(*timeoutCount_);
      onTimeout(ptr_lib::make_shared<Interest>(interest));

      return 0;
    }

  private:
    Name expectedInterest_;
    int* timeoutCount_;
  };

  TestFace face(expectedInterest, &timeoutCount);

  // Verify that if no response is received, the producer appropriately times
  // out. The result vector should not contain elements that have timed out.
  Link link;
  link.addDelegation(10,  Name("/test1"));
  link.addDelegation(20,  Name("/test2"));
  link.addDelegation(100, Name("/test3"));
  keyChain->sign(link);
  ptr_lib::shared_ptr<ProducerDb> testDb(new Sqlite3ProducerDb(databaseFilePath));
  Producer producer(prefix, suffix, &face, keyChain.get(), testDb, 3, link);
  producer.createContentKey
    (testTime,
     bind(&TestProducer::keyTimeoutOnEncryptedKeys, this, _1, &timeoutCount));
}
开发者ID:,项目名称:,代码行数:59,代码来源:

示例3: if

TEST_F(TestConsumer, CosumerWithLink)
{
  ptr_lib::shared_ptr<Data> contentData = createEncryptedContent();
  ptr_lib::shared_ptr<Data> cKeyData = createEncryptedCKey();
  ptr_lib::shared_ptr<Data> dKeyData = createEncryptedDKey();

  int contentCount = 0;
  int cKeyCount = 0;
  int dKeyCount = 0;

  // Prepare a TestFace to instantly answer calls to expressInterest.
  class TestFace : public Face {
  public:
    TestFace(ptr_lib::shared_ptr<Data> contentData,
             ptr_lib::shared_ptr<Data> cKeyData,
             ptr_lib::shared_ptr<Data> dKeyData,
             int* contentCount, int* cKeyCount, int* dKeyCount)
    : Face("localhost"),
      contentData_(contentData),
      cKeyData_(cKeyData),
      dKeyData_(dKeyData),
      contentCount_(contentCount),
      cKeyCount_(cKeyCount),
      dKeyCount_(dKeyCount)
    {}

    virtual uint64_t
    expressInterest
      (const Interest& interest, const OnData& onData,
       const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack,
       WireFormat& wireFormat = *WireFormat::getDefaultWireFormat())
    {
      if (interest.getLink()->getDelegations().size() != 3)
        throw runtime_error
          ("TestFace::expressInterest: The Interest link does not the expected number of delegates");

      if (interest.matchesName(contentData_->getName())) {
        *contentCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), contentData_);
      }
      else if (interest.matchesName(cKeyData_->getName())) {
        *cKeyCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), cKeyData_);
      }
      else if (interest.matchesName(dKeyData_->getName())) {
        *dKeyCount_ = 1;
        onData(ptr_lib::make_shared<Interest>(interest), dKeyData_);
      }
      else
        onTimeout(ptr_lib::make_shared<Interest>(interest));

      return 0;
    }

  private:
    ptr_lib::shared_ptr<Data> contentData_;
    ptr_lib::shared_ptr<Data> cKeyData_;
    ptr_lib::shared_ptr<Data> dKeyData_;

    int* contentCount_;
    int* cKeyCount_;
    int* dKeyCount_;
  };

  TestFace face
    (contentData, cKeyData, dKeyData, &contentCount, &cKeyCount, &dKeyCount);

  // Create the consumer.
  Link ckeyLink;
  ckeyLink.addDelegation(10,  Name("/ckey1"));
  ckeyLink.addDelegation(20,  Name("/ckey2"));
  ckeyLink.addDelegation(100, Name("/ckey13"));
  Link dkeyLink;
  dkeyLink.addDelegation(10,  Name("/dkey1"));
  dkeyLink.addDelegation(20,  Name("/dkey2"));
  dkeyLink.addDelegation(100, Name("/dkey13"));
  Link dataLink;
  dataLink.addDelegation(10,  Name("/data1"));
  dataLink.addDelegation(20,  Name("/data2"));
  dataLink.addDelegation(100, Name("/data13"));
  keyChain->sign(ckeyLink);
  keyChain->sign(dkeyLink);
  keyChain->sign(dataLink);

  Consumer consumer
    (&face, keyChain.get(), groupName, uName,
     ptr_lib::make_shared<Sqlite3ConsumerDb>(databaseFilePath),
     ckeyLink, dkeyLink);
  consumer.addDecryptionKey(uKeyName, fixtureUDKeyBlob);

  int finalCount = 0;
  consumer.consume
    (contentName,
     bind(&TestConsumer::onConsumeComplete, this, _1, _2, &finalCount),
     bind(&TestConsumer::onError, this, _1, _2), dataLink);

  ASSERT_EQ(1, contentCount);
  ASSERT_EQ(1, cKeyCount);
  ASSERT_EQ(1, dKeyCount);
  ASSERT_EQ(1, finalCount);
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的Link::addDelegation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。