Merge tag '0.10.0' into upgrade

quiche 0.10.0

* tag '0.10.0': (262 commits)
  0.10.0
  qlog: update docs and bump to 0.5.0
  recovery: introduce pacing rate multiplier
  recovery: name time conversion constant
  frame: parse ACKs with ECN counts
  Revert "zero-copy emit scatter API"
  avoid counting reset streams' unsent data towards flow control limit
  add method to check if stream can hold more data
  http3_test: silence unused field warnings
  nginx: link to libm to fix build failure
  deps: bump BoringSSL submodule
  build: drop support for building with Android NDK < 19
  recovery: hystart++ draft 03
  zero-copy emit scatter API
  h3: rename max_header_list to max_field_section
  examples: fix invalid pointer bugs
  allow to query if the connection was timed out
  expose local_error to applications
  add method to return the server name requested by the client
  qlog: update to qlog 02, support event importance levels
  ...

Change-Id: I205aa6aa81542ef169b0194d12e50a9d3400295b
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 0000000..28c2370
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,59 @@
+# Copyright 2019 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/rust/rustc_library.gni")
+
+# Ignore warnings because this is third-party code.
+config("ignore_rust_warnings") {
+  rustflags = [ "-Awarnings" ]
+}
+
+rustc_library("quiche") {
+  name = "quiche"
+  edition = "2018"
+  configs -= [
+    "//build/config/rust:2018_idioms",
+    "//build/config:werror",
+  ]
+  configs += [ ":ignore_rust_warnings" ]
+  deps = [
+    "//third_party/rust_crates:lazy_static",
+    "//third_party/rust_crates:libc",
+    "//third_party/rust_crates:libm",
+    "//third_party/rust_crates:log",
+    "//third_party/rust_crates:ring",
+  ]
+  non_rust_deps = [ "//third_party/boringssl" ]
+
+  sources = [
+    "src/crypto.rs",
+    "src/dgram.rs",
+    "src/ffi.rs",
+    "src/frame.rs",
+    "src/h3/ffi.rs",
+    "src/h3/frame.rs",
+    "src/h3/mod.rs",
+    "src/h3/qpack/decoder.rs",
+    "src/h3/qpack/encoder.rs",
+    "src/h3/qpack/huffman/mod.rs",
+    "src/h3/qpack/huffman/table.rs",
+    "src/h3/qpack/mod.rs",
+    "src/h3/qpack/static_table.rs",
+    "src/h3/stream.rs",
+    "src/lib.rs",
+    "src/minmax.rs",
+    "src/octets.rs",
+    "src/packet.rs",
+    "src/rand.rs",
+    "src/ranges.rs",
+    "src/recovery/cubic.rs",
+    "src/recovery/delivery_rate.rs",
+    "src/recovery/hystart.rs",
+    "src/recovery/mod.rs",
+    "src/recovery/prr.rs",
+    "src/recovery/reno.rs",
+    "src/stream.rs",
+    "src/tls.rs",
+  ]
+}
diff --git a/src/ffi.rs b/src/ffi.rs
index 8ad32d5..34fd68b 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -74,11 +74,11 @@
 
 use crate::*;
 
-#[no_mangle]
-pub extern fn quiche_version() -> *const u8 {
-    static VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "\0");
-    VERSION.as_ptr()
-}
+// #[no_mangle]
+// pub extern fn quiche_version() -> *const u8 {
+//     static VERSION: &str = concat!(env!("CARGO_PKG_VERSION"), "\0");
+//     VERSION.as_ptr()
+// }
 
 struct Logger {
     cb: extern fn(line: *const u8, argp: *mut c_void),
diff --git a/src/lib.rs b/src/lib.rs
index 2808b92..d8be83d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4966,6 +4966,7 @@
                     Ok(v) => v,
 
                     Err(Error::Done) => return Ok(()),
+                    Err(Error::InvalidStreamState) => return Ok(()),
 
                     Err(e) => return Err(e),
                 };
@@ -5044,6 +5045,7 @@
                     Ok(v) => v,
 
                     Err(Error::Done) => return Ok(()),
+                    Err(Error::InvalidStreamState) => return Ok(()),
 
                     Err(e) => return Err(e),
                 };
@@ -5095,6 +5097,7 @@
                     Ok(v) => v,
 
                     Err(Error::Done) => return Ok(()),
+                    Err(Error::InvalidStreamState) => return Ok(()),
 
                     Err(e) => return Err(e),
                 };
diff --git a/src/stream.rs b/src/stream.rs
index b96391b..5984228 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -29,7 +29,6 @@
 use std::sync::Arc;
 
 use std::collections::hash_map;
-
 use std::collections::BTreeMap;
 use std::collections::BinaryHeap;
 use std::collections::HashMap;
@@ -104,19 +103,19 @@
     /// Set of stream IDs corresponding to streams that have outstanding data
     /// to read. This is used to generate a `StreamIter` of streams without
     /// having to iterate over the full list of streams.
-    readable: HashSet<u64>,
+    readable: BTreeSet<u64>,
 
     /// Set of stream IDs corresponding to streams that have enough flow control
     /// capacity to be written to, and is not finished. This is used to generate
     /// a `StreamIter` of streams without having to iterate over the full list
     /// of streams.
-    writable: HashSet<u64>,
+    writable: BTreeSet<u64>,
 
     /// Set of stream IDs corresponding to streams that are almost out of flow
     /// control credit and need to send MAX_STREAM_DATA. This is used to
     /// generate a `StreamIter` of streams without having to iterate over the
     /// full list of streams.
-    almost_full: HashSet<u64>,
+    almost_full: BTreeSet<u64>,
 
     /// Set of stream IDs corresponding to streams that are blocked. The value
     /// of the map elements represents the offset of the stream at which the
@@ -655,7 +654,7 @@
     #[inline]
     fn from(streams: &HashSet<u64>) -> Self {
         StreamIter {
-            streams: streams.iter().copied().collect(),
+            streams: streams.iter().rev().copied().collect(),
         }
     }
 }
diff --git a/src/tls.rs b/src/tls.rs
index 25354ef..3111ea1 100644
--- a/src/tls.rs
+++ b/src/tls.rs
@@ -1070,6 +1070,8 @@
     trace!("{}", std::str::from_utf8(&err).unwrap());
 }
 
+#[link(name = "ssl")]
+#[link(name = "crypto")]
 extern {
     // SSL_METHOD
     fn TLS_method() -> *const SSL_METHOD;