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}
This commit is contained in:
honghaiz 2016-03-16 08:55:44 -07:00 committed by Commit bot
parent c4a74e95b5
commit 34b11eb66e
25 changed files with 164 additions and 130 deletions

View File

@ -80,10 +80,14 @@ uint64_t TimeNanos() {
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 @@ int32_t TimeDiff(uint32_t later, uint32_t earlier) {
#endif
}
int64_t TimeDiff64(int64_t later, int64_t earlier) {
return later - earlier;
}
TimestampWrapAroundHandler::TimestampWrapAroundHandler()
: last_ts_(0), num_wrap_(-1) {}

View File

@ -34,8 +34,19 @@ static const int64_t kJan1970AsNtpMillisecs = INT64_C(2208988800000);
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 @@ inline uint32_t TimeMin(uint32_t ts1, uint32_t ts2) {
// 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);

View File

@ -144,6 +144,14 @@ TEST(TimeTest, DISABLED_CurrentTmTime) {
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() {}

View File

@ -205,7 +205,7 @@ class FakeTransportChannel : public TransportChannelImpl,
} 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);
}

View File

@ -1027,7 +1027,7 @@ rtc::DiffServCodePoint P2PTransportChannel::DefaultDscpValue() const {
// 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 @@ void P2PTransportChannel::OnCheckAndPing() {
// 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 @@ bool P2PTransportChannel::IsBackupConnection(Connection* conn) const {
// 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 @@ bool P2PTransportChannel::IsPingable(Connection* conn, uint32_t now) {
// 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 @@ void P2PTransportChannel::PingConnection(Connection* conn) {
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 @@ void P2PTransportChannel::OnReadyToSend(Connection* connection) {
// (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 @@ Connection* P2PTransportChannel::FindOldestConnectionNeedingTriggeredCheck(
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());

View File

@ -220,7 +220,7 @@ class P2PTransportChannel : public TransportChannelImpl,
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 @@ class P2PTransportChannel : public TransportChannelImpl,
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 @@ class P2PTransportChannel : public TransportChannelImpl,
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_;

View File

@ -504,7 +504,8 @@ class P2PTransportChannelTestBase : public testing::Test,
}
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 @@ class P2PTransportChannelTestBase : public testing::Test,
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 @@ class P2PTransportChannelTestBase : public testing::Test,
// 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 @@ class P2PTransportChannelTestBase : public testing::Test,
// 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 @@ TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) {
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 =

View File

