collabora-online/common/Common.hpp

100 lines
3.8 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string>
deltas: track, transmit and cache deltas (disabled for now) Squashed from feature/deltas-expanded. TileCache changes: + add montonic sequence (wid) numbers to TileData + account for sizes of TileData with multiple blobs + simplify saving and notifying of tiles Sends updates (via appendChanges) based on the sequence the right mix of keyframes and/or deltas required as a single message, and parse and apply those on the JS side. We continue to use PNG for slide previews and dialogs, but remove PngCache - used by document tiles only. Annotates delta: properly as a binary package for the websocket. Distinguishes between deltas and keyframes we get from the Kit based on an initial un-compressed prefix character which we then discard. kit can be forced to render a keyframe by oldWid=0 Track invalidity on tiles themselves - to keep the keyframe around. We need to be able to track that a tile is invalid, and so subscribe to the updated version as/when it is ready - but we also want to store the keyframe underneath any deltas. force rendering of a keyframe for an empty slot in the TileCache. force tile sequence to be zero for combinedtiles - so the client can always request standalone tiles with explicit combinedtiles, or tile requests. move Blob to Common.hpp use zero size for un-changed tiles. remove obsolete render-id, and color deltas in debug mode. cleanup unit tests for non-png tile results. Change-Id: I987f84ac4e58004758a243c233b19a6f0d60f8c2 Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-03-25 19:32:01 +01:00
#include <vector>
#include <memory>
// Default values and other shared data between processes.
constexpr int DEFAULT_CLIENT_PORT_NUMBER = 9980;
// define to wrap strace around the forkit
#define STRACE_COOLFORKIT 0
// define to wrap valgrind around the forkit
#define VALGRIND_COOLFORKIT 0
#if VALGRIND_COOLFORKIT
constexpr int TRACE_MULTIPLIER = 20;
#elif CODE_COVERAGE
constexpr int TRACE_MULTIPLIER = 5;
#else
constexpr int TRACE_MULTIPLIER = 1;
#endif
constexpr int COMMAND_TIMEOUT_SECS = 5 * TRACE_MULTIPLIER;
constexpr int COMMAND_TIMEOUT_MS = COMMAND_TIMEOUT_SECS * 1000;
constexpr int CHILD_TIMEOUT_MS = COMMAND_TIMEOUT_MS;
constexpr int CHILD_REBALANCE_INTERVAL_MS = CHILD_TIMEOUT_MS / 10;
constexpr int POLL_TIMEOUT_MICRO_S = (COMMAND_TIMEOUT_MS / 5) * 1000;
constexpr int WS_SEND_TIMEOUT_MS = 1000 * TRACE_MULTIPLIER;
constexpr int TILE_ROUNDTRIP_TIMEOUT_MS = COMMAND_TIMEOUT_MS;
/// Pipe and Socket read buffer size.
/// Should be large enough for ethernet packets
/// which can be 1500 bytes long.
constexpr long READ_BUFFER_SIZE = 64 * 1024;
/// Message larger than this will be dropped as invalid
/// or as intentionally flooding the server.
constexpr int MAX_MESSAGE_SIZE = 2 * 1024 * READ_BUFFER_SIZE;
wsd: faster jail setup via bind-mount loolmount now works and supports mounting and unmounting, plus numerous improvements, refactoring, logging, etc.. When enabled, binding improves the jail setup time by anywhere from 2x to orders of magnitude (in docker, f.e.). A new config entry mount_jail_tree controls whether mounting is used or the old method of linking/copying of jail contents. It is set to true by default and falls back to linking/copying. A test mount is done when the setting is enabled, and if mounting fails, it's disabled to avoid noise. Temporarily disabled for unit-tests until we can cleanup lingering mounts after Jenkins aborts our build job. In a future patch we will have mount/jail cleanup as part of make. The network/system files in /etc that need frequent refreshing are now updated in systemplate to make their most recent version available in the jails. These files can change during the course of loolwsd lifetime, and are unlikely to be updated in systemplate after installation at all. We link to them in the systemplate/etc directory, and if that fails, we copy them before forking each kit instance to have the latest. This reworks the approach used to bind-mount the jails and the templates such that the total is now down to only three mounts: systemplate, lo, tmp. As now systemplate and lotemplate are shared, they must be mounted as readonly, this means that user/ must now be moved into tmp/user/ which is writable. The mount-points must be recursive, because we mount lo/ within the mount-point of systemplate (which is the root of the jail). But because we (re)bind recursively, and because both systemplate and lotemplate are mounted for each jails, we need to make them unbindable, so they wouldn't multiply the mount-points for each jails (an explosive growth!) Contrarywise, we don't want the mount-points to be shared, because we don't expect to add/remove mounts after a jail is created. The random temp directory is now created and set correctly, plus many logging and other improvements. Change-Id: Iae3fda5e876cf47d2cae6669a87b5b826a8748df Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92829 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-04-09 15:02:58 +02:00
constexpr const char JAILED_DOCUMENT_ROOT[] = "/tmp/user/docs/";
constexpr const char CHILD_URI[] = "/coolws/child?";
constexpr const char NEW_CHILD_URI[] = "/coolws/newchild";
constexpr const char FORKIT_URI[] = "/coolws/forkit";
constexpr const char CAPABILITIES_END_POINT[] = "/hosting/capabilities";
/// The file suffix used to mark the file slated for uploading.
constexpr const char TO_UPLOAD_SUFFIX[] = ".upload";
/// The file suffix used to mark the file being uploaded.
constexpr const char UPLOADING_SUFFIX[] = "ing";
wsd: use a shared threadname suffix for each document The use of a common threadname suffix in the WSD and Kit processes is intentional. It is designed to help filter for a single document's logs across both processes. The thread name has nothing to do with the classes in the code, nor is it intended to imply any relationship except with the process and the document in question. As the comment in this patch explains, the choice of the suffix is arbitrary and while it may be changed, it has to be sensible and common between the two threads to allow for easy grepping. Historically, there were in fact dedicated threads within the respective "broker" classes, but this fact should be safely ignored, since at the log level we care less about which part of the code generates a log entry (that info, if needed, is at the end of each log entry, in the form of filename and line number), rather we care more about which document it relates to, which is crucial in investigating production issues. Logs and code structure are only incidentally related. Logs are (or at least should be) designed around the execution structure, not code architecture. (This reverts 2a16f34812cf69bbe0f21b7e7d048fdb3271fa9d) Change-Id: Ic6fe2f9425998824774d2644fe4362e75dea6b88 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/101261 Tested-by: Jenkins Tested-by: Tor Lillqvist <tml@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-08-24 06:17:49 +02:00
/// A shared threadname suffix in both the WSD and Kit processes
/// is highly helpful for filtering the logs for the same document
/// by simply grepping for this shared suffix+ID. e.g. 'grep "broker_123" coolwsd.log'
wsd: use a shared threadname suffix for each document The use of a common threadname suffix in the WSD and Kit processes is intentional. It is designed to help filter for a single document's logs across both processes. The thread name has nothing to do with the classes in the code, nor is it intended to imply any relationship except with the process and the document in question. As the comment in this patch explains, the choice of the suffix is arbitrary and while it may be changed, it has to be sensible and common between the two threads to allow for easy grepping. Historically, there were in fact dedicated threads within the respective "broker" classes, but this fact should be safely ignored, since at the log level we care less about which part of the code generates a log entry (that info, if needed, is at the end of each log entry, in the form of filename and line number), rather we care more about which document it relates to, which is crucial in investigating production issues. Logs and code structure are only incidentally related. Logs are (or at least should be) designed around the execution structure, not code architecture. (This reverts 2a16f34812cf69bbe0f21b7e7d048fdb3271fa9d) Change-Id: Ic6fe2f9425998824774d2644fe4362e75dea6b88 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/101261 Tested-by: Jenkins Tested-by: Tor Lillqvist <tml@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-08-24 06:17:49 +02:00
/// Unfortunately grepping for only "_123" would include more noise than desirable.
/// This also makes the threadname symmetric and the entries aligned.
/// The choice of "broker" as the suffix is historic: it implies the controller
/// of which there are two: one in WSD called DocumentBroker and one in Kit
/// called Document, which wasn't called DocumentBroker to avoid confusing it
/// with the one in WSD. No such confusion should be expected in the logs, since
/// the prefix is "doc" and "kit" respectively, and each log entry has the process
/// name prefixed. And of course these threads are unrelated to the classes in
/// the code: they are logical execution unit names.
#define SHARED_DOC_THREADNAME_SUFFIX "broker_"
/// The HTTP request User-Agent. Used only in Requests.
#define HTTP_AGENT_STRING "COOLWSD HTTP Agent " COOLWSD_VERSION
/// The WOPI User-Agent. Depricated: use HTTP_AGENT_STRING.
#define WOPI_AGENT_STRING HTTP_AGENT_STRING
/// The HTTP response Server. Used only in Responses.
#define HTTP_SERVER_STRING "COOLWSD HTTP Server " COOLWSD_VERSION
/// The client port number, both coolwsd and the kits have this.
extern int ClientPortNumber;
extern std::string MasterLocation;
/// Controls whether experimental features/behavior is enabled or not.
extern bool EnableExperimental;
deltas: track, transmit and cache deltas (disabled for now) Squashed from feature/deltas-expanded. TileCache changes: + add montonic sequence (wid) numbers to TileData + account for sizes of TileData with multiple blobs + simplify saving and notifying of tiles Sends updates (via appendChanges) based on the sequence the right mix of keyframes and/or deltas required as a single message, and parse and apply those on the JS side. We continue to use PNG for slide previews and dialogs, but remove PngCache - used by document tiles only. Annotates delta: properly as a binary package for the websocket. Distinguishes between deltas and keyframes we get from the Kit based on an initial un-compressed prefix character which we then discard. kit can be forced to render a keyframe by oldWid=0 Track invalidity on tiles themselves - to keep the keyframe around. We need to be able to track that a tile is invalid, and so subscribe to the updated version as/when it is ready - but we also want to store the keyframe underneath any deltas. force rendering of a keyframe for an empty slot in the TileCache. force tile sequence to be zero for combinedtiles - so the client can always request standalone tiles with explicit combinedtiles, or tile requests. move Blob to Common.hpp use zero size for un-changed tiles. remove obsolete render-id, and color deltas in debug mode. cleanup unit tests for non-png tile results. Change-Id: I987f84ac4e58004758a243c233b19a6f0d60f8c2 Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-03-25 19:32:01 +01:00
/// More efficient use of vectors
using BlobData = std::vector<char>;
using Blob = std::shared_ptr<BlobData>;
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */