Compare commits

..

37 Commits

Author SHA1 Message Date
matt
152821d77b KASM-1883 add manpage for kasmxproxy 2021-09-15 11:54:42 +00:00
matt
906fcc3e67 KASM-1883 update builds with new deps 2021-09-15 11:07:10 +00:00
Lauri Kasanen
ab32cbc53e Small cleanup, move selection supplying to a func 2021-08-31 17:31:38 +03:00
Lauri Kasanen
a48811b12f Browser to app paste support 2021-08-31 17:22:58 +03:00
Lauri Kasanen
4c4808d2bd Add support for app-to-vnc clipboard copy 2021-08-31 15:37:37 +03:00
Lauri Kasanen
e282851073 Resizing support for nvidia 2021-08-30 14:00:10 +03:00
Lauri Kasanen
40d263368d Pass cursors 2021-08-27 12:16:36 +03:00
Matt
377d3e5629 fix to mode name 2021-08-26 16:38:57 +00:00
Dmitry Maksyoma
5b516e84d9 Fix deb build 2021-08-26 21:26:30 +12:00
Matt
43c31d759b deb package dependency updates 2021-08-25 19:36:51 +00:00
Matt
aa7d1b5a30 Added missing build deps for CentOS 2021-08-25 16:17:33 +00:00
Matt
8b5600e8f3 Add xrandr-dev package to build images 2021-08-25 15:14:30 +00:00
Lauri Kasanen
bbd971e9f1 Resizing support 2021-08-25 14:37:40 +03:00
Lauri Kasanen
0467e938a2 Input 2021-08-25 13:08:42 +03:00
Lauri Kasanen
01623eaffd Image copies 2021-08-25 12:12:00 +03:00
Lauri Kasanen
3383ad52e4 Start on kasmxproxy 2021-08-25 10:58:41 +03:00
mmcclaskey
6f2805e186 Merge pull request #47 from kasmtech/bugfix/KASM-1815_DO_websocket
Bugfix/kasm 1815 do websocket
2021-08-18 05:22:54 -04:00
Lauri Kasanen
d80eb39686 Fix DigitalOcean load balancer websocket connection (they too used wrong case in a header) 2021-08-17 13:30:33 +03:00
Lauri Kasanen
4b28667e90 Fix possible missing clipboard deinit 2021-08-17 13:13:51 +03:00
mmcclaskey
5341bc6fba Merge pull request #46 from kasmtech/speed-up-deb-build
Slash a minute off tarball build
2021-08-16 11:17:37 -04:00
Dmitry Maksyoma
9ec4cba184 Slash a minute off tarball build 2021-08-17 00:00:55 +12:00
mmcclaskey
643a0cfed6 Merge pull request #45 from kasmtech/multiple
Add pid to the internal socket name, clarify websocketport bind error
2021-08-15 05:47:05 -04:00
Lauri Kasanen
9ca850a108 Add pid to the internal socket name, clarify websocketport bind error 2021-08-13 12:15:17 +03:00
matt
ec6bd697a8 update novnc ref 2021-08-05 14:48:41 -04:00
matt
544a9fc592 KASM-1512 api stats KASM-1790 cursor 2021-08-05 11:12:03 -04:00
mmcclaskey
7b5838a1ea Merge pull request #43 from kasmtech/apistats
Apistats
2021-08-05 11:03:35 -04:00
Lauri Kasanen
a9b66833a9 Change frame stats API json formatting 2021-08-03 14:41:54 +03:00
Lauri Kasanen
e208d5bb5f Bottleneck clear should wait instead of try 2021-08-02 13:56:54 +03:00
Lauri Kasanen
f57e6e644b Add some more frame stats granularity, skip frame stats on no-data calls 2021-08-02 13:47:48 +03:00
Lauri Kasanen
c1ed769780 Clear disconnected clients from the bottleneck stats api 2021-08-02 12:45:51 +03:00
matt
fae8aa9051 switched novnc commit 2021-07-29 14:04:39 -04:00
Lauri Kasanen
438271d68b Add support for vmware cursor 2021-07-29 18:02:57 +03:00
Lauri Kasanen
fb9dd56703 Initial /api/get_frame_stats 2021-07-27 15:33:48 +03:00
Lauri Kasanen
32e8d40472 Implement /api/get_bottleneck_stats 2021-07-26 18:58:29 +03:00
Lauri Kasanen
811e7cde3a Use case-insensitive search for the websocket headers 2021-07-12 15:44:24 +03:00
mmcclaskey
72affbfcf4 [skip CI] Readme updates 2021-06-25 10:04:26 -04:00
mmcclaskey
b362110b07 [skip CI] update readme 2021-06-25 05:59:14 -04:00
53 changed files with 1540 additions and 85 deletions

View File

