Skip to content

Commit

Permalink
detect clipboard loops causing heavy clipboard traffic and put a stop…
Browse files Browse the repository at this point in the history
… to it

git-svn-id: https://xpra.org/svn/Xpra/trunk@7751 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Sep 22, 2014
1 parent e0a4ee1 commit aec1ec6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/xpra/server/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
NOYIELD = os.environ.get("XPRA_YIELD") is None
debug = log.debug

MAX_CLIPBOARD_PER_SECOND = 5


def get_generic_window_type(window, strip_net=True):
window_types = window.get_property("window-type")
Expand Down Expand Up @@ -268,6 +270,8 @@ def __init__(self, protocol, disconnect_cb, idle_add, timeout_add, source_remove
self.last_user_event = time.time()
self.last_ping_echoed_time = 0

self.clipboard_stats = deque(maxlen=MAX_CLIPBOARD_PER_SECOND)

self.init_vars()

# ready for processing:
Expand Down Expand Up @@ -1224,6 +1228,16 @@ def send_clipboard_enabled(self, reason=""):
def send_clipboard(self, packet):
if not self.clipboard_enabled or self.suspended:
return
now = time.time()
self.clipboard_stats.append(now)
if len(self.clipboard_stats)>=MAX_CLIPBOARD_PER_SECOND:
elapsed = now-self.clipboard_stats[0]
if elapsed<1:
msg = "more than %s clipboard requests per second!" % MAX_CLIPBOARD_PER_SECOND
log.warn("clipboard disabled: %s", msg)
self.clipboard_enabled = False
self.send_clipboard_enabled(msg)
return
#call compress_clibboard via the work queue:
self.compression_work_queue.put((self.compress_clipboard, packet))

Expand Down

0 comments on commit aec1ec6

Please sign in to comment.