Sort messages between nodes properly

We used to assume the realtime clocks were in sync.  This isn't
realistic.  Use the timestamps on forwarded messages in each
direction to observe the network latency and the offset between nodes.

Since time is no longer exactly linear with all the adjustments, we need
to redo how events are scheduled.  They can't be converted to the
distributed_clock once.  They need to now be converted every time they
are compared between nodes.

Change-Id: I1888c1e6a12f475c321a73aa020b0dc0bab107b3
diff --git a/aos/network/BUILD b/aos/network/BUILD
index a334a47..11eebdb 100644
--- a/aos/network/BUILD
+++ b/aos/network/BUILD
@@ -271,8 +271,8 @@
 
 cc_library(
     name = "web_proxy",
-    hdrs = ["web_proxy.h"],
     srcs = ["web_proxy.cc"],
+    hdrs = ["web_proxy.h"],
     copts = [
         "-DWEBRTC_POSIX",
         "-Wno-unused-parameter",
@@ -283,8 +283,8 @@
         ":web_proxy_utils",
         "//aos/events:shm_event_loop",
         "//aos/seasocks:seasocks_logger",
-        "//third_party/seasocks",
         "//third_party:webrtc",
+        "//third_party/seasocks",
         "@com_github_google_glog//:glog",
     ],
 )
@@ -321,3 +321,22 @@
         "//aos/events:pingpong_config.json",
     ],
 )
+
+cc_library(
+    name = "timestamp_filter",
+    hdrs = ["timestamp_filter.h"],
+    deps = [
+        "//aos/time",
+    ],
+)
+
+cc_test(
+    name = "timestamp_filter_test",
+    srcs = [
+        "timestamp_filter_test.cc",
+    ],
+    deps = [
+        ":timestamp_filter",
+        "//aos/testing:googletest",
+    ],
+)