Using 64-bit timestamp to replace the 32-bit one in webrtc/p2p.
Also changed from unsigned to signed integer per the style guide.
By the way, I kept all delta-times to be 32-bit int.
The only things left in the p2p dir are
1. proberprober/main.cc where Time() is used as the input for a random number.
2. pseudotcp.cc: where 32-bit time info is sent over the wire.
BUG=webrtc:5636
Review URL: https://codereview.webrtc.org/1793553002
Cr-Commit-Position: refs/heads/master@{#12019}
diff --git a/webrtc/base/timeutils.cc b/webrtc/base/timeutils.cc
index b7803ae..0c40c52 100644
--- a/webrtc/base/timeutils.cc
+++ b/webrtc/base/timeutils.cc
@@ -80,10 +80,14 @@
return ticks;
}
-uint32_t Time() {
+uint32_t Time32() {
return static_cast<uint32_t>(TimeNanos() / kNumNanosecsPerMillisec);
}
+int64_t Time64() {
+ return static_cast<int64_t>(TimeNanos() / kNumNanosecsPerMillisec);
+}
+
uint64_t TimeMicros() {
return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec);
}
@@ -192,6 +196,10 @@
#endif
}
+int64_t TimeDiff64(int64_t later, int64_t earlier) {
+ return later - earlier;
+}
+
TimestampWrapAroundHandler::TimestampWrapAroundHandler()
: last_ts_(0), num_wrap_(-1) {}
diff --git a/webrtc/base/timeutils.h b/webrtc/base/timeutils.h
index 3ade430..f0269b5 100644
--- a/webrtc/base/timeutils.h
+++ b/webrtc/base/timeutils.h
@@ -34,8 +34,19 @@
typedef uint32_t TimeStamp;
+// Returns the current time in milliseconds in 32 bits.
+uint32_t Time32();
+
+// Returns the current time in milliseconds in 64 bits.
+int64_t Time64();
+
// Returns the current time in milliseconds.
-uint32_t Time();
+// TODO(honghaiz): Returns Time64 once majority of the webrtc code migrates to
+// 64-bit timestamp.
+inline uint32_t Time() {
+ return Time32();
+}
+
// Returns the current time in microseconds.
uint64_t TimeMicros();
// Returns the current time in nanoseconds.
@@ -68,6 +79,10 @@
// timestamps. The value is negative if 'later' occurs before 'earlier'.
int32_t TimeDiff(uint32_t later, uint32_t earlier);
+// Number of milliseconds that would elapse between 'earlier' and 'later'
+// timestamps. The value is negative if 'later' occurs before 'earlier'.
+int64_t TimeDiff64(int64_t later, int64_t earlier);
+
// The number of milliseconds that have elapsed since 'earlier'.
inline int32_t TimeSince(uint32_t earlier) {
return TimeDiff(Time(), earlier);
diff --git a/webrtc/base/timeutils_unittest.cc b/webrtc/base/timeutils_unittest.cc
index 7e342d0..636c408 100644
--- a/webrtc/base/timeutils_unittest.cc
+++ b/webrtc/base/timeutils_unittest.cc
@@ -144,6 +144,14 @@
EXPECT_TRUE(0 <= microseconds && microseconds < 1000000);
}
+TEST(TimeTest, TestTimeDiff64) {
+ int64_t ts_diff = 100;
+ int64_t ts_earlier = rtc::Time64();
+ int64_t ts_later = ts_earlier + ts_diff;
+ EXPECT_EQ(ts_diff, rtc::TimeDiff(ts_later, ts_earlier));
+ EXPECT_EQ(-ts_diff, rtc::TimeDiff(ts_earlier, ts_later));
+}
+
class TimestampWrapAroundHandlerTest : public testing::Test {
public:
TimestampWrapAroundHandlerTest() {}
diff --git a/webrtc/p2p/base/faketransportcontroller.h b/webrtc/p2p/base/faketransportcontroller.h
index ae5e866..d5fbec4 100644
--- a/webrtc/p2p/base/faketransportcontroller.h
+++ b/webrtc/p2p/base/faketransportcontroller.h
@@ -205,7 +205,7 @@
} else {
rtc::Thread::Current()->Send(this, 0, packet);
}
- rtc::SentPacket sent_packet(options.packet_id, rtc::Time());
+ rtc::SentPacket sent_packet(options.packet_id, rtc::Time64());
SignalSentPacket(this, sent_packet);
return static_cast<int>(len);
}
diff --git a/webrtc/p2p/base/p2ptransportchannel.cc b/webrtc/p2p/base/p2ptransportchannel.cc
index cdfcf95..759fd46 100644
--- a/webrtc/p2p/base/p2ptransportchannel.cc
+++ b/webrtc/p2p/base/p2ptransportchannel.cc
@@ -1027,7 +1027,7 @@
// Monitor connection states.
void P2PTransportChannel::UpdateConnectionStates() {
- uint32_t now = rtc::Time();
+ int64_t now = rtc::Time64();
// We need to copy the list of connections since some may delete themselves
// when we call UpdateState.
@@ -1260,7 +1260,7 @@
// When the best connection is either not receiving or not writable,
// switch to weak ping interval.
int ping_interval = weak() ? weak_ping_interval_ : STRONG_PING_INTERVAL;
- if (rtc::Time() >= last_ping_sent_ms_ + ping_interval) {
+ if (rtc::Time64() >= last_ping_sent_ms_ + ping_interval) {
Connection* conn = FindNextPingableConnection();
if (conn) {
PingConnection(conn);
@@ -1281,7 +1281,7 @@
// Is the connection in a state for us to even consider pinging the other side?
// We consider a connection pingable even if it's not connected because that's
// how a TCP connection is kicked into reconnecting on the active side.
-bool P2PTransportChannel::IsPingable(Connection* conn, uint32_t now) {
+bool P2PTransportChannel::IsPingable(Connection* conn, int64_t now) {
const Candidate& remote = conn->remote_candidate();
// We should never get this far with an empty remote ufrag.
ASSERT(!remote.username().empty());
@@ -1319,7 +1319,7 @@
// ping target to become writable instead. See the big comment in
// CompareConnections.
Connection* P2PTransportChannel::FindNextPingableConnection() {
- uint32_t now = rtc::Time();
+ int64_t now = rtc::Time64();
Connection* conn_to_ping = nullptr;
if (best_connection_ && best_connection_->connected() &&
best_connection_->writable() &&
@@ -1360,7 +1360,7 @@
use_candidate = best_connection_->writable();
}
conn->set_use_candidate_attr(use_candidate);
- last_ping_sent_ms_ = rtc::Time();
+ last_ping_sent_ms_ = rtc::Time64();
conn->Ping(last_ping_sent_ms_);
}
@@ -1508,7 +1508,7 @@
// (last_received_ping > last_sent_ping). But we shouldn't do
// triggered checks if the connection is already writable.
Connection* P2PTransportChannel::FindOldestConnectionNeedingTriggeredCheck(
- uint32_t now) {
+ int64_t now) {
Connection* oldest_needing_triggered_check = nullptr;
for (auto conn : connections_) {
if (!IsPingable(conn, now)) {
@@ -1532,7 +1532,7 @@
return oldest_needing_triggered_check;
}
-Connection* P2PTransportChannel::FindConnectionToPing(uint32_t now) {
+Connection* P2PTransportChannel::FindConnectionToPing(int64_t now) {
RTC_CHECK(connections_.size() ==
pinged_connections_.size() + unpinged_connections_.size());
diff --git a/webrtc/p2p/base/p2ptransportchannel.h b/webrtc/p2p/base/p2ptransportchannel.h
index b86389a..04bc951 100644
--- a/webrtc/p2p/base/p2ptransportchannel.h
+++ b/webrtc/p2p/base/p2ptransportchannel.h
@@ -220,7 +220,7 @@
bool IsDuplicateRemoteCandidate(const Candidate& candidate);
void RememberRemoteCandidate(const Candidate& remote_candidate,
PortInterface* origin_port);
- bool IsPingable(Connection* conn, uint32_t now);
+ bool IsPingable(Connection* conn, int64_t now);
void PingConnection(Connection* conn);
void AddAllocatorSession(PortAllocatorSession* session);
void AddConnection(Connection* connection);
@@ -256,8 +256,8 @@
Connection* best_nominated_connection() const;
bool IsBackupConnection(Connection* conn) const;
- Connection* FindConnectionToPing(uint32_t now);
- Connection* FindOldestConnectionNeedingTriggeredCheck(uint32_t now);
+ Connection* FindConnectionToPing(int64_t now);
+ Connection* FindOldestConnectionNeedingTriggeredCheck(int64_t now);
// Between |conn1| and |conn2|, this function returns the one which should
// be pinged first.
Connection* SelectMostPingableConnection(Connection* conn1,
@@ -321,7 +321,7 @@
IceGatheringState gathering_state_;
int check_receiving_interval_;
- uint32_t last_ping_sent_ms_ = 0;
+ int64_t last_ping_sent_ms_ = 0;
int weak_ping_interval_ = WEAK_PING_INTERVAL;
TransportChannelState state_ = TransportChannelState::STATE_INIT;
IceConfig config_;
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
index e083c33..d3332eb 100644
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
@@ -504,7 +504,8 @@
}
void Test(const Result& expected) {
- int32_t connect_start = rtc::Time(), connect_time;
+ int64_t connect_start = rtc::Time64();
+ int64_t connect_time;
// Create the channels and wait for them to connect.
CreateChannels(1);
@@ -516,7 +517,7 @@
ep2_ch1()->writable(),
expected.connect_wait,
1000);
- connect_time = rtc::TimeSince(connect_start);
+ connect_time = rtc::Time64() - connect_start;
if (connect_time < expected.connect_wait) {
LOG(LS_INFO) << "Connect time: " << connect_time << " ms";
} else {
@@ -528,8 +529,9 @@
// This may take up to 2 seconds.
if (ep1_ch1()->best_connection() &&
ep2_ch1()->best_connection()) {
- int32_t converge_start = rtc::Time(), converge_time;
- int converge_wait = 2000;
+ int64_t converge_start = rtc::Time64();
+ int64_t converge_time;
+ int64_t converge_wait = 2000;
EXPECT_TRUE_WAIT_MARGIN(CheckCandidate1(expected), converge_wait,
converge_wait);
// Also do EXPECT_EQ on each part so that failures are more verbose.
@@ -545,7 +547,7 @@
// For verbose
ExpectCandidate2(expected);
- converge_time = rtc::TimeSince(converge_start);
+ converge_time = rtc::Time64() - converge_start;
if (converge_time < converge_wait) {
LOG(LS_INFO) << "Converge time: " << converge_time << " ms";
} else {
@@ -1771,7 +1773,7 @@
ASSERT_EQ(2U, connections.size());
cricket::Connection* backup_conn = connections[1];
EXPECT_TRUE_WAIT(backup_conn->writable(), 3000);
- uint32_t last_ping_response_ms = backup_conn->last_ping_response_received();
+ int64_t last_ping_response_ms = backup_conn->last_ping_response_received();
EXPECT_TRUE_WAIT(
last_ping_response_ms < backup_conn->last_ping_response_received(), 5000);
int time_elapsed =
diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc
index a630695..9207c9d 100644
--- a/webrtc/p2p/base/port.cc
+++ b/webrtc/p2p/base/port.cc
@@ -32,15 +32,15 @@
inline bool TooManyFailures(
const std::vector<cricket::Connection::SentPing>& pings_since_last_response,
uint32_t maximum_failures,
- uint32_t rtt_estimate,
- uint32_t now) {
+ int rtt_estimate,
+ int64_t now) {
// If we haven't sent that many pings, then we can't have failed that many.
if (pings_since_last_response.size() < maximum_failures)
return false;
// Check if the window in which we would expect a response to the ping has
// already elapsed.
- uint32_t expected_response_time =
+ int64_t expected_response_time =
pings_since_last_response[maximum_failures - 1].sent_time + rtt_estimate;
return now > expected_response_time;
}
@@ -48,8 +48,8 @@
// Determines whether we have gone too long without seeing any response.
inline bool TooLongWithoutResponse(
const std::vector<cricket::Connection::SentPing>& pings_since_last_response,
- uint32_t maximum_time,
- uint32_t now) {
+ int64_t maximum_time,
+ int64_t now) {
if (pings_since_last_response.size() == 0)
return false;
@@ -59,15 +59,15 @@
// We will restrict RTT estimates (when used for determining state) to be
// within a reasonable range.
-const uint32_t MINIMUM_RTT = 100; // 0.1 seconds
-const uint32_t MAXIMUM_RTT = 3000; // 3 seconds
+const int MINIMUM_RTT = 100; // 0.1 seconds
+const int MAXIMUM_RTT = 3000; // 3 seconds
// When we don't have any RTT data, we have to pick something reasonable. We
// use a large value just in case the connection is really slow.
-const uint32_t DEFAULT_RTT = MAXIMUM_RTT;
+const int DEFAULT_RTT = MAXIMUM_RTT;
// Computes our estimate of the RTT given the current estimate.
-inline uint32_t ConservativeRTTEstimate(uint32_t rtt) {
+inline int ConservativeRTTEstimate(int rtt) {
return std::max(MINIMUM_RTT, std::min(MAXIMUM_RTT, 2 * rtt));
}
@@ -806,7 +806,7 @@
reported_(false),
state_(STATE_WAITING),
receiving_timeout_(WEAK_CONNECTION_RECEIVE_TIMEOUT),
- time_created_ms_(rtc::Time()) {
+ time_created_ms_(rtc::Time64()) {
// All of our connections start in WAITING state.
// TODO(mallinath) - Start connections from STATE_FROZEN.
// Wire up to send stun packets
@@ -907,7 +907,7 @@
// The packet did not parse as a valid STUN message
// This is a data packet, pass it along.
set_receiving(true);
- last_data_received_ = rtc::Time();
+ last_data_received_ = rtc::Time64();
recv_rate_tracker_.AddSamples(size);
SignalReadPacket(this, data, size, packet_time);
@@ -1045,8 +1045,8 @@
*s = oss.str();
}
-void Connection::UpdateState(uint32_t now) {
- uint32_t rtt = ConservativeRTTEstimate(rtt_);
+void Connection::UpdateState(int64_t now) {
+ int rtt = ConservativeRTTEstimate(rtt_);
if (LOG_CHECK_LEVEL(LS_VERBOSE)) {
std::string pings;
@@ -1102,7 +1102,7 @@
}
// Check the receiving state.
- uint32_t last_recv_time = last_received();
+ int64_t last_recv_time = last_received();
bool receiving = now <= last_recv_time + receiving_timeout_;
set_receiving(receiving);
if (dead(now)) {
@@ -1110,7 +1110,7 @@
}
}
-void Connection::Ping(uint32_t now) {
+void Connection::Ping(int64_t now) {
last_ping_sent_ = now;
ConnectionRequest *req = new ConnectionRequest(this);
pings_since_last_response_.push_back(SentPing(req->id(), now));
@@ -1122,7 +1122,7 @@
void Connection::ReceivedPing() {
set_receiving(true);
- last_ping_received_ = rtc::Time();
+ last_ping_received_ = rtc::Time64();
}
void Connection::ReceivedPingResponse() {
@@ -1135,10 +1135,10 @@
set_write_state(STATE_WRITABLE);
set_state(STATE_SUCCEEDED);
pings_since_last_response_.clear();
- last_ping_response_received_ = rtc::Time();
+ last_ping_response_received_ = rtc::Time64();
}
-bool Connection::dead(uint32_t now) const {
+bool Connection::dead(int64_t now) const {
if (last_received() > 0) {
// If it has ever received anything, we keep it alive until it hasn't
// received anything for DEAD_CONNECTION_RECEIVE_TIMEOUT. This covers the
@@ -1231,7 +1231,7 @@
// connection.
rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE;
- uint32_t rtt = request->Elapsed();
+ int rtt = request->Elapsed();
ReceivedPingResponse();
@@ -1331,7 +1331,7 @@
delete this;
}
-uint32_t Connection::last_received() const {
+int64_t Connection::last_received() const {
return std::max(last_data_received_,
std::max(last_ping_received_, last_ping_response_received_));
}
diff --git a/webrtc/p2p/base/port.h b/webrtc/p2p/base/port.h
index 84600d1..65f82e4 100644
--- a/webrtc/p2p/base/port.h
+++ b/webrtc/p2p/base/port.h
@@ -52,26 +52,26 @@
// The minimum time we will wait before destroying a connection after creating
// it.
-const uint32_t MIN_CONNECTION_LIFETIME = 10 * 1000; // 10 seconds.
+static const int MIN_CONNECTION_LIFETIME = 10 * 1000; // 10 seconds.
// A connection will be declared dead if it has not received anything for this
// long.
-const uint32_t DEAD_CONNECTION_RECEIVE_TIMEOUT = 30 * 1000; // 30 seconds.
+static const int DEAD_CONNECTION_RECEIVE_TIMEOUT = 30 * 1000; // 30 seconds.
// The timeout duration when a connection does not receive anything.
-const uint32_t WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500; // 2.5 seconds
+static const int WEAK_CONNECTION_RECEIVE_TIMEOUT = 2500; // 2.5 seconds
// The length of time we wait before timing out writability on a connection.
-const uint32_t CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds
+static const int CONNECTION_WRITE_TIMEOUT = 15 * 1000; // 15 seconds
// The length of time we wait before we become unwritable.
-const uint32_t CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds
-
-// The number of pings that must fail to respond before we become unwritable.
-const uint32_t CONNECTION_WRITE_CONNECT_FAILURES = 5;
+static const int CONNECTION_WRITE_CONNECT_TIMEOUT = 5 * 1000; // 5 seconds
// This is the length of time that we wait for a ping response to come back.
-const int CONNECTION_RESPONSE_TIMEOUT = 5 * 1000; // 5 seconds
+static const int CONNECTION_RESPONSE_TIMEOUT = 5 * 1000; // 5 seconds
+
+// The number of pings that must fail to respond before we become unwritable.
+static const uint32_t CONNECTION_WRITE_CONNECT_FAILURES = 5;
enum RelayType {
RELAY_GTURN, // Legacy google relay service.
@@ -414,11 +414,11 @@
public sigslot::has_slots<> {
public:
struct SentPing {
- SentPing(const std::string id, uint32_t sent_time)
+ SentPing(const std::string id, int64_t sent_time)
: id(id), sent_time(sent_time) {}
std::string id;
- uint32_t sent_time;
+ int64_t sent_time;
};
// States are from RFC 5245. http://tools.ietf.org/html/rfc5245#section-5.7.4
@@ -463,10 +463,10 @@
return write_state_ != STATE_WRITE_TIMEOUT;
}
// A connection is dead if it can be safely deleted.
- bool dead(uint32_t now) const;
+ bool dead(int64_t now) const;
// Estimate of the round-trip time over this connection.
- uint32_t rtt() const { return rtt_; }
+ int rtt() const { return rtt_; }
size_t sent_total_bytes();
size_t sent_bytes_second();
@@ -520,7 +520,7 @@
remote_ice_mode_ = mode;
}
- void set_receiving_timeout(uint32_t receiving_timeout_ms) {
+ void set_receiving_timeout(int64_t receiving_timeout_ms) {
receiving_timeout_ = receiving_timeout_ms;
}
@@ -532,19 +532,19 @@
// Checks that the state of this connection is up-to-date. The argument is
// the current time, which is compared against various timeouts.
- void UpdateState(uint32_t now);
+ void UpdateState(int64_t now);
// Called when this connection should try checking writability again.
- uint32_t last_ping_sent() const { return last_ping_sent_; }
- void Ping(uint32_t now);
+ int64_t last_ping_sent() const { return last_ping_sent_; }
+ void Ping(int64_t now);
void ReceivedPingResponse();
- uint32_t last_ping_response_received() const {
+ int64_t last_ping_response_received() const {
return last_ping_response_received_;
}
// Called whenever a valid ping is received on this connection. This is
// public because the connection intercepts the first ping for us.
- uint32_t last_ping_received() const { return last_ping_received_; }
+ int64_t last_ping_received() const { return last_ping_received_; }
void ReceivedPing();
// Handles the binding request; sends a response if this is a valid request.
void HandleBindingRequest(IceMessage* msg);
@@ -584,7 +584,7 @@
// Returns the last received time of any data, stun request, or stun
// response in milliseconds
- uint32_t last_received() const;
+ int64_t last_received() const;
protected:
enum { MSG_DELETE = 0, MSG_FIRST_AVAILABLE };
@@ -628,12 +628,12 @@
bool nominated_;
IceMode remote_ice_mode_;
StunRequestManager requests_;
- uint32_t rtt_;
- uint32_t last_ping_sent_; // last time we sent a ping to the other side
- uint32_t last_ping_received_; // last time we received a ping from the other
- // side
- uint32_t last_data_received_;
- uint32_t last_ping_response_received_;
+ int rtt_;
+ int64_t last_ping_sent_; // last time we sent a ping to the other side
+ int64_t last_ping_received_; // last time we received a ping from the other
+ // side
+ int64_t last_data_received_;
+ int64_t last_ping_response_received_;
std::vector<SentPing> pings_since_last_response_;
rtc::RateTracker recv_rate_tracker_;
@@ -648,8 +648,8 @@
bool reported_;
State state_;
// Time duration to switch from receiving to not receiving.
- uint32_t receiving_timeout_;
- uint32_t time_created_ms_;
+ int receiving_timeout_;
+ int64_t time_created_ms_;
friend class Port;
friend class ConnectionRequest;
diff --git a/webrtc/p2p/base/port_unittest.cc b/webrtc/p2p/base/port_unittest.cc
index c47ceaa..be5ced9 100644
--- a/webrtc/p2p/base/port_unittest.cc
+++ b/webrtc/p2p/base/port_unittest.cc
@@ -266,7 +266,7 @@
void Ping() {
Ping(0);
}
- void Ping(uint32_t now) { conn_->Ping(now); }
+ void Ping(int64_t now) { conn_->Ping(now); }
void Stop() {
if (conn_) {
conn_->Destroy();
@@ -1261,9 +1261,9 @@
ASSERT_EQ_WAIT(1, ch2.complete_count(), kTimeout);
// Test case that the connection has never received anything.
- uint32_t before_created = rtc::Time();
+ int64_t before_created = rtc::Time64();
ch1.CreateConnection(GetCandidate(port2));
- uint32_t after_created = rtc::Time();
+ int64_t after_created = rtc::Time64();
Connection* conn = ch1.conn();
ASSERT(conn != nullptr);
// It is not dead if it is after MIN_CONNECTION_LIFETIME but not pruned.
@@ -1284,9 +1284,9 @@
ch1.CreateConnection(GetCandidate(port2));
conn = ch1.conn();
ASSERT(conn != nullptr);
- uint32_t before_last_receiving = rtc::Time();
+ int64_t before_last_receiving = rtc::Time64();
conn->ReceivedPing();
- uint32_t after_last_receiving = rtc::Time();
+ int64_t after_last_receiving = rtc::Time64();
// The connection will be dead after DEAD_CONNECTION_RECEIVE_TIMEOUT
conn->UpdateState(
before_last_receiving + DEAD_CONNECTION_RECEIVE_TIMEOUT - 1);
@@ -2033,13 +2033,13 @@
rtc::PacketTime());
ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000);
EXPECT_EQ(STUN_BINDING_RESPONSE, lport->last_stun_msg()->type());
- uint32_t last_ping_received1 = lconn->last_ping_received();
+ int64_t last_ping_received1 = lconn->last_ping_received();
// Adding a delay of 100ms.
rtc::Thread::Current()->ProcessMessages(100);
// Pinging lconn using stun indication message.
lconn->OnReadPacket(buf->Data(), buf->Length(), rtc::PacketTime());
- uint32_t last_ping_received2 = lconn->last_ping_received();
+ int64_t last_ping_received2 = lconn->last_ping_received();
EXPECT_GT(last_ping_received2, last_ping_received1);
}
@@ -2313,7 +2313,7 @@
for (uint32_t i = 1; i <= CONNECTION_WRITE_CONNECT_FAILURES; ++i) {
ch1.Ping(i);
}
- uint32_t unreliable_timeout_delay = CONNECTION_WRITE_CONNECT_TIMEOUT + 500u;
+ int unreliable_timeout_delay = CONNECTION_WRITE_CONNECT_TIMEOUT + 500;
ch1.conn()->UpdateState(unreliable_timeout_delay);
EXPECT_EQ(Connection::STATE_WRITE_UNRELIABLE, ch1.conn()->write_state());
diff --git a/webrtc/p2p/base/relayport.cc b/webrtc/p2p/base/relayport.cc
index 19883a3..f5ad911 100644
--- a/webrtc/p2p/base/relayport.cc
+++ b/webrtc/p2p/base/relayport.cc
@@ -16,7 +16,7 @@
namespace cricket {
-static const uint32_t kMessageConnectTimeout = 1;
+static const int kMessageConnectTimeout = 1;
static const int kKeepAliveDelay = 10 * 60 * 1000;
static const int kRetryTimeout = 50 * 1000; // ICE says 50 secs
// How long to wait for a socket to connect to remote host in milliseconds
@@ -175,7 +175,7 @@
private:
RelayEntry* entry_;
RelayConnection* connection_;
- uint32_t start_time_;
+ int64_t start_time_;
};
RelayPort::RelayPort(rtc::Thread* thread,
@@ -779,7 +779,7 @@
: StunRequest(new RelayMessage()),
entry_(entry),
connection_(connection) {
- start_time_ = rtc::Time();
+ start_time_ = rtc::Time64();
}
void AllocateRequest::Prepare(StunMessage* request) {
@@ -834,7 +834,7 @@
<< " reason='" << attr->reason() << "'";
}
- if (rtc::TimeSince(start_time_) <= kRetryTimeout)
+ if (rtc::Time64() - start_time_ <= kRetryTimeout)
entry_->ScheduleKeepAlive();
}
diff --git a/webrtc/p2p/base/relayserver.cc b/webrtc/p2p/base/relayserver.cc
index e208d70..aad0070 100644
--- a/webrtc/p2p/base/relayserver.cc
+++ b/webrtc/p2p/base/relayserver.cc
@@ -355,11 +355,12 @@
// else-branch will then disappear.
// Compute the appropriate lifetime for this binding.
- uint32_t lifetime = MAX_LIFETIME;
+ int lifetime = MAX_LIFETIME;
const StunUInt32Attribute* lifetime_attr =
request.GetUInt32(STUN_ATTR_LIFETIME);
if (lifetime_attr)
- lifetime = std::min(lifetime, lifetime_attr->value() * 1000);
+ lifetime =
+ std::min(lifetime, static_cast<int>(lifetime_attr->value() * 1000));
binding = new RelayServerBinding(this, username, "0", lifetime);
binding->SignalTimeout.connect(this, &RelayServer::OnTimeout);
@@ -653,7 +654,7 @@
RelayServerBinding::RelayServerBinding(RelayServer* server,
const std::string& username,
const std::string& password,
- uint32_t lifetime)
+ int lifetime)
: server_(server),
username_(username),
password_(password),
@@ -693,7 +694,7 @@
}
void RelayServerBinding::NoteUsed() {
- last_used_ = rtc::Time();
+ last_used_ = rtc::Time64();
}
bool RelayServerBinding::HasMagicCookie(const char* bytes, size_t size) const {
@@ -734,7 +735,7 @@
// If the lifetime timeout has been exceeded, then send a signal.
// Otherwise, just keep waiting.
- if (rtc::Time() >= last_used_ + lifetime_) {
+ if (rtc::Time64() >= last_used_ + lifetime_) {
LOG(LS_INFO) << "Expiring binding " << username_;
SignalTimeout(this);
} else {
diff --git a/webrtc/p2p/base/relayserver.h b/webrtc/p2p/base/relayserver.h
index f1109f1..7ee71d9 100644
--- a/webrtc/p2p/base/relayserver.h
+++ b/webrtc/p2p/base/relayserver.h
@@ -184,11 +184,11 @@
RelayServerBinding(RelayServer* server,
const std::string& username,
const std::string& password,
- uint32_t lifetime);
+ int lifetime);
virtual ~RelayServerBinding();
RelayServer* server() { return server_; }
- uint32_t lifetime() { return lifetime_; }
+ int lifetime() { return lifetime_; }
const std::string& username() { return username_; }
const std::string& password() { return password_; }
const std::string& magic_cookie() { return magic_cookie_; }
@@ -226,8 +226,8 @@
std::vector<RelayServerConnection*> internal_connections_;
std::vector<RelayServerConnection*> external_connections_;
- uint32_t lifetime_;
- uint32_t last_used_;
+ int lifetime_;
+ int64_t last_used_;
// TODO: bandwidth
};
diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc
index e871a6c..16546fa 100644
--- a/webrtc/p2p/base/stunport.cc
+++ b/webrtc/p2p/base/stunport.cc
@@ -35,7 +35,7 @@
public:
StunBindingRequest(UDPPort* port,
const rtc::SocketAddress& addr,
- uint32_t start_time,
+ int64_t start_time,
int lifetime)
: port_(port),
server_addr_(addr),
@@ -65,7 +65,7 @@
}
// The keep-alive requests will be stopped after its lifetime has passed.
- if (WithinLifetime(rtc::Time())) {
+ if (WithinLifetime(rtc::Time64())) {
port_->requests_.SendDelayed(
new StunBindingRequest(port_, server_addr_, start_time_, lifetime_),
port_->stun_keepalive_delay());
@@ -85,9 +85,9 @@
port_->OnStunBindingOrResolveRequestFailed(server_addr_);
- uint32_t now = rtc::Time();
+ int64_t now = rtc::Time64();
if (WithinLifetime(now) &&
- rtc::TimeDiff(now, start_time_) < RETRY_TIMEOUT) {
+ rtc::TimeDiff64(now, start_time_) < RETRY_TIMEOUT) {
port_->requests_.SendDelayed(
new StunBindingRequest(port_, server_addr_, start_time_, lifetime_),
port_->stun_keepalive_delay());
@@ -104,13 +104,13 @@
private:
// Returns true if |now| is within the lifetime of the request (a negative
// lifetime means infinite).
- bool WithinLifetime(uint32_t now) const {
- return lifetime_ < 0 || rtc::TimeDiff(now, start_time_) <= lifetime_;
+ bool WithinLifetime(int64_t now) const {
+ return lifetime_ < 0 || rtc::TimeDiff64(now, start_time_) <= lifetime_;
}
UDPPort* port_;
const rtc::SocketAddress server_addr_;
- uint32_t start_time_;
+ int64_t start_time_;
// The time duration for which this request will be rescheduled.
int lifetime_;
};
@@ -411,7 +411,7 @@
} else if (socket_->GetState() == rtc::AsyncPacketSocket::STATE_BOUND) {
// Check if |server_addr_| is compatible with the port's ip.
if (IsCompatibleAddress(stun_addr)) {
- requests_.Send(new StunBindingRequest(this, stun_addr, rtc::Time(),
+ requests_.Send(new StunBindingRequest(this, stun_addr, rtc::Time64(),
stun_keepalive_lifetime_));
} else {
// Since we can't send stun messages to the server, we should mark this
diff --git a/webrtc/p2p/base/stunrequest.cc b/webrtc/p2p/base/stunrequest.cc
index 3338861..9ceb6da 100644
--- a/webrtc/p2p/base/stunrequest.cc
+++ b/webrtc/p2p/base/stunrequest.cc
@@ -191,8 +191,8 @@
return msg_;
}
-uint32_t StunRequest::Elapsed() const {
- return rtc::TimeSince(tstamp_);
+int StunRequest::Elapsed() const {
+ return static_cast<int>(rtc::Time64() - tstamp_);
}
@@ -211,7 +211,7 @@
return;
}
- tstamp_ = rtc::Time();
+ tstamp_ = rtc::Time64();
rtc::ByteBuffer buf;
msg_->Write(&buf);
diff --git a/webrtc/p2p/base/stunrequest.h b/webrtc/p2p/base/stunrequest.h
index 4217a81..f6d216d 100644
--- a/webrtc/p2p/base/stunrequest.h
+++ b/webrtc/p2p/base/stunrequest.h
@@ -101,7 +101,7 @@
const StunMessage* msg() const;
// Time elapsed since last send (in ms)
- uint32_t Elapsed() const;
+ int Elapsed() const;
protected:
int count_;
@@ -129,7 +129,7 @@
StunRequestManager* manager_;
StunMessage* msg_;
- uint32_t tstamp_;
+ int64_t tstamp_;
friend class StunRequestManager;
};
diff --git a/webrtc/p2p/base/stunrequest_unittest.cc b/webrtc/p2p/base/stunrequest_unittest.cc
index 8a23834..5e4d256 100644
--- a/webrtc/p2p/base/stunrequest_unittest.cc
+++ b/webrtc/p2p/base/stunrequest_unittest.cc
@@ -146,13 +146,13 @@
TEST_F(StunRequestTest, TestBackoff) {
StunMessage* req = CreateStunMessage(STUN_BINDING_REQUEST, NULL);
- uint32_t start = rtc::Time();
+ int64_t start = rtc::Time64();
manager_.Send(new StunRequestThunker(req, this));
StunMessage* res = CreateStunMessage(STUN_BINDING_RESPONSE, req);
for (int i = 0; i < 9; ++i) {
while (request_count_ == i)
rtc::Thread::Current()->ProcessMessages(1);
- int32_t elapsed = rtc::TimeSince(start);
+ int64_t elapsed = rtc::Time64() - start;
LOG(LS_INFO) << "STUN request #" << (i + 1)
<< " sent at " << elapsed << " ms";
EXPECT_GE(TotalDelay(i + 1), elapsed);
diff --git a/webrtc/p2p/base/turnport.cc b/webrtc/p2p/base/turnport.cc
index 9fa549f..5f719ce 100644
--- a/webrtc/p2p/base/turnport.cc
+++ b/webrtc/p2p/base/turnport.cc
@@ -145,8 +145,8 @@
const rtc::SocketAddress& address() const { return ext_addr_; }
BindState state() const { return state_; }
- uint32_t destruction_timestamp() { return destruction_timestamp_; }
- void set_destruction_timestamp(uint32_t destruction_timestamp) {
+ int64_t destruction_timestamp() { return destruction_timestamp_; }
+ void set_destruction_timestamp(int64_t destruction_timestamp) {
destruction_timestamp_ = destruction_timestamp;
}
@@ -176,7 +176,7 @@
// It is also used as an ID of the event scheduling. When the destruction
// event actually fires, the TurnEntry will be destroyed only if the
// timestamp here matches the one in the firing event.
- uint32_t destruction_timestamp_ = 0;
+ int64_t destruction_timestamp_ = 0;
};
TurnPort::TurnPort(rtc::Thread* thread,
@@ -990,8 +990,7 @@
delete entry;
}
-void TurnPort::DestroyEntryIfNotCancelled(TurnEntry* entry,
- uint32_t timestamp) {
+void TurnPort::DestroyEntryIfNotCancelled(TurnEntry* entry, int64_t timestamp) {
if (!EntryExists(entry)) {
return;
}
@@ -1012,7 +1011,7 @@
void TurnPort::ScheduleEntryDestruction(TurnEntry* entry) {
ASSERT(entry->destruction_timestamp() == 0);
- uint32_t timestamp = rtc::Time();
+ int64_t timestamp = rtc::Time64();
entry->set_destruction_timestamp(timestamp);
invoker_.AsyncInvokeDelayed<void>(
thread(),
diff --git a/webrtc/p2p/base/turnport.h b/webrtc/p2p/base/turnport.h
index da14945..797fa3f 100644
--- a/webrtc/p2p/base/turnport.h
+++ b/webrtc/p2p/base/turnport.h
@@ -243,7 +243,7 @@
void DestroyEntry(TurnEntry* entry);
// Destroys the entry only if |timestamp| matches the destruction timestamp
// in |entry|.
- void DestroyEntryIfNotCancelled(TurnEntry* entry, uint32_t timestamp);
+ void DestroyEntryIfNotCancelled(TurnEntry* entry, int64_t timestamp);
void ScheduleEntryDestruction(TurnEntry* entry);
void CancelEntryDestruction(TurnEntry* entry);
void OnConnectionDestroyed(Connection* conn);
diff --git a/webrtc/p2p/base/turnport_unittest.cc b/webrtc/p2p/base/turnport_unittest.cc
index 9455d17..2c93ead 100644
--- a/webrtc/p2p/base/turnport_unittest.cc
+++ b/webrtc/p2p/base/turnport_unittest.cc
@@ -629,7 +629,7 @@
// using timestamp |ts_before| but then get an allocate mismatch error and
// receive an even newer nonce based on the system clock. |ts_before| is
// chosen so that the two NONCEs generated by the server will be different.
- uint32_t ts_before = rtc::Time() - 1;
+ int64_t ts_before = rtc::Time64() - 1;
std::string first_nonce =
turn_server_.server()->SetTimestampForNextNonce(ts_before);
turn_port_->PrepareAddress();
diff --git a/webrtc/p2p/base/turnserver.cc b/webrtc/p2p/base/turnserver.cc
index 4754574..14dcf05 100644
--- a/webrtc/p2p/base/turnserver.cc
+++ b/webrtc/p2p/base/turnserver.cc
@@ -35,7 +35,7 @@
static const int kMaxChannelNumber = 0x7FFF;
static const size_t kNonceKeySize = 16;
-static const size_t kNonceSize = 40;
+static const size_t kNonceSize = 48;
static const size_t TURN_CHANNEL_HEADER_SIZE = 4U;
@@ -392,12 +392,13 @@
}
}
-std::string TurnServer::GenerateNonce(uint32_t now) const {
+std::string TurnServer::GenerateNonce(int64_t now) const {
// Generate a nonce of the form hex(now + HMAC-MD5(nonce_key_, now))
std::string input(reinterpret_cast<const char*>(&now), sizeof(now));
std::string nonce = rtc::hex_encode(input.c_str(), input.size());
nonce += rtc::ComputeHmac(rtc::DIGEST_MD5, nonce_key_, input);
ASSERT(nonce.size() == kNonceSize);
+
return nonce;
}
@@ -408,7 +409,7 @@
}
// Decode the timestamp.
- uint32_t then;
+ int64_t then;
char* p = reinterpret_cast<char*>(&then);
size_t len = rtc::hex_decode(p, sizeof(then),
nonce.substr(0, sizeof(then) * 2));
@@ -423,7 +424,7 @@
}
// Validate the timestamp.
- return rtc::TimeSince(then) < kNonceTimeout;
+ return rtc::Time64() - then < kNonceTimeout;
}
TurnServerAllocation* TurnServer::FindAllocation(TurnServerConnection* conn) {
@@ -464,7 +465,7 @@
TurnMessage resp;
InitErrorResponse(msg, code, reason, &resp);
- uint32_t timestamp = rtc::Time();
+ int64_t timestamp = rtc::Time64();
if (ts_for_next_nonce_) {
timestamp = ts_for_next_nonce_;
ts_for_next_nonce_ = 0;
@@ -817,10 +818,10 @@
int TurnServerAllocation::ComputeLifetime(const TurnMessage* msg) {
// Return the smaller of our default lifetime and the requested lifetime.
- uint32_t lifetime = kDefaultAllocationTimeout / 1000; // convert to seconds
+ int lifetime = kDefaultAllocationTimeout / 1000; // convert to seconds
const StunUInt32Attribute* lifetime_attr = msg->GetUInt32(STUN_ATTR_LIFETIME);
- if (lifetime_attr && lifetime_attr->value() < lifetime) {
- lifetime = lifetime_attr->value();
+ if (lifetime_attr && static_cast<int>(lifetime_attr->value()) < lifetime) {
+ lifetime = static_cast<int>(lifetime_attr->value());
}
return lifetime;
}
diff --git a/webrtc/p2p/base/turnserver.h b/webrtc/p2p/base/turnserver.h
index 44a8b38..59751a0 100644
--- a/webrtc/p2p/base/turnserver.h
+++ b/webrtc/p2p/base/turnserver.h
@@ -200,13 +200,13 @@
void SetExternalSocketFactory(rtc::PacketSocketFactory* factory,
const rtc::SocketAddress& address);
// For testing only.
- std::string SetTimestampForNextNonce(uint32_t timestamp) {
+ std::string SetTimestampForNextNonce(int64_t timestamp) {
ts_for_next_nonce_ = timestamp;
return GenerateNonce(timestamp);
}
private:
- std::string GenerateNonce(uint32_t now) const;
+ std::string GenerateNonce(int64_t now) const;
void OnInternalPacket(rtc::AsyncPacketSocket* socket, const char* data,
size_t size, const rtc::SocketAddress& address,
const rtc::PacketTime& packet_time);
@@ -277,7 +277,7 @@
// For testing only. If this is non-zero, the next NONCE will be generated
// from this value, and it will be reset to 0 after generating the NONCE.
- uint32_t ts_for_next_nonce_ = 0;
+ int64_t ts_for_next_nonce_ = 0;
friend class TurnServerAllocation;
};
diff --git a/webrtc/p2p/stunprober/main.cc b/webrtc/p2p/stunprober/main.cc
index 076113c..9ef91e0 100644
--- a/webrtc/p2p/stunprober/main.cc
+++ b/webrtc/p2p/stunprober/main.cc
@@ -117,7 +117,7 @@
}
rtc::InitializeSSL();
- rtc::InitRandom(rtc::Time());
+ rtc::InitRandom(rtc::Time32());
rtc::Thread* thread = rtc::ThreadManager::Instance()->WrapCurrentThread();
rtc::scoped_ptr<rtc::BasicPacketSocketFactory> socket_factory(
new rtc::BasicPacketSocketFactory());
diff --git a/webrtc/p2p/stunprober/stunprober.cc b/webrtc/p2p/stunprober/stunprober.cc
index 9316ea8..18628da 100644
--- a/webrtc/p2p/stunprober/stunprober.cc
+++ b/webrtc/p2p/stunprober/stunprober.cc
@@ -161,7 +161,7 @@
return;
}
- request.sent_time_ms = rtc::Time();
+ request.sent_time_ms = rtc::Time64();
num_request_sent_++;
RTC_DCHECK(static_cast<size_t>(num_request_sent_) <= server_ips_.size());
@@ -169,7 +169,7 @@
void StunProber::Requester::Request::ProcessResponse(const char* buf,
size_t buf_len) {
- int64_t now = rtc::Time();
+ int64_t now = rtc::Time64();
rtc::ByteBuffer message(buf, buf_len);
cricket::StunMessage stun_response;
if (!stun_response.Read(&message)) {
@@ -394,7 +394,7 @@
return true;
}
-bool StunProber::should_send_next_request(uint32_t now) {
+bool StunProber::should_send_next_request(int64_t now) {
if (interval_ms_ < THREAD_WAKE_UP_INTERVAL_MS) {
return now >= next_request_time_ms_;
} else {
@@ -412,7 +412,7 @@
void StunProber::MaybeScheduleStunRequests() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
- uint32_t now = rtc::Time();
+ int64_t now = rtc::Time64();
if (Done()) {
invoker_.AsyncInvokeDelayed<void>(
diff --git a/webrtc/p2p/stunprober/stunprober.h b/webrtc/p2p/stunprober/stunprober.h
index b725cbe..44999a2 100644
--- a/webrtc/p2p/stunprober/stunprober.h
+++ b/webrtc/p2p/stunprober/stunprober.h
@@ -184,7 +184,7 @@
requests_per_ip_;
}
- bool should_send_next_request(uint32_t now);
+ bool should_send_next_request(int64_t now);
int get_wake_up_interval_ms();
bool SendNextRequest();
@@ -201,7 +201,7 @@
Requester* current_requester_ = nullptr;
// The time when the next request should go out.
- uint64_t next_request_time_ms_ = 0;
+ int64_t next_request_time_ms_ = 0;
// Total requests sent so far.
uint32_t num_request_sent_ = 0;