@@ -1,11 +1,11 @@
# KasmVNC - Linux Web Remote Desktop
[![Kasm Technologies](https://kasm-static-content.s3.amazonaws.com/368_kasm_logo_.jpg "Kasm Logo")](https://kasmweb.com)
[Kasm Technologies LLC](https://www.kasmweb.com) developed Kasm Server, a Containerized Desktop Infrastructure (CDI) solution. Kasm started with TigerVNC and eventually forked it to create KasmVNC. KasmVNC is used within the overal Kasm CDI infrastructure, however, you can use KasmVNC for individual servers. KasmVNC has different goals than TigerVNC:
<a href="https://kasmweb.com"><img src="https://kasm-static-content.s3.amazonaws.com/logo_kasm.png" width="300"><a/>
[Kasm Technologies](https://www.kasmweb.com) developed Kasm Workspaces, the Containerized Streaming Platform. Kasm has open-sourced the Workspace docker images, which include containerized [full desktops and apps](https://github.com/kasmtech/workspaces-images) and [base images](https://github.com/kasmtech/workspaces-core-images) intended for developers to create custimized streaming containers. These containers can be used standalone or within the [Kasm Workspaces Platform](https://www.kasmweb.com) which provides a full Enterprise feature set. KasmVNC is used as the streaming tech for our container images, however, you can use KasmVNC for individual servers. While the term VNC is in the name, KasmVNC is not intended to remain compliant with the RFB spec and has different goals than other VNC projects:
- Web-based - KasmVNC is designed to provide a web accessible remote desktop. It comes with a web server and websocket server built in. There is no need to install other components. Simply run and navigate to your desktop's URL on the port you specify. While you can still tun on the legacy VNC port, it is disabled by default.
- Security - KasmVNC defaults to HTTPS and allows for HTTP Basic Auth. VNC Password authentication is limited by specification to 8 characters and is not suffecient for use on an internet accessible remote desktop. Our goal is to create a by default secure, web based experience.
- Security - The RFB specification (VNC) limits the password field to 8 characters, so while the client may take a longer password, only the first 8 characters are sent. KasmVNC defaults to HTTPS with HTTP Basic Auth and disables the legacy VNC authentication method which is not sufficiently secure for internet accessible systems.
- Simplicity - KasmVNC aims at being simple to deploy and configure.
# New Features!
@@ -91,11 +91,13 @@ The options for vncserver:
| interface | Which interface to bind the web server to. |
### Development
Would you like to contribute to KasmVNC? Please reachout to us at info@kasmweb.com
Would you like to contribute to KasmVNC? Please reachout to us at info@kasmweb.com. We have investigated or are working on the following, if you have experience in these fields and would like to help please let us know.
We need help, especially in packaging KasmVNC for various operating systems. We would love to have standard debian or RMP packages and host our own repo, however, that all requires a lot of experience, proper testing, and pipeline development for automated builds.
Real-time H264 encoding using NVIDIA and Intel encoding technology.
We also need help with Windows, which is not currently supported. While KasmVNC can technically be built for Windows 10, it is unusably slow, due to all the changes that occured in Windows since the original Windows support was added in the chain of VNC forked projects.
Windows version of KasmVNC. We have been able to get it to compile for Windows and increased the performance, but still not releasable. Experienced Windows developers with a background in cross compiling would help.
ARM version of KasmVNC, we have had requests for this and at one point we did have an ARM build of KasmVNC but it takes dev cycles to mainain and bring it back to life.
### Compiling From Source
See the [builder/README.md](https://github.com/kasmtech/KasmVNC/blob/master/builder/README.md). We containerize our build systems to ensure highly repeatable builds.

View File

@@ -1,6 +1,7 @@
#!/bin/bash
set -e
set -x
build_www_dir() {
local webpacked_www=$PWD/builder/www

View File

@@ -1,5 +1,7 @@
#!/bin/sh -e
set -x
detect_quilt() {
if which quilt 1>/dev/null; then
QUILT_PRESENT=1
@@ -80,7 +82,9 @@ cd /src
detect_quilt
if [ -n "$QUILT_PRESENT" ]; then
quilt push -a
echo 'Patches applied!'
fi
make servertarball
cp kasmvnc*.tar.gz /build/kasmvnc.${KASMVNC_BUILD_OS}_${KASMVNC_BUILD_OS_CODENAME}.tar.gz

View File

@@ -10,7 +10,8 @@ RUN yum install -y make
RUN yum group install -y "Development Tools"
RUN yum install -y xorg-x11-server-devel zlib-devel libjpeg-turbo-devel
RUN yum install -y libxkbfile-devel libXfont2-devel xorg-x11-font-utils \
xorg-x11-xtrans-devel xorg-x11-xkb-utils-devel
xorg-x11-xtrans-devel xorg-x11-xkb-utils-devel libXrandr-devel pam-devel \
gnutls-devel libX11-devel libXtst-devel libXcursor-devel
RUN yum install -y mesa-dri-drivers
# Additions for webp
@@ -22,8 +23,7 @@ RUN cd /tmp/libwebp-1.0.2 && \
RUN useradd -m docker && echo "docker:docker" | chpasswd
COPY . /src
RUN chown -R docker:docker /src
COPY --chown=docker:docker . /src/
USER docker
ENTRYPOINT ["/src/builder/build.sh"]

View File

@@ -13,7 +13,7 @@ RUN apt-get update && \
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev
RUN apt-get update && apt-get -y install cmake git libjpeg-dev libgnutls28-dev vim wget tightvncserver
RUN apt-get update && apt-get -y install libjpeg-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev
RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev
# Additions for webp
RUN cd /tmp && wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.2.tar.gz
@@ -24,8 +24,7 @@ RUN cd /tmp/libwebp-1.0.2 && \
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
COPY . /src
RUN chown -R docker:docker /src
COPY --chown=docker:docker . /src/
USER docker
ENTRYPOINT ["/src/builder/build.sh"]

View File

@@ -13,7 +13,7 @@ RUN apt-get update && \
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev
RUN apt-get update && apt-get -y install cmake git libjpeg-dev libgnutls28-dev vim wget tightvncserver
RUN apt-get update && apt-get -y install libjpeg-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev
RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev
# Additions for webp
RUN cd /tmp && wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.2.tar.gz
@@ -24,8 +24,7 @@ RUN cd /tmp/libwebp-1.0.2 && \
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
COPY . /src
RUN chown -R docker:docker /src
COPY --chown=docker:docker . /src/
USER docker
ENTRYPOINT ["/src/builder/build.sh"]

View File

@@ -34,11 +34,6 @@ RUN apt-get purge -y pm-utils xscreensaver*
RUN apt-get update && apt-get install -y vim less
RUN apt-get update && apt-get -y install lsb-release
RUN apt-get update && apt-get -y install xdg-desktop-portal firefox-esr
COPY ./xdg-desktop-portal-gtk_1.2.0-1_amd64.deb /tmp
RUN apt-get install -y /tmp/xdg-*.deb
# RUN apt-get install -y xdg-desktop-portal-gtk
RUN echo 'source $STARTUPDIR/generate_container_user' >> $HOME/.bashrc
RUN mkdir -p $STARTUPDIR
@@ -52,12 +47,8 @@ RUN dpkg -i /tmp/*.deb; apt-get -yf install
### END CUSTOM STUFF ###
RUN sed -i -e 's/about:home/postimages.org/' /usr/lib/firefox-esr/browser/defaults/preferences/firefox.js
RUN sed -i -e '/browser.startup.firstrunSkipsHomepage/d' /usr/lib/firefox-esr/browser/defaults/preferences/firefox.js
RUN echo 'pref("browser.startup.firstrunSkipsHomepage", false);' >> /usr/lib/firefox-esr/browser/defaults/preferences/firefox.js
RUN chown -R 1000:0 $HOME
USER 1000:ssl-cert
WORKDIR $HOME
ENV GTK_USE_PORTAL=1
ENTRYPOINT [ "/dockerstartup/vnc_startup.sh" ]

View File

@@ -18,7 +18,7 @@ RUN dnf install -y make
RUN dnf group install -y "Development Tools"
RUN dnf install -y xorg-x11-server-devel zlib-devel libjpeg-turbo-devel
RUN dnf install -y libxkbfile-devel libXfont2-devel xorg-x11-font-utils \
xorg-x11-xtrans-devel xorg-x11-xkb-utils-devel
xorg-x11-xtrans-devel xorg-x11-xkb-utils-devel libXrandr-devel libXcursor-devel
RUN dnf install -y mesa-dri-drivers
RUN dnf install -y bzip2 redhat-lsb-core
@@ -31,8 +31,7 @@ RUN cd /tmp/libwebp-1.0.2 && \
RUN useradd -m docker && echo "docker:docker" | chpasswd
COPY . /src
RUN chown -R docker:docker /src
COPY --chown=docker:docker . /src/
USER docker
ENTRYPOINT ["/src/builder/build.sh"]

View File

@@ -13,7 +13,7 @@ RUN apt-get update && \
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata
RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev
RUN apt-get update && apt-get -y install cmake git libjpeg-dev libgnutls28-dev vim wget tightvncserver
RUN apt-get update && apt-get -y install libjpeg-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev
RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev
# Additions for webp
RUN cd /tmp && wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.2.tar.gz
@@ -24,8 +24,7 @@ RUN cd /tmp/libwebp-1.0.2 && \
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
COPY . /src
RUN chown -R docker:docker /src
COPY --chown=docker:docker . /src/
USER docker
ENTRYPOINT ["/src/builder/build.sh"]

View File

@@ -14,8 +14,7 @@ RUN cd /tmp/libwebp-1.0.2 && ./configure && make && make install
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
COPY . /src
RUN chown -R docker:docker /src
COPY --chown=docker:docker . /src/
USER docker

View File

@@ -11,7 +11,7 @@ RUN apt-get update && \
RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev
RUN apt-get update && apt-get -y install cmake git libjpeg-dev libgnutls28-dev vim wget tightvncserver
RUN apt-get update && apt-get -y install libjpeg-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev
RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev
# Additions for webp
RUN cd /tmp && wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.2.tar.gz
@@ -28,8 +28,7 @@ RUN cd /tmp/libwebp-1.0.2 && \
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
COPY . /src
RUN chown -R docker:docker /src
COPY --chown=docker:docker . /src/
USER docker
ENTRYPOINT ["/src/builder/build.sh"]

View File

@@ -33,7 +33,6 @@ RUN apt-get update && apt-get install -y supervisor xfce4 xfce4-terminal xterm l
RUN apt-get purge -y pm-utils xscreensaver*
RUN apt-get update && apt-get install -y vim less
RUN apt-get update && apt-get -y install lsb-release
RUN apt-get update && apt-get -y install xdg-desktop-portal xdg-desktop-portal-gtk firefox
RUN echo 'source $STARTUPDIR/generate_container_user' >> $HOME/.bashrc
@@ -48,12 +47,8 @@ RUN dpkg -i /tmp/*.deb; apt-get -yf install
### END CUSTOM STUFF ###
RUN echo 'pref("browser.startup.firstrunSkipsHomepage", false);' >> /usr/lib/firefox/browser/defaults/preferences/syspref.js
RUN echo 'pref("browser.startup.homepage", "postimages.org");' >> /usr/lib/firefox/browser/defaults/preferences/syspref.js
RUN chown -R 1000:0 $HOME
USER 1000:ssl-cert
WORKDIR $HOME
ENV GTK_USE_PORTAL=1
ENTRYPOINT [ "/dockerstartup/vnc_startup.sh" ]

View File

@@ -13,7 +13,7 @@ RUN apt-get update && \
RUN apt-get update && apt-get install -y --no-install-recommends tzdata
RUN apt-get update && apt-get -y build-dep xorg-server libxfont-dev
RUN apt-get update && apt-get -y install cmake git libjpeg-dev libgnutls28-dev vim wget tightvncserver
RUN apt-get update && apt-get -y install libjpeg-dev libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev
RUN apt-get update && apt-get -y install libpng-dev libtiff-dev libgif-dev libavcodec-dev libssl-dev libxrandr-dev libxcursor-dev
# Additions for webp
RUN cd /tmp && wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.0.2.tar.gz
@@ -24,8 +24,7 @@ RUN cd /tmp/libwebp-1.0.2 && \
RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo
COPY . /src
RUN chown -R docker:docker /src
COPY --chown=docker:docker . /src/
USER docker
ENTRYPOINT ["/src/builder/build.sh"]

View File

@@ -88,8 +88,6 @@ detect_www_dir
detect_cert_location
[ -n "$KASMVNC_VERBOSE_LOGGING" ] && verbose_logging_option="-log *:stderr:100"
# dbus-daemon --session --address=systemd: --nofork --nopidfile --syslog-only &
echo -e "start vncserver with param: VNC_COL_DEPTH=$VNC_COL_DEPTH, VNC_RESOLUTION=$VNC_RESOLUTION\n..."
vncserver $DISPLAY -depth $VNC_COL_DEPTH -geometry $VNC_RESOLUTION -FrameRate=$MAX_FRAME_RATE -websocketPort $VNC_PORT $cert_option -sslOnly -interface 0.0.0.0 $VNCOPTIONS $package_www_dir_option $verbose_logging_option #&> $STARTUPDIR/no_vnc_startup.log

View File

@@ -62,8 +62,10 @@ cp $SRC/man/man1/Xvnc.1 $DESTDIR/usr/share/man/man1/;
cp $SRC/share/man/man1/vncserver.1 $DST_MAN;
cp $SRC/share/man/man1/vncconfig.1 $DST_MAN;
cp $SRC/share/man/man1/vncpasswd.1 $DST_MAN;
cp $SRC/share/man/man1/kasmxpoxy.1 $DST_MAN;
cd $DST_MAN && ln -s vncpasswd.1 kasmvncpasswd.1;
%files
/usr/bin/*
/usr/share/man/man1/*

View File

@@ -24,6 +24,8 @@
#include <rfb/PixelBuffer.h>
#include <rfb/PixelFormat.h>
#include <stdint.h>
#include <map>
#include <string>
#include <vector>
namespace network {
@@ -34,6 +36,17 @@ namespace network {
// from main thread
void mainUpdateScreen(rfb::PixelBuffer *pb);
void mainUpdateBottleneckStats(const char userid[], const char stats[]);
void mainClearBottleneckStats(const char userid[]);
void mainUpdateServerFrameStats(uint8_t changedPerc, uint32_t all,
uint32_t jpeg, uint32_t webp, uint32_t analysis,
uint32_t jpegarea, uint32_t webparea,
uint16_t njpeg, uint16_t nwebp,
uint16_t enc, uint16_t scale, uint16_t shot,
uint16_t w, uint16_t h);
void mainUpdateClientFrameStats(const char userid[], uint32_t render, uint32_t all,
uint32_t ping);
void mainUpdateUserInfo(const uint8_t ownerConn, const uint8_t numUsers);
// from network threads
uint8_t *netGetScreenshot(uint16_t w, uint16_t h,
@@ -42,13 +55,25 @@ namespace network {
uint8_t netAddUser(const char name[], const char pw[], const bool write);
uint8_t netRemoveUser(const char name[]);
uint8_t netGiveControlTo(const char name[]);
void netGetBottleneckStats(char *buf, uint32_t len);
void netGetFrameStats(char *buf, uint32_t len);
uint8_t netServerFrameStatsReady();
enum USER_ACTION {
//USER_ADD, - handled locally for interactivity
USER_REMOVE,
USER_GIVE_CONTROL,
WANT_FRAME_STATS_SERVERONLY,
WANT_FRAME_STATS_ALL,
WANT_FRAME_STATS_OWNER,
WANT_FRAME_STATS_SPECIFIC,
};
uint8_t netRequestFrameStats(USER_ACTION what, const char *client);
uint8_t netOwnerConnected();
uint8_t netNumActiveUsers();
uint8_t netGetClientFrameStatsNum();
struct action_data {
enum USER_ACTION action;
kasmpasswd_entry_t data;
@@ -68,6 +93,40 @@ namespace network {
std::vector<uint8_t> cachedJpeg;
uint16_t cachedW, cachedH;
uint8_t cachedQ;
std::map<std::string, std::string> bottleneckStats;
pthread_mutex_t statMutex;
struct clientFrameStats_t {
uint32_t render;
uint32_t all;
uint32_t ping;
};
struct serverFrameStats_t {
uint32_t all;
uint32_t jpeg;
uint32_t webp;
uint32_t analysis;
uint32_t jpegarea;
uint32_t webparea;
uint16_t njpeg;
uint16_t nwebp;
uint16_t enc;
uint16_t scale;
uint16_t shot;
uint16_t w;
uint16_t h;
uint8_t changedPerc;
uint8_t inprogress;
};
std::map<std::string, clientFrameStats_t> clientFrameStats;
serverFrameStats_t serverFrameStats;
pthread_mutex_t frameStatMutex;
uint8_t ownerConnected;
uint8_t activeUsers;
pthread_mutex_t userInfoMutex;
};
}

View File

@@ -56,10 +56,16 @@ static const struct TightJPEGConfiguration conf[10] = {
GetAPIMessager::GetAPIMessager(const char *passwdfile_): passwdfile(passwdfile_),
screenW(0), screenH(0), screenHash(0),
cachedW(0), cachedH(0), cachedQ(0) {
cachedW(0), cachedH(0), cachedQ(0),
ownerConnected(0), activeUsers(0) {
pthread_mutex_init(&screenMutex, NULL);
pthread_mutex_init(&userMutex, NULL);
pthread_mutex_init(&statMutex, NULL);
pthread_mutex_init(&frameStatMutex, NULL);
pthread_mutex_init(&userInfoMutex, NULL);
serverFrameStats.inprogress = 0;
}
// from main thread
@@ -95,6 +101,78 @@ void GetAPIMessager::mainUpdateScreen(rfb::PixelBuffer *pb) {
pthread_mutex_unlock(&screenMutex);
}
void GetAPIMessager::mainUpdateBottleneckStats(const char userid[], const char stats[]) {
if (pthread_mutex_trylock(&statMutex))
return;
bottleneckStats[userid] = stats;
pthread_mutex_unlock(&statMutex);
}
void GetAPIMessager::mainClearBottleneckStats(const char userid[]) {
if (pthread_mutex_lock(&statMutex))
return;
bottleneckStats.erase(userid);
pthread_mutex_unlock(&statMutex);
}
void GetAPIMessager::mainUpdateServerFrameStats(uint8_t changedPerc,
uint32_t all, uint32_t jpeg, uint32_t webp, uint32_t analysis,
uint32_t jpegarea, uint32_t webparea,
uint16_t njpeg, uint16_t nwebp,
uint16_t enc, uint16_t scale, uint16_t shot,
uint16_t w, uint16_t h) {
if (pthread_mutex_lock(&frameStatMutex))
return;
serverFrameStats.changedPerc = changedPerc;
serverFrameStats.all = all;
serverFrameStats.jpeg = jpeg;
serverFrameStats.webp = webp;
serverFrameStats.analysis = analysis;
serverFrameStats.jpegarea = jpegarea;
serverFrameStats.webparea = webparea;
serverFrameStats.njpeg = njpeg;
serverFrameStats.nwebp = nwebp;
serverFrameStats.enc = enc;
serverFrameStats.scale = scale;
serverFrameStats.shot = shot;
serverFrameStats.w = w;
serverFrameStats.h = h;
pthread_mutex_unlock(&frameStatMutex);
}
void GetAPIMessager::mainUpdateClientFrameStats(const char userid[], uint32_t render,
uint32_t all, uint32_t ping) {
if (pthread_mutex_lock(&frameStatMutex))
return;
clientFrameStats_t s;
s.render = render;
s.all = all;
s.ping = ping;
clientFrameStats[userid] = s;
pthread_mutex_unlock(&frameStatMutex);
}
void GetAPIMessager::mainUpdateUserInfo(const uint8_t ownerConn, const uint8_t numUsers) {
if (pthread_mutex_lock(&userInfoMutex))
return;
ownerConnected = ownerConn;
activeUsers = numUsers;
pthread_mutex_unlock(&userInfoMutex);
}
// from network threads
uint8_t *GetAPIMessager::netGetScreenshot(uint16_t w, uint16_t h,
const uint8_t q, const bool dedup,
@@ -286,3 +364,271 @@ uint8_t GetAPIMessager::netGiveControlTo(const char name[]) {
return 1;
}
void GetAPIMessager::netGetBottleneckStats(char *buf, uint32_t len) {
/*
{
"username.1": {
"192.168.100.2:14908": [ 100, 100, 100, 100 ],
"192.168.100.3:14918": [ 100, 100, 100, 100 ]
},
"username.2": {
"192.168.100.5:14904": [ 100, 100, 100, 100 ]
}
}
*/
std::map<std::string, std::string>::const_iterator it;
const char *prev = NULL;
FILE *f;
if (pthread_mutex_lock(&statMutex)) {
buf[0] = 0;
return;
}
// Conservative estimate
if (len < bottleneckStats.size() * 60) {
buf[0] = 0;
goto out;
}
f = fmemopen(buf, len, "w");
fprintf(f, "{\n");
for (it = bottleneckStats.begin(); it != bottleneckStats.end(); it++) {
// user@127.0.0.1_1627311208.791752::websocket
const char *id = it->first.c_str();
const char *data = it->second.c_str();
const char *at = strchr(id, '@');
if (!at)
continue;
const unsigned userlen = at - id;
if (prev && !strncmp(prev, id, userlen)) {
// Same user
fprintf(f, ",\n\t\t\"%s\": %s", at + 1, data);
} else {
// New one
if (prev) {
fprintf(f, "\n\t},\n");
}
fprintf(f, "\t\"%.*s\": {\n", userlen, id);
fprintf(f, "\t\t\"%s\": %s", at + 1, data);
}
prev = id;
}
if (!bottleneckStats.size())
fprintf(f, "}\n");
else
fprintf(f, "\n\t}\n}\n");
fclose(f);
out:
pthread_mutex_unlock(&statMutex);
}
void GetAPIMessager::netGetFrameStats(char *buf, uint32_t len) {
/*
{
"frame" : {
"resx": 1024,
"resy": 1280,
"changed": 75,
"server_time": 23
},
"server_side" : [
{ "process_name": "Analysis", "time": 20 },
{ "process_name": "TightWEBPEncoder", "time": 20, "count": 64, "area": 12 },
{ "process_name": "TightJPEGEncoder", "time": 20, "count": 64, "area": 12 }
],
"client_side" : [
{
"client": "123.1.2.1:1211",
"client_time": 20,
"ping": 20,
"processes" : [
{ "process_name": "scanRenderQ", "time": 20 }
]
}
}
}
*/
std::map<std::string, clientFrameStats_t>::const_iterator it;
unsigned i = 0;
FILE *f;
if (pthread_mutex_lock(&frameStatMutex)) {
buf[0] = 0;
return;
}
const unsigned num = clientFrameStats.size();
// Conservative estimate
if (len < 1024) {
buf[0] = 0;
goto out;
}
f = fmemopen(buf, len, "w");
fprintf(f, "{\n");
fprintf(f, "\t\"frame\" : {\n"
"\t\t\"resx\": %u,\n"
"\t\t\"resy\": %u,\n"
"\t\t\"changed\": %u,\n"
"\t\t\"server_time\": %u\n"
"\t},\n",
serverFrameStats.w,
serverFrameStats.h,
serverFrameStats.changedPerc,
serverFrameStats.all);
fprintf(f, "\t\"server_side\" : [\n"
"\t\t{ \"process_name\": \"Analysis\", \"time\": %u },\n"
"\t\t{ \"process_name\": \"Screenshot\", \"time\": %u },\n"
"\t\t{ \"process_name\": \"Encoding_total\", \"time\": %u, \"videoscaling\": %u },\n"
"\t\t{ \"process_name\": \"TightJPEGEncoder\", \"time\": %u, \"count\": %u, \"area\": %u },\n"
"\t\t{ \"process_name\": \"TightWEBPEncoder\", \"time\": %u, \"count\": %u, \"area\": %u }\n"
"\t],\n",
serverFrameStats.analysis,
serverFrameStats.shot,
serverFrameStats.enc,
serverFrameStats.scale,
serverFrameStats.jpeg,
serverFrameStats.njpeg,
serverFrameStats.jpegarea,
serverFrameStats.webp,
serverFrameStats.nwebp,
serverFrameStats.webparea);
fprintf(f, "\t\"client_side\" : [\n");
for (it = clientFrameStats.begin(); it != clientFrameStats.end(); it++, i++) {
const char *id = it->first.c_str();
const clientFrameStats_t &s = it->second;
fprintf(f, "\t\t\{\n"
"\t\t\t\"client\": \"%s\",\n"
"\t\t\t\"client_time\": %u,\n"
"\t\t\t\"ping\": %u,\n"
"\t\t\t\"processes\" : [\n"
"\t\t\t\t{ \"process_name\": \"scanRenderQ\", \"time\": %u }\n"
"\t\t\t]\n"
"\t\t}",
id,
s.all,
s.ping,
s.render);
if (i == num - 1)
fprintf(f, "\n");
else
fprintf(f, ",\n");
}
fprintf(f, "\t]\n}\n");
fclose(f);
serverFrameStats.inprogress = 0;
out:
pthread_mutex_unlock(&frameStatMutex);
}
uint8_t GetAPIMessager::netRequestFrameStats(USER_ACTION what, const char *client) {
// Return 1 for success
action_data act;
act.action = what;
if (client) {
strncpy(act.data.password, client, PASSWORD_LEN);
act.data.password[PASSWORD_LEN - 1] = '\0';
}
// In progress already?
bool fail = false;
if (pthread_mutex_lock(&frameStatMutex))
return 0;
if (serverFrameStats.inprogress) {
fail = true;
vlog.error("Frame stats request already in progress, refusing another");
} else {
clientFrameStats.clear();
memset(&serverFrameStats, 0, sizeof(serverFrameStats_t));
serverFrameStats.inprogress = 1;
}
pthread_mutex_unlock(&frameStatMutex);
if (fail)
return 0;
// Send it in
if (pthread_mutex_lock(&userMutex))
return 0;
actionQueue.push_back(act);
pthread_mutex_unlock(&userMutex);
return 1;
}
uint8_t GetAPIMessager::netOwnerConnected() {
uint8_t ret;
if (pthread_mutex_lock(&userInfoMutex))
return 0;
ret = ownerConnected;
pthread_mutex_unlock(&userInfoMutex);
return ret;
}
uint8_t GetAPIMessager::netNumActiveUsers() {
uint8_t ret;
if (pthread_mutex_lock(&userInfoMutex))
return 0;
ret = activeUsers;
pthread_mutex_unlock(&userInfoMutex);
return ret;
}
uint8_t GetAPIMessager::netGetClientFrameStatsNum() {
uint8_t ret;
if (pthread_mutex_lock(&frameStatMutex))
return 0;
ret = clientFrameStats.size();
pthread_mutex_unlock(&frameStatMutex);
return ret;
}
uint8_t GetAPIMessager::netServerFrameStatsReady() {
uint8_t ret;
if (pthread_mutex_lock(&frameStatMutex))
return 0;
ret = serverFrameStats.w != 0;
pthread_mutex_unlock(&frameStatMutex);
return ret;
}

View File

@@ -40,6 +40,8 @@
#include <unistd.h>
#include <pthread.h>
#include <wordexp.h>
#include <sys/types.h>
#include <unistd.h>
#include "websocket.h"
#include <network/GetAPI.h>
@@ -459,6 +461,67 @@ static uint8_t givecontrolCb(void *messager, const char name[])
return msgr->netGiveControlTo(name);
}
static void bottleneckStatsCb(void *messager, char *buf, uint32_t len)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
msgr->netGetBottleneckStats(buf, len);
}
static void frameStatsCb(void *messager, char *buf, uint32_t len)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
msgr->netGetFrameStats(buf, len);
}
static uint8_t requestFrameStatsNoneCb(void *messager)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
return msgr->netRequestFrameStats(GetAPIMessager::WANT_FRAME_STATS_SERVERONLY, NULL);
}
static uint8_t requestFrameStatsOwnerCb(void *messager)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
return msgr->netRequestFrameStats(GetAPIMessager::WANT_FRAME_STATS_OWNER, NULL);
}
static uint8_t requestFrameStatsAllCb(void *messager)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
return msgr->netRequestFrameStats(GetAPIMessager::WANT_FRAME_STATS_ALL, NULL);
}
static uint8_t requestFrameStatsOneCb(void *messager, const char *client)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
return msgr->netRequestFrameStats(GetAPIMessager::WANT_FRAME_STATS_SPECIFIC, client);
}
static uint8_t ownerConnectedCb(void *messager)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
return msgr->netOwnerConnected();
}
static uint8_t numActiveUsersCb(void *messager)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
return msgr->netNumActiveUsers();
}
static uint8_t getClientFrameStatsNumCb(void *messager)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
return msgr->netGetClientFrameStatsNum();
}
static uint8_t serverFrameStatsReadyCb(void *messager)
{
GetAPIMessager *msgr = (GetAPIMessager *) messager;
return msgr->netServerFrameStatsReady();
}
WebsocketListener::WebsocketListener(const struct sockaddr *listenaddr,
socklen_t listenaddrlen,
bool sslonly, const char *cert, const char *certkey,
@@ -503,7 +566,7 @@ WebsocketListener::WebsocketListener(const struct sockaddr *listenaddr,
if (bind(sock, &sa.u.sa, listenaddrlen) == -1) {
int e = errorNumber;
closesocket(sock);
throw SocketException("failed to bind socket", e);
throw SocketException("failed to bind socket, is someone else on our -websocketPort?", e);
}
listen(sock); // sets the internal fd
@@ -513,13 +576,16 @@ WebsocketListener::WebsocketListener(const struct sockaddr *listenaddr,
//
internalSocket = socket(AF_UNIX, SOCK_STREAM, 0);
char sockname[32];
sprintf(sockname, ".KasmVNCSock%u", getpid());
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, ".KasmVNCSock");
strcpy(addr.sun_path, sockname);
addr.sun_path[0] = '\0';
if (bind(internalSocket, (struct sockaddr *) &addr,
sizeof(sa_family_t) + sizeof(".KasmVNCSock"))) {
sizeof(sa_family_t) + strlen(sockname))) {
throw SocketException("failed to bind socket", errorNumber);
}
@@ -548,6 +614,18 @@ WebsocketListener::WebsocketListener(const struct sockaddr *listenaddr,
settings.adduserCb = adduserCb;
settings.removeCb = removeCb;
settings.givecontrolCb = givecontrolCb;
settings.bottleneckStatsCb = bottleneckStatsCb;
settings.frameStatsCb = frameStatsCb;
settings.requestFrameStatsNoneCb = requestFrameStatsNoneCb;
settings.requestFrameStatsOwnerCb = requestFrameStatsOwnerCb;
settings.requestFrameStatsAllCb = requestFrameStatsAllCb;
settings.requestFrameStatsOneCb = requestFrameStatsOneCb;
settings.ownerConnectedCb = ownerConnectedCb;
settings.numActiveUsersCb = numActiveUsersCb;
settings.getClientFrameStatsNumCb = getClientFrameStatsNumCb;
settings.serverFrameStatsReadyCb = serverFrameStatsReadyCb;
pthread_t tid;
pthread_create(&tid, NULL, start_server, NULL);

View File

@@ -566,7 +566,7 @@ int parse_handshake(ws_ctx_t *ws_ctx, char *handshake) {
headers->key3[0] = '\0';
if ((strlen(handshake) < 92) || (bcmp(handshake, "GET ", 4) != 0) ||
(!strstr(handshake, "Upgrade: websocket"))) {
(!strcasestr(handshake, "Upgrade: websocket"))) {
return 0;
}
start = handshake+4;
@@ -583,11 +583,11 @@ int parse_handshake(ws_ctx_t *ws_ctx, char *handshake) {
headers->host[end-start] = '\0';
headers->origin[0] = '\0';
start = strstr(handshake, "\r\nOrigin: ");
start = strcasestr(handshake, "\r\nOrigin: ");
if (start) {
start += 10;
} else {
start = strstr(handshake, "\r\nSec-WebSocket-Origin: ");
start = strcasestr(handshake, "\r\nSec-WebSocket-Origin: ");
if (!start) { return 0; }
start += 24;
}
@@ -595,7 +595,7 @@ int parse_handshake(ws_ctx_t *ws_ctx, char *handshake) {
strncpy(headers->origin, start, end-start);
headers->origin[end-start] = '\0';
start = strstr(handshake, "\r\nSec-WebSocket-Version: ");
start = strcasestr(handshake, "\r\nSec-WebSocket-Version: ");
if (start) {
// HyBi/RFC 6455
start += 25;
@@ -605,7 +605,7 @@ int parse_handshake(ws_ctx_t *ws_ctx, char *handshake) {
ws_ctx->hixie = 0;
ws_ctx->hybi = strtol(headers->version, NULL, 10);
start = strstr(handshake, "\r\nSec-WebSocket-Key: ");
start = strcasestr(handshake, "\r\nSec-WebSocket-Key: ");
if (!start) { return 0; }
start += 21;
end = strstr(start, "\r\n");
@@ -619,7 +619,7 @@ int parse_handshake(ws_ctx_t *ws_ctx, char *handshake) {
strncpy(headers->connection, start, end-start);
headers->connection[end-start] = '\0';
start = strstr(handshake, "\r\nSec-WebSocket-Protocol: ");
start = strcasestr(handshake, "\r\nSec-WebSocket-Protocol: ");
if (!start) { return 0; }
start += 26;
end = strstr(start, "\r\n");
@@ -637,14 +637,14 @@ int parse_handshake(ws_ctx_t *ws_ctx, char *handshake) {
strncpy(headers->key3, start, 8);
headers->key3[8] = '\0';
start = strstr(handshake, "\r\nSec-WebSocket-Key1: ");
start = strcasestr(handshake, "\r\nSec-WebSocket-Key1: ");
if (!start) { return 0; }
start += 22;
end = strstr(start, "\r\n");
strncpy(headers->key1, start, end-start);
headers->key1[end-start] = '\0';
start = strstr(handshake, "\r\nSec-WebSocket-Key2: ");
start = strcasestr(handshake, "\r\nSec-WebSocket-Key2: ");
if (!start) { return 0; }
start += 22;
end = strstr(start, "\r\n");
@@ -1074,6 +1074,89 @@ static uint8_t ownerapi(ws_ctx_t *ws_ctx, const char *in) {
wserr("Passed give_control request to main thread\n");
ret = 1;
} else entry("/api/get_bottleneck_stats") {
char statbuf[4096];
settings.bottleneckStatsCb(settings.messager, statbuf, 4096);
sprintf(buf, "HTTP/1.1 200 OK\r\n"
"Server: KasmVNC/4.0\r\n"
"Connection: close\r\n"
"Content-type: text/plain\r\n"
"Content-length: %lu\r\n"
"\r\n", strlen(statbuf));
ws_send(ws_ctx, buf, strlen(buf));
ws_send(ws_ctx, statbuf, strlen(statbuf));
wserr("Sent bottleneck stats to API caller\n");
ret = 1;
} else entry("/api/get_frame_stats") {
char statbuf[4096], decname[1024];
unsigned waitfor;
param = parse_get(args, "client", &len);
if (len) {
memcpy(buf, param, len);
buf[len] = '\0';
percent_decode(buf, decname);
} else {
wserr("client param required\n");
goto nope;
}
if (!decname[0])
goto nope;
if (!strcmp(decname, "none")) {
waitfor = 0;
if (!settings.requestFrameStatsNoneCb(settings.messager))
goto nope;
} else if (!strcmp(decname, "auto")) {
waitfor = settings.ownerConnectedCb(settings.messager);
if (!waitfor) {
if (!settings.requestFrameStatsNoneCb(settings.messager))
goto nope;
} else {
if (!settings.requestFrameStatsOwnerCb(settings.messager))
goto nope;
}
} else if (!strcmp(decname, "all")) {
waitfor = settings.numActiveUsersCb(settings.messager);
if (!settings.requestFrameStatsAllCb(settings.messager))
goto nope;
} else {
waitfor = 1;
if (!settings.requestFrameStatsOneCb(settings.messager, decname))
goto nope;
}
while (1) {
usleep(10 * 1000);
if (settings.serverFrameStatsReadyCb(settings.messager))
break;
}
if (waitfor) {
unsigned waits;
for (waits = 0; waits < 20; waits++) { // wait up to 2s
if (settings.getClientFrameStatsNumCb(settings.messager) >= waitfor)
break;
usleep(100 * 1000);
}
}
settings.frameStatsCb(settings.messager, statbuf, 4096);
sprintf(buf, "HTTP/1.1 200 OK\r\n"
"Server: KasmVNC/4.0\r\n"
"Connection: close\r\n"
"Content-type: text/plain\r\n"
"Content-length: %lu\r\n"
"\r\n", strlen(statbuf));
ws_send(ws_ctx, buf, strlen(buf));
ws_send(ws_ctx, statbuf, strlen(statbuf));
wserr("Sent frame stats to API caller\n");
ret = 1;
}
#undef entry

View File

@@ -84,6 +84,18 @@ typedef struct {
const uint8_t write);
uint8_t (*removeCb)(void *messager, const char name[]);
uint8_t (*givecontrolCb)(void *messager, const char name[]);
void (*bottleneckStatsCb)(void *messager, char *buf, uint32_t len);
void (*frameStatsCb)(void *messager, char *buf, uint32_t len);
uint8_t (*requestFrameStatsNoneCb)(void *messager);
uint8_t (*requestFrameStatsOwnerCb)(void *messager);
uint8_t (*requestFrameStatsAllCb)(void *messager);
uint8_t (*requestFrameStatsOneCb)(void *messager, const char *client);
uint8_t (*ownerConnectedCb)(void *messager);
uint8_t (*numActiveUsersCb)(void *messager);
uint8_t (*getClientFrameStatsNumCb)(void *messager);
uint8_t (*serverFrameStatsReadyCb)(void *messager);
} settings_t;
#ifdef __cplusplus

View File

@@ -21,6 +21,7 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include "websocket.h"
/*
@@ -223,9 +224,12 @@ static void do_proxy(ws_ctx_t *ws_ctx, int target) {
void proxy_handler(ws_ctx_t *ws_ctx) {
char sockname[32];
sprintf(sockname, ".KasmVNCSock%u", getpid());
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, ".KasmVNCSock");
strcpy(addr.sun_path, sockname);
addr.sun_path[0] = '\0';
struct timeval tv;
@@ -243,7 +247,7 @@ void proxy_handler(ws_ctx_t *ws_ctx) {
handler_msg("connecting to VNC target\n");
if (connect(tsock, (struct sockaddr *) &addr,
sizeof(sa_family_t) + sizeof(".KasmVNCSock")) < 0) {
sizeof(sa_family_t) + strlen(sockname)) < 0) {
handler_emsg("Could not connect to target: %s\n",
strerror(errno));

View File

@@ -695,6 +695,8 @@ bool ComparingUpdateTracker::compare(bool skipScrollDetection, const Region &ski
std::vector<Rect> rects;
std::vector<Rect>::iterator i;
changedPerc = 100;
if (!enabled)
return false;
@@ -749,8 +751,13 @@ bool ComparingUpdateTracker::compare(bool skipScrollDetection, const Region &ski
for (i = rects.begin(); i != rects.end(); i++)
totalPixels += i->area();
newChanged.get_rects(&rects);
for (i = rects.begin(); i != rects.end(); i++)
unsigned newchangedarea = 0;
for (i = rects.begin(); i != rects.end(); i++) {
missedPixels += i->area();
newchangedarea += i->area();
}
changedPerc = newchangedarea * 100 / fb->area();
if (changed.equals(newChanged))
return false;

View File

@@ -48,6 +48,8 @@ namespace rfb {
virtual void getUpdateInfo(UpdateInfo* info, const Region& cliprgn);
virtual void clear();
rdr::U8 changedPerc;
private:
void compareRect(const Rect& r, Region* newchanged, const Region &skipCursorArea);
PixelBuffer* fb;

View File

@@ -298,6 +298,11 @@ size_t Congestion::getBandwidth()
return congWindow * 1000 / safeBaseRTT;
}
unsigned Congestion::getPingTime() const
{
return safeBaseRTT;
}
void Congestion::debugTrace(const char* filename, int fd)
{
#ifdef CONGESTION_TRACE

View File

@@ -51,6 +51,8 @@ namespace rfb {
// per second.
size_t getBandwidth();
unsigned getPingTime() const;
// debugTrace() writes the current congestion window, as well as the
// congestion window of the underlying TCP layer, to the specified
// file

View File

@@ -37,6 +37,7 @@ ConnParams::ConnParams()
width(0), height(0), useCopyRect(false),
supportsLocalCursor(false), supportsLocalXCursor(false),
supportsLocalCursorWithAlpha(false),
supportsVMWareCursor(false),
supportsCursorPosition(false),
supportsDesktopResize(false), supportsExtendedDesktopSize(false),
supportsDesktopRename(false), supportsLastRect(false),
@@ -123,6 +124,7 @@ void ConnParams::setEncodings(int nEncodings, const rdr::S32* encodings)
useCopyRect = false;
supportsLocalCursor = false;
supportsLocalCursorWithAlpha = false;
supportsVMWareCursor = false;
supportsDesktopResize = false;
supportsExtendedDesktopSize = false;
supportsLocalXCursor = false;
@@ -153,6 +155,9 @@ void ConnParams::setEncodings(int nEncodings, const rdr::S32* encodings)
case pseudoEncodingCursorWithAlpha:
supportsLocalCursorWithAlpha = true;
break;
case pseudoEncodingVMwareCursor:
supportsVMWareCursor = true;
break;
case pseudoEncodingDesktopSize:
supportsDesktopResize = true;
break;

View File

@@ -102,6 +102,7 @@ namespace rfb {
bool supportsLocalCursor;
bool supportsLocalXCursor;
bool supportsLocalCursorWithAlpha;
bool supportsVMWareCursor;
bool supportsCursorPosition;
bool supportsDesktopResize;
bool supportsExtendedDesktopSize;

View File

@@ -359,6 +359,8 @@ void EncodeManager::doUpdate(bool allowLossy, const Region& changed_,
changed = changed_;
gettimeofday(&start, NULL);
memset(&jpegstats, 0, sizeof(codecstats_t));
memset(&webpstats, 0, sizeof(codecstats_t));
if (allowLossy && activeEncoders[encoderFullColour] == encoderTightWEBP) {
const unsigned rate = 1024 * 1000 / rfb::Server::frameRate;
@@ -1014,6 +1016,7 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb,
std::vector<uint8_t> isWebp, fromCache;
std::vector<Palette> palettes;
std::vector<std::vector<uint8_t> > compresseds;
std::vector<uint32_t> ms;
uint32_t i;
if (rfb::Server::rectThreads > 0)
@@ -1078,9 +1081,13 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb,
palettes.resize(subrects.size());
compresseds.resize(subrects.size());
scaledrects.resize(subrects.size());
ms.resize(subrects.size());
// In case the current resolution is above the max video res, and video was detected,
// scale to that res, keeping aspect ratio
struct timeval scalestart;
gettimeofday(&scalestart, NULL);
const PixelBuffer *scaledpb = NULL;
if (videoDetected &&
(maxVideoX < pb->getRect().width() || maxVideoY < pb->getRect().height())) {
@@ -1129,15 +1136,25 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb,
}
}
}
scalingTime = msSince(&scalestart);
#pragma omp parallel for schedule(dynamic, 1)
for (i = 0; i < subrects.size(); ++i) {
encoderTypes[i] = getEncoderType(subrects[i], pb, &palettes[i], compresseds[i],
&isWebp[i], &fromCache[i],
scaledpb, scaledrects[i]);
scaledpb, scaledrects[i], ms[i]);
checkWebpFallback(start);
}
for (i = 0; i < subrects.size(); ++i) {
if (encoderTypes[i] == encoderFullColour) {
if (isWebp[i])
webpstats.ms += ms[i];
else
jpegstats.ms += ms[i];
}
}
if (start) {
encodingTime = msSince(start);
@@ -1178,7 +1195,8 @@ void EncodeManager::writeRects(const Region& changed, const PixelBuffer* pb,
uint8_t EncodeManager::getEncoderType(const Rect& rect, const PixelBuffer *pb,
Palette *pal, std::vector<uint8_t> &compressed,
uint8_t *isWebp, uint8_t *fromCache,
const PixelBuffer *scaledpb, const Rect& scaledrect) const
const PixelBuffer *scaledpb, const Rect& scaledrect,
uint32_t &ms) const
{
struct RectInfo info;
unsigned int maxColours = 256;
@@ -1231,9 +1249,12 @@ uint8_t EncodeManager::getEncoderType(const Rect& rect, const PixelBuffer *pb,
*isWebp = 0;
*fromCache = 0;
ms = 0;
if (type == encoderFullColour) {
uint32_t len;
const void *data;
struct timeval start;
gettimeofday(&start, NULL);
if (encCache->enabled &&
(data = encCache->get(activeEncoders[encoderFullColour],
@@ -1274,6 +1295,8 @@ uint8_t EncodeManager::getEncoderType(const Rect& rect, const PixelBuffer *pb,
compressed,
videoDetected);
}
ms = msSince(&start);
}
delete ppb;
@@ -1292,10 +1315,15 @@ void EncodeManager::writeSubRect(const Rect& rect, const PixelBuffer *pb,
encoder = startRect(rect, type, compressed.size() == 0, isWebp);
if (compressed.size()) {
if (isWebp)
if (isWebp) {
((TightWEBPEncoder *) encoder)->writeOnly(compressed);
else
webpstats.area += rect.area();
webpstats.rects++;
} else {
((TightJPEGEncoder *) encoder)->writeOnly(compressed);
jpegstats.area += rect.area();
jpegstats.rects++;
}
} else {
if (encoder->flags & EncoderUseNativePF) {
ppb = preparePixelBuffer(rect, pb, false);

View File

@@ -68,9 +68,24 @@ namespace rfb {
const RenderedCursor* renderedCursor,
size_t maxUpdateSize);
void clearEncodingTime() {
encodingTime = 0;
};
unsigned getEncodingTime() const {
return encodingTime;
};
unsigned getScalingTime() const {
return scalingTime;
};
struct codecstats_t {
uint32_t ms;
uint32_t area;
uint32_t rects;
};
codecstats_t jpegstats, webpstats;
protected:
void doUpdate(bool allowLossy, const Region& changed,
@@ -105,7 +120,8 @@ namespace rfb {
uint8_t getEncoderType(const Rect& rect, const PixelBuffer *pb, Palette *pal,
std::vector<uint8_t> &compressed, uint8_t *isWebp,
uint8_t *fromCache,
const PixelBuffer *scaledpb, const Rect& scaledrect) const;
const PixelBuffer *scaledpb, const Rect& scaledrect,
uint32_t &ms) const;
virtual bool handleTimeout(Timer* t);
bool checkSolidTile(const Rect& r, const rdr::U8* colourValue,
@@ -183,6 +199,7 @@ namespace rfb {
bool webpTookTooLong;
unsigned encodingTime;
unsigned maxEncodingTime, framesSinceEncPrint;
unsigned scalingTime;
EncCache *encCache;

View File

@@ -63,7 +63,8 @@ namespace rfb {
const size_t* lengths,
const rdr::U8* const* data);
virtual void sendStats() = 0;
virtual void sendStats(const bool toClient = true) = 0;
virtual void handleFrameStats(rdr::U32 all, rdr::U32 render) = 0;
virtual bool canChangeKasmSettings() const = 0;

View File

@@ -80,6 +80,9 @@ void SMsgReader::readMsg()
case msgTypeRequestStats:
readRequestStats();
break;
case msgTypeFrameStats:
readFrameStats();
break;
case msgTypeKeyEvent:
readKeyEvent();
break;
@@ -346,6 +349,14 @@ void SMsgReader::readRequestStats()
handler->sendStats();
}
void SMsgReader::readFrameStats()
{
is->skip(3);
rdr::U32 all = is->readU32();
rdr::U32 render = is->readU32();
handler->handleFrameStats(all, render);
}
void SMsgReader::readQEMUMessage()
{
int subType = is->readU8();

View File

@@ -57,6 +57,7 @@ namespace rfb {
void readClientCutText();
void readExtendedClipboard(rdr::S32 len);
void readRequestStats();
void readFrameStats();
void readQEMUMessage();
void readQEMUKeyEvent();

View File

@@ -43,6 +43,7 @@ SMsgWriter::SMsgWriter(ConnParams* cp_, rdr::OutStream* os_)
needSetDesktopSize(false), needExtendedDesktopSize(false),
needSetDesktopName(false), needSetCursor(false),
needSetXCursor(false), needSetCursorWithAlpha(false),
needSetVMWareCursor(false),
needCursorPos(false),
needLEDState(false), needQEMUKeyEvent(false)
{
@@ -208,6 +209,12 @@ void SMsgWriter::writeStats(const char* str, int len)
endMsg();
}
void SMsgWriter::writeRequestFrameStats()
{
startMsg(msgTypeRequestFrameStats);
endMsg();
}
void SMsgWriter::writeFence(rdr::U32 flags, unsigned len, const char data[])
{
if (!cp->supportsFence)
@@ -315,6 +322,16 @@ bool SMsgWriter::writeSetCursorWithAlpha()
return true;
}
bool SMsgWriter::writeSetVMwareCursor()
{
if (!cp->supportsVMWareCursor)
return false;
needSetVMWareCursor = true;
return true;
}
void SMsgWriter::writeCursorPos()
{
if (!cp->supportsEncoding(pseudoEncodingVMwareCursorPosition))
@@ -349,7 +366,7 @@ bool SMsgWriter::needFakeUpdate()
{
if (needSetDesktopName)
return true;
if (needSetCursor || needSetXCursor || needSetCursorWithAlpha)
if (needSetCursor || needSetXCursor || needSetCursorWithAlpha || needSetVMWareCursor)
return true;
if (needCursorPos)
return true;
@@ -405,6 +422,8 @@ void SMsgWriter::writeFramebufferUpdateStart(int nRects)
nRects++;
if (needSetCursorWithAlpha)
nRects++;
if (needSetVMWareCursor)
nRects++;
if (needCursorPos)
nRects++;
if (needLEDState)
@@ -522,6 +541,15 @@ void SMsgWriter::writePseudoRects()
needSetCursorWithAlpha = false;
}
if (needSetVMWareCursor) {
const Cursor& cursor = cp->cursor();
writeSetVMwareCursorRect(cursor.width(), cursor.height(),
cursor.hotspot().x, cursor.hotspot().y,
cursor.getBuffer());
needSetVMWareCursor = false;
}
if (needCursorPos) {
const Point& cursorPos = cp->cursorPos();
@@ -712,6 +740,28 @@ void SMsgWriter::writeSetCursorWithAlphaRect(int width, int height,
}
}
void SMsgWriter::writeSetVMwareCursorRect(int width, int height,
int hotspotX, int hotspotY,
const rdr::U8* data)
{
if (!cp->supportsVMWareCursor)
throw Exception("Client does not support local cursors");
if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader)
throw Exception("SMsgWriter::writeSetVMwareCursorRect: nRects out of sync");
os->writeS16(hotspotX);
os->writeS16(hotspotY);
os->writeU16(width);
os->writeU16(height);
os->writeU32(pseudoEncodingVMwareCursor);
os->writeU8(1); // Alpha cursor
os->pad(1);
// FIXME: Should alpha be premultiplied?
os->writeBytes(data, width*height*4);
}
void SMsgWriter::writeSetVMwareCursorPositionRect(int hotspotX, int hotspotY)
{
if (!cp->supportsEncoding(pseudoEncodingVMwareCursorPosition))

View File

@@ -65,6 +65,8 @@ namespace rfb {
void writeStats(const char* str, int len);
void writeRequestFrameStats();
// writeFence() sends a new fence request or response to the client.
void writeFence(rdr::U32 flags, unsigned len, const char data[]);
@@ -90,6 +92,7 @@ namespace rfb {
bool writeSetCursor();
bool writeSetXCursor();
bool writeSetCursorWithAlpha();
bool writeSetVMwareCursor();
// Notifies the client that the cursor pointer was moved by the server.
void writeCursorPos();
@@ -149,6 +152,9 @@ namespace rfb {
void writeSetCursorWithAlphaRect(int width, int height,
int hotspotX, int hotspotY,
const rdr::U8* data);
void writeSetVMwareCursorRect(int width, int height,
int hotspotX, int hotspotY,
const rdr::U8* data);
void writeSetVMwareCursorPositionRect(int hotspotX, int hotspotY);
void writeLEDStateRect(rdr::U8 state);
void writeQEMUKeyEventRect();
@@ -165,6 +171,7 @@ namespace rfb {
bool needSetCursor;
bool needSetXCursor;
bool needSetCursorWithAlpha;
bool needSetVMWareCursor;
bool needCursorPos;
bool needLEDState;
bool needQEMUKeyEvent;

View File

@@ -17,6 +17,7 @@
* USA.
*/
#include <network/GetAPI.h>
#include <network/TcpSocket.h>
#include <rfb/ComparingUpdateTracker.h>
@@ -61,7 +62,7 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s,
continuousUpdates(false), encodeManager(this, &server_->encCache),
needsPermCheck(false), pointerEventTime(0),
clientHasCursor(false),
accessRights(AccessDefault), startTime(time(0))
accessRights(AccessDefault), startTime(time(0)), frameTracking(false)
{
setStreams(&sock->inStream(), &sock->outStream());
peerEndpoint.buf = sock->getPeerEndpoint();
@@ -98,6 +99,9 @@ VNCSConnectionST::VNCSConnectionST(VNCServerST* server_, network::Socket *s,
gettimeofday(&lastKeyEvent, NULL);
server->clients.push_front(this);
if (server->apimessager)
server->apimessager->mainUpdateUserInfo(checkOwnerConn(), server->clients.size());
}
@@ -128,6 +132,11 @@ VNCSConnectionST::~VNCSConnectionST()
server->clients.remove(this);
delete [] fenceData;
if (server->apimessager) {
server->apimessager->mainUpdateUserInfo(checkOwnerConn(), server->clients.size());
server->apimessager->mainClearBottleneckStats(peerEndpoint.buf);
}
}
@@ -567,6 +576,7 @@ bool VNCSConnectionST::needRenderedCursor()
return false;
if (!cp.supportsLocalCursorWithAlpha &&
!cp.supportsVMWareCursor &&
!cp.supportsLocalCursor && !cp.supportsLocalXCursor)
return true;
if (!server->cursorPos.equals(pointerEventPos) &&
@@ -1184,6 +1194,7 @@ bool VNCSConnectionST::isCongested()
void VNCSConnectionST::writeFramebufferUpdate()
{
congestion.updatePosition(sock->outStream().length());
encodeManager.clearEncodingTime();
// We're in the middle of processing a command that's supposed to be
// synchronised. Allowing an update to slip out right now might violate
@@ -1229,6 +1240,9 @@ void VNCSConnectionST::writeFramebufferUpdate()
// window.
sock->cork(true);
if (frameTracking)
writer()->writeRequestFrameStats();
// First take care of any updates that cannot contain framebuffer data
// changes.
writeNoDataUpdate();
@@ -1459,7 +1473,7 @@ static void pruneStatList(std::list<struct timeval> &list, const struct timeval
}
}
void VNCSConnectionST::sendStats() {
void VNCSConnectionST::sendStats(const bool toClient) {
char buf[1024];
struct timeval now;
@@ -1498,8 +1512,28 @@ void VNCSConnectionST::sendStats() {
#undef ten
vlog.info("Sending client stats:\n%s\n", buf);
writer()->writeStats(buf, strlen(buf));
if (toClient) {
vlog.info("Sending client stats:\n%s\n", buf);
writer()->writeStats(buf, strlen(buf));
} else if (server->apimessager) {
server->apimessager->mainUpdateBottleneckStats(peerEndpoint.buf, buf);
}
}
void VNCSConnectionST::handleFrameStats(rdr::U32 all, rdr::U32 render)
{
if (server->apimessager) {
const char *at = strchr(peerEndpoint.buf, '@');
if (!at)
at = peerEndpoint.buf;
else
at++;
server->apimessager->mainUpdateClientFrameStats(at, render, all,
congestion.getPingTime());
}
frameTracking = false;
}
// setCursor() is called whenever the cursor has changed shape or pixel format.
@@ -1520,11 +1554,13 @@ void VNCSConnectionST::setCursor()
clientHasCursor = true;
}
if (!writer()->writeSetCursorWithAlpha()) {
if (!writer()->writeSetCursor()) {
if (!writer()->writeSetXCursor()) {
// No client support
return;
if (!writer()->writeSetVMwareCursor()) {
if (!writer()->writeSetCursorWithAlpha()) {
if (!writer()->writeSetCursor()) {
if (!writer()->writeSetXCursor()) {
// No client support
return;
}
}
}
}
@@ -1611,3 +1647,15 @@ int VNCSConnectionST::getStatus()
return 4;
}
bool VNCSConnectionST::checkOwnerConn() const
{
std::list<VNCSConnectionST*>::const_iterator it;
for (it = server->clients.begin(); it != server->clients.end(); it++) {
bool write, owner;
if ((*it)->getPerms(write, owner) && owner)
return true;
}
return false;
}

View File

@@ -164,6 +164,35 @@ namespace rfb {
void setStatus(int status);
int getStatus();
virtual void sendStats(const bool toClient = true);
virtual void handleFrameStats(rdr::U32 all, rdr::U32 render);
bool is_owner() const {
bool write, owner;
if (getPerms(write, owner) && owner)
return true;
return false;
}
void setFrameTracking() {
frameTracking = true;
}
EncodeManager::codecstats_t getJpegStats() const {
return encodeManager.jpegstats;
}
EncodeManager::codecstats_t getWebpStats() const {
return encodeManager.webpstats;
}
unsigned getEncodingTime() const {
return encodeManager.getEncodingTime();
}
unsigned getScalingTime() const {
return encodeManager.getScalingTime();
}
private:
// SConnection callbacks
@@ -191,7 +220,6 @@ namespace rfb {
virtual void supportsContinuousUpdates();
virtual void supportsLEDState();
virtual void sendStats();
virtual bool canChangeKasmSettings() const {
return (accessRights & (AccessPtrEvents | AccessKeyEvents)) ==
(AccessPtrEvents | AccessKeyEvents);
@@ -219,6 +247,8 @@ namespace rfb {
bool getPerms(bool &write, bool &owner) const;
bool checkOwnerConn() const;
// Congestion control
void writeRTTPing();
bool isCongested();
@@ -294,6 +324,8 @@ namespace rfb {
time_t startTime;
std::vector<CopyPassRect> copypassed;
bool frameTracking;
};
}
#endif

View File

@@ -128,7 +128,7 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_)
renderedCursorInvalid(false),
queryConnectionHandler(0), keyRemapper(&KeyRemapper::defInstance),
lastConnectionTime(0), disableclients(false),
frameTimer(this), apimessager(NULL)
frameTimer(this), apimessager(NULL), trackingFrameStats(0)
{
lastUserInputTime = lastDisconnectTime = time(0);
slog.debug("creating single-threaded server %s", name.buf);
@@ -210,6 +210,8 @@ VNCServerST::VNCServerST(const char* name_, SDesktop* desktop_)
if (inotify_add_watch(inotifyfd, kasmpasswdpath, IN_CLOSE_WRITE | IN_DELETE_SELF) < 0)
slog.error("Failed to set watch");
}
trackingClient[0] = 0;
}
VNCServerST::~VNCServerST()
@@ -271,6 +273,11 @@ void VNCServerST::removeSocket(network::Socket* sock) {
std::list<VNCSConnectionST*>::iterator ci;
for (ci = clients.begin(); ci != clients.end(); ci++) {
if ((*ci)->getSock() == sock) {
if (clipboardClient == *ci)
handleClipboardAnnounce(*ci, false);
clipboardRequestors.remove(*ci);
// - Delete the per-Socket resources
delete *ci;
@@ -774,7 +781,8 @@ int VNCServerST::msToNextUpdate()
return frameTimer.getRemainingMs();
}
static void checkAPIMessages(network::GetAPIMessager *apimessager)
static void checkAPIMessages(network::GetAPIMessager *apimessager,
rdr::U8 &trackingFrameStats, char trackingClient[])
{
if (pthread_mutex_lock(&apimessager->userMutex))
return;
@@ -827,6 +835,20 @@ static void checkAPIMessages(network::GetAPIMessager *apimessager)
slog.error("Tried to give control to nonexistent user %s", act.data.user);
}
break;
case network::GetAPIMessager::WANT_FRAME_STATS_SERVERONLY:
trackingFrameStats = act.action;
break;
case network::GetAPIMessager::WANT_FRAME_STATS_ALL:
trackingFrameStats = act.action;
break;
case network::GetAPIMessager::WANT_FRAME_STATS_OWNER:
trackingFrameStats = act.action;
break;
case network::GetAPIMessager::WANT_FRAME_STATS_SPECIFIC:
trackingFrameStats = act.action;
memcpy(trackingClient, act.data.password, 128);
break;
}
if (set) {
@@ -923,6 +945,9 @@ void VNCServerST::writeUpdate()
assert(blockCounter == 0);
assert(desktopStarted);
struct timeval start;
gettimeofday(&start, NULL);
if (DLPRegion.enabled) {
comparer->enable_copyrect(false);
blackOut();
@@ -949,6 +974,9 @@ void VNCServerST::writeUpdate()
else
comparer->disable();
struct timeval beforeAnalysis;
gettimeofday(&beforeAnalysis, NULL);
// Skip scroll detection if the client is slow, and didn't get the previous one yet
if (comparer->compare(clients.size() == 1 && (*clients.begin())->has_copypassed(),
cursorReg))
@@ -956,6 +984,8 @@ void VNCServerST::writeUpdate()
comparer->clear();
const unsigned analysisMs = msSince(&beforeAnalysis);
encCache.clear();
encCache.enabled = clients.size() > 1;
@@ -981,11 +1011,22 @@ void VNCServerST::writeUpdate()
}
}
unsigned shottime = 0;
if (apimessager) {
struct timeval shotstart;
gettimeofday(&shotstart, NULL);
apimessager->mainUpdateScreen(pb);
shottime = msSince(&shotstart);
checkAPIMessages(apimessager);
trackingFrameStats = 0;
checkAPIMessages(apimessager, trackingFrameStats, trackingClient);
}
const rdr::U8 origtrackingFrameStats = trackingFrameStats;
EncodeManager::codecstats_t jpegstats, webpstats;
unsigned enctime = 0, scaletime = 0;
memset(&jpegstats, 0, sizeof(EncodeManager::codecstats_t));
memset(&webpstats, 0, sizeof(EncodeManager::codecstats_t));
for (ci = clients.begin(); ci != clients.end(); ci = ci_next) {
ci_next = ci; ci_next++;
@@ -993,10 +1034,68 @@ void VNCServerST::writeUpdate()
if (permcheck)
(*ci)->recheckPerms();
if (trackingFrameStats == network::GetAPIMessager::WANT_FRAME_STATS_ALL ||
(trackingFrameStats == network::GetAPIMessager::WANT_FRAME_STATS_OWNER &&
(*ci)->is_owner()) ||
(trackingFrameStats == network::GetAPIMessager::WANT_FRAME_STATS_SPECIFIC &&
strstr((*ci)->getPeerEndpoint(), trackingClient))) {
(*ci)->setFrameTracking();
// Only one owner
if (trackingFrameStats == network::GetAPIMessager::WANT_FRAME_STATS_OWNER)
trackingFrameStats = network::GetAPIMessager::WANT_FRAME_STATS_SERVERONLY;
}
(*ci)->add_copied(ui.copied, ui.copy_delta);
(*ci)->add_copypassed(ui.copypassed);
(*ci)->add_changed(ui.changed);
(*ci)->writeFramebufferUpdateOrClose();
if (apimessager) {
(*ci)->sendStats(false);
const EncodeManager::codecstats_t subjpeg = (*ci)->getJpegStats();
const EncodeManager::codecstats_t subwebp = (*ci)->getWebpStats();
jpegstats.ms += subjpeg.ms;
jpegstats.area += subjpeg.area;
jpegstats.rects += subjpeg.rects;
webpstats.ms += subwebp.ms;
webpstats.area += subwebp.area;
webpstats.rects += subwebp.rects;
enctime += (*ci)->getEncodingTime();
scaletime += (*ci)->getScalingTime();
}
}
if (trackingFrameStats) {
if (enctime) {
const unsigned totalMs = msSince(&start);
if (apimessager)
apimessager->mainUpdateServerFrameStats(comparer->changedPerc, totalMs,
jpegstats.ms, webpstats.ms,
analysisMs,
jpegstats.area, webpstats.area,
jpegstats.rects, webpstats.rects,
enctime, scaletime, shottime,
pb->getRect().width(),
pb->getRect().height());
} else {
// Zero encoding time means this was a no-data frame; restore the stats request
if (apimessager && pthread_mutex_lock(&apimessager->userMutex) == 0) {
network::GetAPIMessager::action_data act;
act.action = (network::GetAPIMessager::USER_ACTION) origtrackingFrameStats;
memcpy(act.data.password, trackingClient, 128);
apimessager->actionQueue.push_back(act);
pthread_mutex_unlock(&apimessager->userMutex);
}
}
}
}

View File

@@ -267,6 +267,9 @@ namespace rfb {
network::GetAPIMessager *apimessager;
rdr::U8 trackingFrameStats;
char trackingClient[128];
struct {
bool enabled;
int x1, y1, x2, y2;

View File

@@ -86,6 +86,7 @@ namespace rfb {
const int pseudoEncodingVideoOutTimeLevel100 = -1887;
// VMware-specific
const int pseudoEncodingVMwareCursor = 0x574d5664;
const int pseudoEncodingVMwareCursorPosition = 0x574d5666;
// UltraVNC-specific

View File

@@ -30,6 +30,7 @@ namespace rfb {
// kasm
const int msgTypeStats = 178;
const int msgTypeRequestFrameStats = 179;
const int msgTypeServerFence = 248;
@@ -47,6 +48,7 @@ namespace rfb {
// kasm
const int msgTypeRequestStats = 178;
const int msgTypeFrameStats = 179;
const int msgTypeClientFence = 248;

View File

@@ -16,6 +16,7 @@ install: unpack_tarball
cp $(SRC_BIN)/vncserver $(DESTDIR)/usr/bin/kasmvncserver
cp $(SRC_BIN)/vncconfig $(DESTDIR)/usr/bin/kasmvncconfig
cp $(SRC_BIN)/kasmvncpasswd $(DESTDIR)/usr/bin/
cp $(SRC_BIN)/kasmxproxy $(DESTDIR)/usr/bin/
cp -r $(SRC)/share/doc/kasmvnc*/* $(DESTDIR)/usr/share/doc/kasmvncserver/
rsync -r --exclude '.git*' --exclude po2js --exclude xgettext-html \
--exclude www/utils/ --exclude .eslintrc \

2
debian/control vendored
View File

@@ -3,7 +3,7 @@ Section: x11
Priority: optional
Maintainer: Kasm Technologies LLC <info@kasmweb.com>
Build-Depends: debhelper (>= 11), rsync, libjpeg-dev, libjpeg-dev, libpng-dev,
libtiff-dev, libgif-dev, libavcodec-dev, libssl-dev, libgl1, libxfont2, libsm6
libtiff-dev, libgif-dev, libavcodec-dev, libssl-dev, libgl1, libxfont2, libsm6, libxext-dev, libxrandr-dev, libxtst-dev, libxcursor-dev
Standards-Version: 4.1.3
Homepage: https://github.com/kasmtech/KasmVNC
#Vcs-Browser: https://salsa.debian.org/debian/kasmvnc

2
debian/postinst vendored
View File

@@ -21,7 +21,7 @@ case "$1" in
configure)
bindir=/usr/bin
mandir=/usr/share/man
commands="kasmvncserver kasmvncpasswd kasmvncconfig Xkasmvnc"
commands="kasmvncserver kasmvncpasswd kasmvncconfig Xkasmvnc kasmxproxy"
for kasm_command in $commands; do
generic_command=`echo "$kasm_command" | sed -e 's/kasm//'`;

2
debian/prerm vendored
View File

@@ -21,7 +21,7 @@ case "$1" in
remove)
bindir=/usr/bin
mandir=/usr/share/man
commands="kasmvncserver kasmvncpasswd kasmvncconfig Xkasmvnc"
commands="kasmvncserver kasmvncpasswd kasmvncconfig Xkasmvnc kasmxproxy"
for kasm_command in $commands; do
generic_command=`echo "$kasm_command" | sed -e 's/kasm//'`;

Submodule kasmweb updated: 67466077c0...ba40cacce0

View File

@@ -45,6 +45,7 @@ mkdir -p $OUTDIR/man/man1
make DESTDIR=$TMPDIR/inst install
if [ $SERVER = 1 ]; then
install -m 755 ./unix/kasmxproxy/kasmxproxy $OUTDIR/bin/
install -m 755 ./xorg.build/bin/Xvnc $OUTDIR/bin/
install -m 644 ./xorg.build/man/man1/Xvnc.1 $OUTDIR/man/man1/Xvnc.1
install -m 644 ./xorg.build/man/man1/Xserver.1 $OUTDIR/man/man1/Xserver.1

View File

@@ -3,6 +3,7 @@ add_subdirectory(common)
add_subdirectory(vncconfig)
add_subdirectory(vncpasswd)
add_subdirectory(kasmvncpasswd)
add_subdirectory(kasmxproxy)
install(PROGRAMS vncserver DESTINATION ${BIN_DIR})
install(FILES vncserver.man DESTINATION ${MAN_DIR}/man1 RENAME vncserver.1)

1
unix/kasmxproxy/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
kasmxproxy

View File

@@ -0,0 +1,11 @@
include_directories(${X11_INCLUDE_DIR})
add_executable(kasmxproxy
xxhash.c
kasmxproxy.c)
target_link_libraries(kasmxproxy ${X11_LIBRARIES} ${X11_XTest_LIB} ${X11_Xrandr_LIB}
${X11_Xcursor_LIB} ${X11_Xfixes_LIB})
install(TARGETS kasmxproxy DESTINATION ${BIN_DIR})
install(FILES kasmxproxy.man DESTINATION ${MAN_DIR}/man1 RENAME kasmxproxy.1)

View File

@@ -0,0 +1,530 @@
/* Copyright (C) 2021 Kasm. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
#include <getopt.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <unistd.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xcursor/Xcursor.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xrandr.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/XTest.h>
#include "xxhash.h"
#define min(a, b) ((a) < (b) ? (a) : (b))
static void help(const char name[]) {
printf("Usage: %s [opts]\n\n"
"-a --app-display disp App display, default :0\n"
"-v --vnc-display disp VNC display, default :1\n"
"\n"
"-f --fps fps FPS, default 30\n"
"-r --resize Enable resize, default disabled.\n"
" Do not enable this if there's a physical screen\n"
" connected to the app display.\n",
name);
exit(1);
}
#define CUT_MAX (16 * 1024)
static uint8_t cutbuf[CUT_MAX];
static void supplyselection(Display *disp, const XEvent * const ev, const Atom xa_targets) {
XSelectionEvent sev;
sev.type = SelectionNotify;
sev.display = disp;
sev.requestor = ev->xselectionrequest.requestor;
sev.selection = ev->xselectionrequest.selection;
sev.target = ev->xselectionrequest.target;
sev.time = ev->xselectionrequest.time;
/*printf("someone wants our clipboard, sel %lu, tgt %lu, prop %lu\n",
sev.selection, sev.target,
ev.xselectionrequest.property);*/
if (ev->xselectionrequest.property == None)
sev.property = sev.target;
else
sev.property = ev->xselectionrequest.property;
const uint32_t len = strlen((char *) cutbuf);
if (xa_targets != None &&
sev.target == xa_targets) {
// Which formats can we do
Atom tgt[2] = {
xa_targets,
XA_STRING
};
XChangeProperty(disp, sev.requestor,
ev->xselectionrequest.property,
XA_ATOM, 32,
PropModeReplace,
(unsigned char *) tgt,
2);
//puts("sent targets");
} else {
// Data
XChangeProperty(disp, sev.requestor,
ev->xselectionrequest.property,
sev.target, 8,
PropModeReplace,
cutbuf, len);
//printf("sent data, of len %u\n", len);
}
// Send the notify event
XSendEvent(disp, sev.requestor, False, 0,
(XEvent *) &sev);
}
int main(int argc, char **argv) {
const char *appstr = ":0";
const char *vncstr = ":1";
uint8_t resize = 0;
uint8_t fps = 30;
const struct option longargs[] = {
{"app-display", 1, NULL, 'a'},
{"vnc-display", 1, NULL, 'v'},
{"resize", 0, NULL, 'r'},
{"fps", 1, NULL, 'f'},
{NULL, 0, NULL, 0},
};
while (1) {
int c = getopt_long(argc, argv, "a:v:rf:", longargs, NULL);
if (c == -1)
break;
switch (c) {
case 'a':
appstr = strdup(optarg);
break;
case 'v':
vncstr = strdup(optarg);
break;
case 'r':
resize = 1;
break;
case 'f':
fps = atoi(optarg);
if (fps < 1 || fps > 120) {
printf("Invalid fps\n");
return 1;
}
break;
default:
help(argv[0]);
break;
}
}
Display *appdisp = XOpenDisplay(appstr);
if (!appdisp) {
printf("Cannot open display %s\n", appstr);
return 1;
}
if (!XShmQueryExtension(appdisp)) {
printf("Display %s lacks SHM extension\n", appstr);
return 1;
}
Display *vncdisp = XOpenDisplay(vncstr);
if (!vncdisp) {
printf("Cannot open display %s\n", vncstr);
return 1;
}
if (!XShmQueryExtension(vncdisp)) {
printf("Display %s lacks SHM extension\n", vncstr);
return 1;
}
const int appscreen = DefaultScreen(appdisp);
const int vncscreen = DefaultScreen(vncdisp);
Visual *appvis = DefaultVisual(appdisp, appscreen);
//Visual *vncvis = DefaultVisual(vncdisp, vncscreen);
const int appdepth = DefaultDepth(appdisp, appscreen);
const int vncdepth = DefaultDepth(vncdisp, vncscreen);
if (appdepth != vncdepth) {
printf("Depths don't match, app %u vnc %u\n", appdepth, vncdepth);
return 1;
}
Window approot = DefaultRootWindow(appdisp);
Window vncroot = DefaultRootWindow(vncdisp);
XWindowAttributes appattr, vncattr;
XGCValues gcval;
gcval.plane_mask = AllPlanes;
gcval.function = GXcopy;
GC gc = XCreateGC(vncdisp, vncroot, GCFunction | GCPlaneMask, &gcval);
XImage *img = NULL;
XShmSegmentInfo shminfo;
unsigned imgw = 0, imgh = 0;
if (XGrabPointer(vncdisp, vncroot, False,
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, None,
CurrentTime) != Success)
return 1;
if (XGrabKeyboard(vncdisp, vncroot, False, GrabModeAsync, GrabModeAsync,
CurrentTime) != Success)
return 1;
int xfixesbase, xfixeserrbase;
XFixesQueryExtension(appdisp, &xfixesbase, &xfixeserrbase);
XFixesSelectSelectionInput(appdisp, approot, XA_PRIMARY,
XFixesSetSelectionOwnerNotifyMask);
int xfixesbasevnc, xfixeserrbasevnc;
XFixesQueryExtension(vncdisp, &xfixesbasevnc, &xfixeserrbasevnc);
XFixesSelectSelectionInput(vncdisp, vncroot, XA_PRIMARY,
XFixesSetSelectionOwnerNotifyMask);
Atom xa_targets_vnc = XInternAtom(vncdisp, "TARGETS", False);
Atom xa_targets_app = XInternAtom(appdisp, "TARGETS", False);
Window selwin = XCreateSimpleWindow(appdisp, approot, 3, 2, 1, 1, 0, 0, 0);
Window vncselwin = XCreateSimpleWindow(vncdisp, vncroot, 3, 2, 1, 1, 0, 0, 0);
XFixesCursorImage *cursor = NULL;
uint64_t cursorhash = 0;
Cursor xcursor = None;
const unsigned sleeptime = 1000 * 1000 / fps;
while (1) {
if (!XGetWindowAttributes(appdisp, approot, &appattr))
break;
if (!XGetWindowAttributes(vncdisp, vncroot, &vncattr))
break;
if (resize && (appattr.width != vncattr.width ||
appattr.height != vncattr.height)) {
// resize app display to VNC display size
XRRScreenConfiguration *config = XRRGetScreenInfo(appdisp, approot);
int nsizes, i, match = -1;
XRRScreenSize *sizes = XRRConfigSizes(config, &nsizes);
//printf("%u sizes\n", nsizes);
for (i = 0; i < nsizes; i++) {
if (sizes[i].width == vncattr.width &&
sizes[i].height == vncattr.height) {
//printf("match %u\n", i);
match = i;
break;
}
}
if (match >= 0) {
XRRSetScreenConfig(appdisp, config, approot, match,
RR_Rotate_0, CurrentTime);
} else {
/*XRRSetScreenSize(appdisp, approot,
vncattr.width, vncattr.height,
sizes[0].mwidth, sizes[0].mheight);*/
XRRScreenResources *res = XRRGetScreenResources(appdisp, approot);
//printf("%u outputs, %u crtcs\n", res->noutput, res->ncrtc);
// Nvidia crap uses a *different* list for 1.0 and 1.2!
unsigned oldmode = 0xffff;
//printf("1.2 modes %u\n", res->nmode);
for (i = 0; i < res->nmode; i++) {
if (res->modes[i].width == vncattr.width &&
res->modes[i].height == vncattr.height) {
oldmode = i;
//printf("old mode %u matched\n", i);
break;
}
}
unsigned tgt = 0;
if (res->noutput > 1) {
for (i = 0; i < res->noutput; i++) {
XRROutputInfo *info = XRRGetOutputInfo(appdisp, res, res->outputs[i]);
if (info->connection == RR_Connected)
tgt = i;
//printf("%u %s %u\n", i, info->name, info->connection);
XRRFreeOutputInfo(info);
}
}
if (oldmode < 0xffff) {
Status s;
// nvidia needs this weird dance
s = XRRSetCrtcConfig(appdisp, res, res->crtcs[tgt],
CurrentTime,
0, 0,
None, RR_Rotate_0,
NULL, 0);
//printf("disable %u\n", s);
XRRSetScreenSize(appdisp, approot,
vncattr.width, vncattr.height,
sizes[0].mwidth, sizes[0].mheight);
s = XRRSetCrtcConfig(appdisp, res, res->crtcs[tgt],
CurrentTime,
0, 0,
res->modes[oldmode].id, RR_Rotate_0,
&res->outputs[tgt], 1);
//printf("set %u\n", s);
} else {
char name[32];
sprintf(name, "%ux%u_60", vncattr.width, vncattr.height);
printf("Creating new Mode %s\n", name);
XRRModeInfo *mode = XRRAllocModeInfo(name, strlen(name));
mode->width = vncattr.width;
mode->height = vncattr.height;
RRMode rmode = XRRCreateMode(appdisp, approot, mode);
XRRAddOutputMode(appdisp,
res->outputs[tgt],
rmode);
XRRFreeModeInfo(mode);
}
XRRFreeScreenResources(res);
}
XRRFreeScreenConfigInfo(config);
}
const unsigned w = min(appattr.width, vncattr.width);
const unsigned h = min(appattr.height, vncattr.height);
if (w != imgw || h != imgh) {
if (img) {
XShmDetach(appdisp, &shminfo);
XDestroyImage(img);
shmdt(shminfo.shmaddr);
shmctl(shminfo.shmid, IPC_RMID, NULL);
}
img = XShmCreateImage(appdisp, appvis, appdepth, ZPixmap,
NULL, &shminfo, w, h);
if (!img)
break;
shminfo.shmid = shmget(IPC_PRIVATE,
img->bytes_per_line * img->height,
IPC_CREAT | 0666);
if (shminfo.shmid == -1)
break;
shminfo.shmaddr = img->data = shmat(shminfo.shmid, 0, 0);
shminfo.readOnly = False;
if (!XShmAttach(appdisp, &shminfo))
break;
imgw = w;
imgh = h;
}
XShmGetImage(appdisp, approot, img, 0, 0, 0xffffffff);
XPutImage(vncdisp, vncroot, gc, img, 0, 0, 0, 0, w, h);
// Handle events
while (XPending(vncdisp)) {
XEvent ev;
XNextEvent(vncdisp, &ev);
if (ev.type == xfixesbasevnc + XFixesSelectionNotify) {
XFixesSelectionNotifyEvent *xfe =
(XFixesSelectionNotifyEvent *) &ev;
// printf("vnc disp did a copy, owner %lu, root %lu\n",
// xfe->owner, vncroot);
if (xfe->owner == None || xfe->owner == vncroot)
continue;
XConvertSelection(vncdisp, XA_PRIMARY, XA_STRING, XA_STRING,
vncselwin, CurrentTime);
} else switch (ev.type) {
case KeyPress:
case KeyRelease:
XTestFakeKeyEvent(appdisp, ev.xkey.keycode,
ev.type == KeyPress,
CurrentTime);
break;
case ButtonPress:
case ButtonRelease:
XTestFakeButtonEvent(appdisp, ev.xbutton.button,
ev.type == ButtonPress,
CurrentTime);
break;
case MotionNotify:
XTestFakeMotionEvent(appdisp, appscreen,
ev.xmotion.x,
ev.xmotion.y,
CurrentTime);
break;
case SelectionRequest:
supplyselection(vncdisp, &ev, xa_targets_vnc);
break;
case SelectionNotify:
{
Atom realtype;
int fmt;
unsigned long nitems, bytes_rem;
unsigned char *data;
if (XGetWindowProperty(vncdisp, vncselwin,
XA_STRING,
0, CUT_MAX / 4,
False, AnyPropertyType,
&realtype, &fmt,
&nitems, &bytes_rem,
&data) == Success) {
if (bytes_rem) {
printf("Clipboard too large, ignoring\n");
} else {
const uint32_t len = nitems * (fmt / 8);
//printf("realtype %lu, fmt %u, nitems %lu\n",
// realtype, fmt, nitems);
memcpy(cutbuf, data, len);
if (len < CUT_MAX)
cutbuf[len] = 0;
else
cutbuf[CUT_MAX - 1] = 0;
// Send it to the app screen
XSetSelectionOwner(appdisp, XA_PRIMARY,
approot,
CurrentTime);
}
XFree(data);
} else {
printf("Failed to fetch vnc clipboard\n");
}
}
break;
case SelectionClear:
cutbuf[0] = '\0';
XSetSelectionOwner(appdisp, XA_PRIMARY, None,
CurrentTime);
break;
default:
printf("Unexpected event type %u\n", ev.type);
break;
}
}
// App-side events
while (XPending(appdisp)) {
XEvent ev;
XNextEvent(appdisp, &ev);
if (ev.type == xfixesbase + XFixesSelectionNotify) {
XFixesSelectionNotifyEvent *xfe =
(XFixesSelectionNotifyEvent *) &ev;
//printf("app disp did a copy, owner %lu\n", xfe->owner);
if (xfe->owner == None || xfe->owner == approot)
continue;
XConvertSelection(appdisp, XA_PRIMARY, XA_STRING, XA_STRING,
selwin, CurrentTime);
} else switch (ev.type) {
case SelectionNotify:
{
Atom realtype;
int fmt;
unsigned long nitems, bytes_rem;
unsigned char *data;
if (XGetWindowProperty(appdisp, selwin,
XA_STRING,
0, CUT_MAX / 4,
False, AnyPropertyType,
&realtype, &fmt,
&nitems, &bytes_rem,
&data) == Success) {
if (bytes_rem) {
printf("Clipboard too large, ignoring\n");
} else {
const uint32_t len = nitems * (fmt / 8);
//printf("realtype %lu, fmt %u, nitems %lu\n",
// realtype, fmt, nitems);
memcpy(cutbuf, data, len);
if (len < CUT_MAX)
cutbuf[len] = 0;
else
cutbuf[CUT_MAX - 1] = 0;
// Send it to the VNC screen
XSetSelectionOwner(vncdisp, XA_PRIMARY,
vncroot,
CurrentTime);
}
XFree(data);
} else {
printf("Failed to fetch app clipboard\n");
}
}
break;
case SelectionRequest:
supplyselection(appdisp, &ev, xa_targets_app);
break;
default:
printf("Unexpected app event type %u\n", ev.type);
break;
}
}
// Cursors
cursor = XFixesGetCursorImage(appdisp);
uint64_t newhash = XXH64(cursor->pixels,
cursor->width * cursor->height * sizeof(unsigned long),
0);
if (cursorhash != newhash) {
if (cursorhash)
XFreeCursor(vncdisp, xcursor);
XcursorImage *converted = XcursorImageCreate(cursor->width, cursor->height);
converted->xhot = cursor->xhot;
converted->yhot = cursor->yhot;
unsigned i;
for (i = 0; i < cursor->width * cursor->height; i++) {
converted->pixels[i] = cursor->pixels[i];
}
xcursor = XcursorImageLoadCursor(vncdisp, converted);
XDefineCursor(vncdisp, vncroot, xcursor);
XcursorImageDestroy(converted);
cursorhash = newhash;
}
usleep(sleeptime);
}
XCloseDisplay(appdisp);
XCloseDisplay(vncdisp);
return 0;
}

View File

@@ -0,0 +1,18 @@
.TH kasmxproxy 1 "" "KasmVNC" "Virtual Network Computing"
.SH NAME
kasmxproxy \- proxy an existing X11 display to a KasmVNC display
.SH SYNOPSIS
.B kasmxproxy
.RB [ \-a \-\-app\-display
.IR source display, default :0 ]
.RB [ \-v \-\-vnc\-display
.IR destination display, default :1 ]
.RB [ \-f \-\-fps
.IR FPS, default 30 ]
.RB [ \-r \-\-resize
.IR Enable resizing, default disabled. WARNING: DO NOT ENABLE IF PHYSICAL DISPLAY IS ATTACHED ]
.br
.BI "kasmxproxy -a :1 -v :10 -r"
.SH DESCRIPTION
.B kasmxproxy
is used to proxy an x display, usually attached to a physical GPU, to KasmVNC display. This is usually used in the context of providing GPU acceleration to a KasmVNC session.

1
unix/kasmxproxy/xxhash.c Symbolic link
View File

@@ -0,0 +1 @@
../../common/rfb/xxhash.c

1
unix/kasmxproxy/xxhash.h Symbolic link
View File

@@ -0,0 +1 @@
../../common/rfb/xxhash.h