dcsctp: Add Heartbeat Handler

It's responsible for answering incoming Heartbeat Requests, and to
send requests itself when a connection is idle. When it receives
a response, it will measure the RTT and if it doesn't receive a response
in time, that will result in a TX error, which will eventually close
the connection.

Bug: webrtc:12614
Change-Id: I08371d9072ff0461f60e0a2f7696c0fd7ccb57c5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214129
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33828}
diff --git a/net/dcsctp/socket/BUILD.gn b/net/dcsctp/socket/BUILD.gn
index 45e911a..8d5bdd8 100644
--- a/net/dcsctp/socket/BUILD.gn
+++ b/net/dcsctp/socket/BUILD.gn
@@ -18,6 +18,21 @@
   ]
 }
 
+rtc_library("heartbeat_handler") {
+  deps = [
+    ":context",
+    "../../../api:array_view",
+    "../../../rtc_base",
+    "../../../rtc_base:checks",
+    "../../../rtc_base:rtc_base_approved",
+    "../public:types",
+  ]
+  sources = [
+    "heartbeat_handler.cc",
+    "heartbeat_handler.h",
+  ]
+}
+
 if (rtc_include_tests) {
   rtc_source_set("mock_callbacks") {
     testonly = true
@@ -37,4 +52,18 @@
       "../public:types",
     ]
   }
+
+  rtc_library("dcsctp_socket_unittests") {
+    testonly = true
+
+    deps = [
+      ":heartbeat_handler",
+      "../../../api:array_view",
+      "../../../rtc_base:checks",
+      "../../../rtc_base:gunit_helpers",
+      "../../../rtc_base:rtc_base_approved",
+      "../../../test:test_support",
+    ]
+    sources = [ "heartbeat_handler_test.cc" ]
+  }
 }