Make ID of datachannel stats not depend on dc.id
The ID of stats was based on the datachannel's "id"
attribute, but that could change - it was -1 before ID
allocation, and a number afterwards.
This CL changes the stats ID to depend on a monotonically
increasing counter for allocated datachannels.
Bug: webrtc:10842
Change-Id: I3e0c5dc07df8a7a502396de06bbedc9f676994a0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/147642
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28720}
diff --git a/pc/data_channel.h b/pc/data_channel.h
index e4166dd..728226c 100644
--- a/pc/data_channel.h
+++ b/pc/data_channel.h
@@ -142,6 +142,7 @@
virtual std::string protocol() const { return config_.protocol; }
virtual bool negotiated() const { return config_.negotiated; }
virtual int id() const { return config_.id; }
+ virtual int internal_id() const { return internal_id_; }
virtual uint64_t buffered_amount() const;
virtual void Close();
virtual DataState state() const { return state_; }
@@ -214,6 +215,10 @@
// channel's sid is free.
sigslot::signal1<DataChannel*> SignalClosed;
+ // Reset the allocator for internal ID values for testing, so that
+ // the internal IDs generated are predictable. Test only.
+ static void ResetInternalIdAllocatorForTesting(int new_value);
+
protected:
DataChannel(DataChannelProviderInterface* client,
cricket::DataChannelType dct,
@@ -267,6 +272,7 @@
void QueueControlMessage(const rtc::CopyOnWriteBuffer& buffer);
bool SendControlMessage(const rtc::CopyOnWriteBuffer& buffer);
+ const int internal_id_;
std::string label_;
InternalDataChannelInit config_;
DataChannelObserver* observer_;