@ -32,15 +32,15 @@ namespace {
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 @@ inline bool TooManyFailures(
// 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 @@ inline bool TooLongWithoutResponse(
// 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 @@ Connection::Connection(Port* port,
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 @@ void Connection::OnReadPacket(
// 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 @@ void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) {
*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 @@ void Connection::UpdateState(uint32_t now) {
}
// 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::UpdateState(uint32_t now) {
}
}
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::Ping(uint32_t now) {
void Connection::ReceivedPing() {
set_receiving(true);
last_ping_received_ = rtc::Time();
last_ping_received_ = rtc::Time64();
}
void Connection::ReceivedPingResponse() {
@ -1135,10 +1135,10 @@ void Connection::ReceivedPingResponse() {
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 @@ void Connection::OnConnectionRequestResponse(ConnectionRequest* request,
// 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 @@ void Connection::OnMessage(rtc::Message *pmsg) {
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_));
}

View File

@ -52,26 +52,26 @@ extern const char TCPTYPE_SIMOPEN_STR[];
// 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 @@ class Connection : public rtc::MessageHandler,
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 @@ class Connection : public rtc::MessageHandler,
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 @@ class Connection : public rtc::MessageHandler,
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 @@ class Connection : public rtc::MessageHandler,
// 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 @@ class Connection : public rtc::MessageHandler,
// 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 @@ class Connection : public rtc::MessageHandler,
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 @@ class Connection : public rtc::MessageHandler,
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;

View File

@ -266,7 +266,7 @@ class TestChannel : public sigslot::has_slots<> {
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 @@ TEST_F(PortTest, TestConnectionDead) {
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 @@ TEST_F(PortTest, TestConnectionDead) {
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 @@ TEST_F(PortTest, TestHandleStunBindingIndication) {
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 @@ TEST_F(PortTest, TestWritableState) {
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());

View File

@ -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 @@ class AllocateRequest : public StunRequest {
private:
RelayEntry* entry_;
RelayConnection* connection_;
uint32_t start_time_;
int64_t start_time_;
};
RelayPort::RelayPort(rtc::Thread* thread,
@ -779,7 +779,7 @@ AllocateRequest::AllocateRequest(RelayEntry* entry,
: StunRequest(new RelayMessage()),
entry_(entry),
connection_(connection) {
start_time_ = rtc::Time();
start_time_ = rtc::Time64();
}
void AllocateRequest::Prepare(StunMessage* request) {
@ -834,7 +834,7 @@ void AllocateRequest::OnErrorResponse(StunMessage* response) {
<< " reason='" << attr->reason() << "'";
}
if (rtc::TimeSince(start_time_) <= kRetryTimeout)
if (rtc::Time64() - start_time_ <= kRetryTimeout)
entry_->ScheduleKeepAlive();
}

View File

@ -355,11 +355,12 @@ void RelayServer::HandleStunAllocate(
// 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 @@ const uint32_t MSG_LIFETIME_TIMER = 1;
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::AddExternalConnection(RelayServerConnection* conn) {
}
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 @@ void RelayServerBinding::OnMessage(rtc::Message *pmsg) {
// 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 {

View File

@ -184,11 +184,11 @@ class RelayServerBinding : public rtc::MessageHandler {
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 @@ class RelayServerBinding : public rtc::MessageHandler {
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
};

View File

@ -35,7 +35,7 @@ class StunBindingRequest : public StunRequest {
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 @@ class StunBindingRequest : public StunRequest {
}
// 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 @@ class StunBindingRequest : public StunRequest {
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 @@ class StunBindingRequest : public StunRequest {
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 @@ void UDPPort::SendStunBindingRequest(const rtc::SocketAddress& stun_addr) {
} 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

View File

@ -191,8 +191,8 @@ const StunMessage* StunRequest::msg() const {
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 @@ void StunRequest::OnMessage(rtc::Message* pmsg) {
return;
}
tstamp_ = rtc::Time();
tstamp_ = rtc::Time64();
rtc::ByteBuffer buf;
msg_->Write(&buf);

View File

@ -101,7 +101,7 @@ class StunRequest : public rtc::MessageHandler {
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 @@ class StunRequest : public rtc::MessageHandler {
StunRequestManager* manager_;
StunMessage* msg_;
uint32_t tstamp_;
int64_t tstamp_;
friend class StunRequestManager;
};

View File

@ -146,13 +146,13 @@ TEST_F(StunRequestTest, TestUnexpected) {
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);

View File

@ -145,8 +145,8 @@ class TurnEntry : public sigslot::has_slots<> {
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 @@ class TurnEntry : public sigslot::has_slots<> {
// 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 @@ void TurnPort::DestroyEntry(TurnEntry* entry) {
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::OnConnectionDestroyed(Connection* conn) {
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(),

View File

@ -243,7 +243,7 @@ class TurnPort : public Port {
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);

View File

@ -629,7 +629,7 @@ TEST_F(TurnPortTest, TestTurnAllocateNonceResetAfterAllocateMismatch) {
// 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();

View File

@ -35,7 +35,7 @@ static const int kMinChannelNumber = 0x4000;
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 @@ void TurnServer::HandleAllocateRequest(TurnServerConnection* conn,
}
}
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 @@ bool TurnServer::ValidateNonce(const std::string& nonce) const {
}
// 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 @@ bool TurnServer::ValidateNonce(const std::string& nonce) const {
}
// Validate the timestamp.
return rtc::TimeSince(then) < kNonceTimeout;
return rtc::Time64() - then < kNonceTimeout;
}
TurnServerAllocation* TurnServer::FindAllocation(TurnServerConnection* conn) {
@ -464,7 +465,7 @@ void TurnServer::SendErrorResponseWithRealmAndNonce(
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 @@ void TurnServerAllocation::OnExternalPacket(
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;
}

View File

@ -200,13 +200,13 @@ class TurnServer : public sigslot::has_slots<> {
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 @@ class TurnServer : public sigslot::has_slots<> {
// 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;
};

View File

@ -117,7 +117,7 @@ int main(int argc, char** argv) {
}
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());

View File

@ -161,7 +161,7 @@ void StunProber::Requester::SendStunRequest() {
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::SendStunRequest() {
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 @@ bool StunProber::SendNextRequest() {
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 @@ int StunProber::get_wake_up_interval_ms() {
void StunProber::MaybeScheduleStunRequests() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
uint32_t now = rtc::Time();
int64_t now = rtc::Time64();
if (Done()) {
invoker_.AsyncInvokeDelayed<void>(

View File

@ -184,7 +184,7 @@ class StunProber : public sigslot::has_slots<> {
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 @@ class StunProber : public sigslot::has_slots<> {
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;