1 #pragma once 2 3 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 4 #if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC 5 6 #include <async_wrap.h> 7 #include <base_object.h> 8 #include <env.h> 9 #include <stream_base.h> 10 #include <deque> 11 12 namespace node { 13 namespace quic { 14 15 // The LogStream is a utility that the QUIC impl uses to publish both QLog 16 // and Keylog diagnostic data (one instance for each). 17 class LogStream : public AsyncWrap, public StreamBase { 18 public: 19 static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( 20 Environment* env); 21 22 static BaseObjectPtr<LogStream> Create(Environment* env); 23 24 LogStream(Environment* env, v8::Local<v8::Object> obj); 25 26 enum class EmitOption { 27 NONE, 28 FIN, 29 }; 30 31 void Emit(const uint8_t* data, 32 size_t len, 33 EmitOption option = EmitOption::NONE); 34 35 void Emit(const std::string_view line, EmitOption option = EmitOption::NONE); 36 37 void End(); 38 39 int ReadStart() override; 40 41 int ReadStop() override; 42 43 // We do not use either of these. 44 int DoShutdown(ShutdownWrap* req_wrap) override; 45 int DoWrite(WriteWrap* w, 46 uv_buf_t* bufs, 47 size_t count, 48 uv_stream_t* send_handle) override; 49 50 bool IsAlive() override; 51 bool IsClosing() override; 52 AsyncWrap* GetAsyncWrap() override; 53 54 void MemoryInfo(MemoryTracker* tracker) const override; 55 SET_MEMORY_INFO_NAME(LogStream) 56 SET_SELF_SIZE(LogStream) 57 58 private: 59 struct Chunk { 60 // len will be <= buf.len 61 size_t len; 62 uv_buf_t buf; 63 }; 64 size_t total_ = 0; 65 bool fin_seen_ = false; 66 bool ended_ = false; 67 bool reading_ = false; 68 std::deque<Chunk> buffer_; 69 70 // The value here is fairly arbitrary. Once we get everything 71 // fully implemented and start working with this, we might 72 // tune this number further. 73 static constexpr size_t kMaxLogStreamBuffer = 1024 * 10; 74 75 // The LogStream buffer enforces a maximum size of kMaxLogStreamBuffer. 76 void ensure_space(size_t amt); 77 }; 78 79 } // namespace quic 80 } // namespace node 81 82 #endif // HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC 83 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 84