Skip to content

Commit

Permalink
#3229 add a new 'rencodeplus' encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Aug 3, 2021
1 parent efc87a4 commit 592f27a
Show file tree
Hide file tree
Showing 8 changed files with 558 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ tests/unittests/test-file*
/xpra/gtk_common/gtk3/gdk_bindings.c
/xpra/net/vsock.c
/xpra/net/bencode/cython_bencode.c
/xpra/net/rencodeplus/rencodeplus.c
/xpra/platform/darwin/gdk3_bindings.c
/xpra/platform/win32/propsys.cpp
/xpra/platform/xposix/netdev_query.c
Expand Down
14 changes: 12 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def is_RH():
vsock_ENABLED = LINUX and os.path.exists("/usr/include/linux/vm_sockets.h")
bencode_ENABLED = DEFAULT
cython_bencode_ENABLED = DEFAULT
rencodeplus_ENABLED = DEFAULT
clipboard_ENABLED = DEFAULT
Xdummy_ENABLED = None if POSIX else False #None means auto-detect
Xdummy_wrapper_ENABLED = None if POSIX else False #None means auto-detect
Expand Down Expand Up @@ -225,7 +226,8 @@ def is_RH():
"v4l2",
"dec_avcodec2", "csc_swscale",
"csc_cython", "csc_libyuv",
"bencode", "cython_bencode", "vsock", "netdev", "mdns",
"bencode", "cython_bencode", "rencodeplus",
"vsock", "netdev", "mdns",
"clipboard",
"scripts",
"server", "client", "dbus", "x11", "xinput", "uinput", "sd_listen",
Expand Down Expand Up @@ -310,7 +312,7 @@ def is_RH():
vpx_ENABLED = nvfbc_ENABLED = dec_avcodec2_ENABLED = False
webp_ENABLED = jpeg_encoder_ENABLED = jpeg_decoder_ENABLED = False
server_ENABLED = client_ENABLED = shadow_ENABLED = False
cython_bencode_ENABLED = False
cython_bencode_ENABLED = rencodeplus_ENABLED = False
gtk3_ENABLED = False
x11_ENABLED = False
#sanity check the flags:
Expand Down Expand Up @@ -931,6 +933,7 @@ def clean():
"xpra/platform/xposix/sd_listen.c",
"xpra/platform/xposix/netdev_query.c",
"xpra/net/bencode/cython_bencode.c",
"xpra/net/rencodeplus/rencodeplus.c",
"xpra/net/vsock.c",
"xpra/buffers/membuf.c",
"xpra/buffers/xxh.c",
Expand Down Expand Up @@ -2323,6 +2326,13 @@ def get_nvcc_version(command):
["xpra/net/bencode/cython_bencode.pyx"],
**bencode_pkgconfig)

toggle_packages(rencodeplus_ENABLED, "xpra.net.rencodeplus.rencodeplus")
if rencodeplus_ENABLED:
rencodeplus_pkgconfig = pkgconfig(optimize=3)
add_cython_ext("xpra.net.rencodeplus.rencodeplus",
["xpra/net/rencodeplus/rencodeplus.pyx"],
**rencodeplus_pkgconfig)

if netdev_ENABLED:
netdev_pkgconfig = pkgconfig()
add_cython_ext("xpra.platform.xposix.netdev_query",
Expand Down
4 changes: 3 additions & 1 deletion xpra/net/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#packet encoding flags:
FLAGS_BENCODE = 0x0 #assume bencode if not other flag is set
FLAGS_RENCODE = 0x1
FLAGS_CIPHER = 0x2
FLAGS_YAML = 0x4
FLAGS_RENCODEPLUS = 0x10
#these flags can actually be combined with the encoders above:
FLAGS_FLUSH = 0x8
FLAGS_CIPHER = 0x2

#compression flags are carried in the "level" field,
#the low bits contain the compression level, the high bits the compression algo:
Expand Down
14 changes: 11 additions & 3 deletions xpra/net/packet_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
from threading import Lock

from xpra.log import Logger
from xpra.net.header import FLAGS_RENCODE, FLAGS_YAML, FLAGS_BENCODE, FLAGS_NOHEADER
from xpra.net.header import FLAGS_RENCODE, FLAGS_RENCODEPLUS, FLAGS_YAML, FLAGS_BENCODE, FLAGS_NOHEADER
from xpra.util import envbool

#all the encoders we know about, in best compatibility order:
ALL_ENCODERS = ("rencode", "bencode", "yaml", "none")
ALL_ENCODERS = ("rencodeplus", "rencode", "bencode", "yaml", "none")
#order for performance:
PERFORMANCE_ORDER = ("rencode", "bencode", "yaml")
PERFORMANCE_ORDER = ("rencodeplus", "rencode", "bencode", "yaml")

Encoding = namedtuple("Encoding", ["name", "flag", "version", "encode", "decode"])

Expand All @@ -30,6 +30,12 @@ def do_rencode(v):
return dumps(v), FLAGS_RENCODE
return Encoding("rencode", FLAGS_RENCODE, __version__, do_rencode, loads)

def init_rencodeplus():
from xpra.net.rencodeplus.rencodeplus import dumps, loads, __version__ #pylint: disable=no-name-in-module
def do_rencodeplus(v):
return dumps(v), FLAGS_RENCODEPLUS
return Encoding("rencodeplus", FLAGS_RENCODEPLUS, __version__, do_rencodeplus, loads)

def init_bencode():
from xpra.net.bencode import bencode, bdecode, __version__
def do_bencode(v):
Expand Down Expand Up @@ -95,6 +101,8 @@ def get_encoder(e):
return ENCODERS[e].encode

def get_packet_encoding_type(protocol_flags) -> str:
if protocol_flags & FLAGS_RENCODEPLUS:
return "rencode"
if protocol_flags & FLAGS_RENCODE:
return "rencode"
if protocol_flags & FLAGS_YAML:
Expand Down
4 changes: 4 additions & 0 deletions xpra/net/rencodeplus/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This file is part of Xpra.
# Copyright (C) 2021 Antoine Martin <antoine@xpra.org>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

0 comments on commit 592f27a

Please sign in to comment.