Files
roro9stack/src/platform/https_get.h
T
twislaandClaude Sonnet 5.5 510ce42a99 Updates from Gitea, step 3: install from Gitea, and IRC steps aside for it
A release downloads straight into the inactive slot through the existing
install path: the signature is checked after 160 bytes, before anything
is written, the hash at the end. Tried on the device against the real
server: a download cut short, a flipped byte in the signature and one in
the image are each refused with the running firmware untouched; the real
v0.10.0 installed, restarted, and confirmed itself on Probation.

A TLS connection to Gitea peaks at about 52 KB of heap whether or not the
certificate is verified. With IRC connected (66 KB free) a check left 3 KB
and a download 836 bytes. A check, list or install a person asks for now
makes IRC step aside (holdForUpdate) and come back after: the lowest free
heap during a full download with IRC connected is 38 KB. The daily check
never interrupts IRC; with IRC up it waits. A TLS connection starts with
80 KB free (it was 55).

Debug Builds get test knobs: update probe <host>, update damage cut|flip,
update pretend <version>.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
2026-10-06 15:51:10 +02:00

52 lines
1.9 KiB
C++

#pragma once
#include <NetworkClientSecure.h>
#include <memory>
#include <string>
#include "http_head.h"
#include "platform/counted_client.h"
namespace roro {
// One HTTPS GET, read as a stream: the connection checks the server's chain and name against the
// roots in ca_roots.h, the head is parsed, and the body comes out whole whether the server sent it
// with a length or in chunks. Used by the Update Service to read Gitea's answers and to download a
// release. Redirects aren't followed: the device only goes where it was told to (Q163).
class HttpsGet {
public:
// A TLS connection to Gitea peaks at about 52 KB of heap (measured: the same with or without
// checking the certificate); with Q86's 20 KB to spare, it starts with at least this much free.
static constexpr size_t kNeedFree = 80 * 1024;
explicit HttpsGet(net::User user) : tls_(user) {}
~HttpsGet() { close(); }
// Connects and reads the head. "" when a 200 is on its way, or why not, in words for the screen.
std::string open(const std::string& host, const std::string& path, const char* accept);
long contentLength() const { return head_.contentLength; } // -1: not known
// Body bytes into `buf`: how many, 0 at the end, -1 when the connection broke or stalled
// before the end.
int read(uint8_t* buf, size_t len);
void close();
private:
static constexpr size_t kRaw = 1024;
static constexpr uint32_t kStallMs = 10000;
int readRaw(uint8_t* into, size_t len); // from the connection, waiting up to kStallMs
Counted<NetworkClientSecure> tls_;
release::HttpHead head_;
release::ChunkedDecoder chunks_;
std::unique_ptr<uint8_t[]> raw_;
std::string early_; // body bytes that arrived with the head
size_t earlyAt_ = 0;
long left_ = -1; // body bytes still to come, if the server said how many
bool done_ = false;
};
} // namespace roro