cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

kubernetes.h (4602B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#ifndef GUAC_KUBERNETES_H
     21#define GUAC_KUBERNETES_H
     22
     23#include "common/clipboard.h"
     24#include "io.h"
     25#include "settings.h"
     26#include "terminal/terminal.h"
     27
     28#include <guacamole/client.h>
     29#include <guacamole/recording.h>
     30#include <libwebsockets.h>
     31
     32#include <pthread.h>
     33
     34/**
     35 * The name of the WebSocket protocol specific to Kubernetes which should be
     36 * sent to the Kubernetes server when attaching to a pod.
     37 */
     38#define GUAC_KUBERNETES_LWS_PROTOCOL "v4.channel.k8s.io"
     39
     40/**
     41 * The maximum number of messages to allow within the outbound message buffer.
     42 * If messages are sent despite the buffer being full, those messages will be
     43 * dropped.
     44 */
     45#define GUAC_KUBERNETES_MAX_OUTBOUND_MESSAGES 8
     46
     47/**
     48 * The maximum number of milliseconds to wait for a libwebsockets event to
     49 * occur before entering another iteration of the libwebsockets event loop.
     50 */
     51#define GUAC_KUBERNETES_SERVICE_INTERVAL 1000
     52
     53/**
     54 * Kubernetes-specific client data.
     55 */
     56typedef struct guac_kubernetes_client {
     57
     58    /**
     59     * Kubernetes connection settings.
     60     */
     61    guac_kubernetes_settings* settings;
     62
     63    /**
     64     * The libwebsockets context associated with the connected WebSocket.
     65     */
     66    struct lws_context* context;
     67
     68    /**
     69     * The connected WebSocket.
     70     */
     71    struct lws* wsi;
     72
     73    /**
     74     * Outbound message ring buffer for outbound WebSocket messages. As
     75     * libwebsockets uses an event loop for all operations, outbound messages
     76     * may be sent only in context of a particular event received via a
     77     * callback. Until that event is received, pending data must accumulate in
     78     * a buffer.
     79     */
     80    guac_kubernetes_message outbound_messages[GUAC_KUBERNETES_MAX_OUTBOUND_MESSAGES];
     81
     82    /**
     83     * The number of messages currently waiting in the outbound message
     84     * buffer.
     85     */
     86    int outbound_messages_waiting;
     87
     88    /**
     89     * The index of the oldest entry in the outbound message buffer. Newer
     90     * messages follow this entry.
     91     */
     92    int outbound_messages_top;
     93
     94    /**
     95     * Lock which is acquired when the outbound message buffer is being read
     96     * or manipulated.
     97     */
     98    pthread_mutex_t outbound_message_lock;
     99
    100    /**
    101     * The Kubernetes client thread.
    102     */
    103    pthread_t client_thread;
    104
    105    /**
    106     * The terminal which will render all output from the Kubernetes pod.
    107     */
    108    guac_terminal* term;
    109
    110    /**
    111     * The number of rows last sent to Kubernetes in a terminal resize
    112     * request.
    113     */
    114    int rows;
    115
    116    /**
    117     * The number of columns last sent to Kubernetes in a terminal resize
    118     * request.
    119     */
    120    int columns;
    121
    122    /**
    123     * The in-progress session recording, or NULL if no recording is in
    124     * progress.
    125     */
    126    guac_recording* recording;
    127
    128} guac_kubernetes_client;
    129
    130/**
    131 * Main Kubernetes client thread, handling transfer of STDOUT/STDERR of an
    132 * attached Kubernetes pod to STDOUT of the terminal.
    133 */
    134void* guac_kubernetes_client_thread(void* data);
    135
    136/**
    137 * Sends a message to the Kubernetes server requesting that the terminal be
    138 * resized to the given dimensions. This message may be queued until the
    139 * underlying WebSocket connection is ready to send.
    140 *
    141 * @param client
    142 *     The guac_client associated with the Kubernetes connection.
    143 *
    144 * @param rows
    145 *     The new terminal size in rows.
    146 *
    147 * @param columns
    148 *     The new terminal size in columns.
    149 */
    150void guac_kubernetes_resize(guac_client* client, int rows, int columns);
    151
    152/**
    153 * Sends messages to the Kubernetes server such that the terminal is forced
    154 * to redraw. This function should be invoked at the beginning of each
    155 * session in order to restore expected display state.
    156 *
    157 * @param client
    158 *     The guac_client associated with the Kubernetes connection.
    159 */
    160void guac_kubernetes_force_redraw(guac_client* client);
    161
    162#endif
    163