Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2014 Named Data Networking Project |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #include "pit-face-record.hpp" |
| 8 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 9 | namespace nfd { |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 10 | namespace pit { |
| 11 | |
| 12 | FaceRecord::FaceRecord(shared_ptr<Face> face) |
| 13 | : m_face(face) |
| 14 | , m_lastNonce(0) |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 15 | , m_lastRenewed(time::steady_clock::TimePoint::min()) |
| 16 | , m_expiry(time::steady_clock::TimePoint::min()) |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 17 | { |
| 18 | } |
| 19 | |
| 20 | FaceRecord::FaceRecord(const FaceRecord& other) |
| 21 | : m_face(other.m_face) |
| 22 | , m_lastNonce(other.m_lastNonce) |
| 23 | , m_lastRenewed(other.m_lastRenewed) |
| 24 | , m_expiry(other.m_expiry) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | void |
| 29 | FaceRecord::update(const Interest& interest) |
| 30 | { |
| 31 | m_lastNonce = interest.getNonce(); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 32 | m_lastRenewed = time::steady_clock::now(); |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 33 | |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 34 | static const time::milliseconds DEFAULT_INTEREST_LIFETIME = time::milliseconds(4000); |
| 35 | time::milliseconds lifetime = interest.getInterestLifetime(); |
| 36 | if (lifetime < time::milliseconds::zero()) { |
Junxiao Shi | 57f0f31 | 2014-03-16 11:52:20 -0700 | [diff] [blame] | 37 | lifetime = DEFAULT_INTEREST_LIFETIME; |
| 38 | } |
| 39 | m_expiry = m_lastRenewed + time::milliseconds(lifetime); |
Junxiao Shi | cbba04c | 2014-01-26 14:21:22 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | |
| 43 | } // namespace pit |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 44 | } // namespace nfd |