From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from [192.168.88.254] (unknown [125.160.110.187]) by gnuweeb.org (Postfix) with ESMTPSA id A70EC8057F; Thu, 25 Aug 2022 09:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1661420457; bh=M3MdZm580fnekUiqYfKJtG33BrNq5frsYHvY4dISNW4=; h=Date:To:Cc:From:Subject:From; b=eqqg/Iz89FW0uLzGymt/HYsVXN2D50jS0qwjfjPinQpSQ95jqyNzpMX1p3vbAWJik Td2be3jZM4VMxsO0U0YpaMluEPUvV1tnK+xuB2eMaaRWtr6PlRNheiJ6QAS2M81cdZ 6lfBvnocDvJPfWr1/WhfdQhr01Wmr8mGj7iFm+MB5/s0v52Hsfv3L+PVKxuOIgXXia sGRIMzNLHURNbwRDJE5uTbngR+1OzK9DM5kWhITZtw58KA4sLM/e47Xb0aG5rml0TV WQx0zjrf95lDiZoioBWn42HPLWMp8DPG3pINuSiUi92b9d8JoHmj2AASlxQZkFnqJn 2RdzqcIzsrhXw== Message-ID: <78e1a565-e450-61d8-47b3-87920131cfda@gnuweeb.org> Date: Thu, 25 Aug 2022 16:40:47 +0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Alviro Iskandar Setiawan Cc: Kanna Scarlet , Muhammad Rizki , GNU/Weeb Mailing List From: Ammar Faizi Subject: [GIT PULL] ncns update (chunked request body support) Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: Hi Alviro, Sorry for sending you a pull request directly this time. I am in a rush and don't have much time to get this sorted. I spent my day debugging this. So in a non-chunked request, the body is fully written before the request even goes in a connected state. So the calling sequence for a non-chunked request is: -> CreateNet() -> SetURL() -> SetRequestHeader() -> SetPayload() # request body goes here -> Start() in SQE --- cr on connected --- cr on response started -> Read() in SQE --- cr on read completed But in a chunked request, the body should be fully written before we wait for "on response started" from the Chromium net event. This is because HTTP works that way. The request should go first before the client waits for the response. The calling sequence that made the SQE stuck was like this: -> CreateNet() -> SetURL() -> SetRequestHeader() -> StartChunkedBody() -> Start() in SQE --- cr on connected --- the ring waits for "on response started" -> Write() -> Write() -> Write() -> Write() -> Write() -> Read() in SQE -> Write() -> Write() --- wait for "on read completed" ^^^ stuck here That calling sequence is wrong, because the read will never complete before the data stream class in the Chromium reaches its EOF (IOW, the SetIsFinalChunk() [1] is called). That being said, implies "wait for 'on read completed'" must only be done after the write operation has finished. I guess between Friday and Saturday I can ship this feature properly. Please pull! [1]: https://source.chromium.org/chromium/chromium/src/+/109fd67d081a16dc8564bd15c146a78f4e068559:net/base/upload_data_stream.h;l=119-121 The following changes since commit 7914975d89b6cb947de27b17df13b2f4830197a1: Merge branch 'dev.ring_cleanup' (2022-08-18 05:48:50 +0700) are available in the Git repository at: https://gitlab.torproject.org/ammarfaizi2/ncns.git tags/chnet_body_chunked.2022-08-25 for you to fetch changes up to 77bbcc903899016f3e99ce499ded2056cea77a03: chnet: Completely refactor again (2022-08-25 15:51:30 +0700) ---------------------------------------------------------------- chnet_body_chunked.2022-08-25 ---------------------------------------------------------------- Ammar Faizi (23): chnet: Add initial request body support chnet: node: Add set_user_data support on SQE tests/js/ring: Update the unit test to utilize set_user_data binding.gyp: Add `-ggdb3` flag for better debugging experience binding.gyp: Add `-Wno-enum-constexpr-conversion` flag chnet: node: Add set_method function to set HTTP method chnet: node: Add get_error function to return the error string chnet: node: Add set_payload function to set HTTP req body tests/js/ring: Add simple HTTP POST request example in NodeJS chnet: Split construct URL req creation into a new function chnet: Add set request header support chnet: node: Fix unused variable warning chnet: node: Add set request header function in NodeJS tests/js/ring: Add more set header function test chnet: node: Don't use static counter for data ID tests/js/ring: Add JavaScript class wrapper example chnet: Initial chunked request body support chnet: Rework the chunked request body interface chnet: ring: Refactor the ring completely chnet: Use busy-waiting for signal waiter chnet: ring: Bump max_entry to 2G tests/cpp: Delete basic.cpp as it's no longer relevant chnet: Completely refactor again binding.gyp | 4 +- chnet/WorkQueue.cc | 17 +- chnet/WorkQueue.h | 5 + chnet/chnet.cc | 239 +++++++++++++---- chnet/chnet.h | 215 +++++++++++++-- chnet/chnet.old.cc | 582 ++++++++++++++++++++++++++++++++++++++++ chnet/chnet.old.h | 236 ++++++++++++++++ chnet/chnet_node.cc | 564 +++++++++++++++++++++++++++++--------- chnet/chnet_node.h | 6 - chnet/chnet_ring.cc | 493 ++++++++++++++++------------------ chnet/chnet_ring.h | 200 ++++++++------ chnet/common.h | 20 +- tests/cpp/basic.cc | 97 ------- tests/cpp/ring.cc | 536 +++++++++++++++++++++++++++++------- tests/index.php | 14 + tests/js/ring.js | 405 ++++++++++++++++++++++++---- 16 files changed, 2797 insertions(+), 836 deletions(-) create mode 100644 chnet/chnet.old.cc create mode 100644 chnet/chnet.old.h delete mode 100644 tests/cpp/basic.cc -- Ammar Faizi