From cdb5c190105470ed32b8180e1522e46999670343 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 3 Jul 2016 21:51:56 -0700 Subject: [PATCH] websockets: turn on autoPingInterval to expire stale connections With this, both clients and servers will send a PING at least once every minute, and will drop connections that haven't seen any traffic for 10 minutes. This should help keep NAT table entries alive, and will drop connections that are no longer viable because their NAT entries have expired. closes #60 --- src/wormhole/server/rendezvous_websocket.py | 1 + src/wormhole/wormhole.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/wormhole/server/rendezvous_websocket.py b/src/wormhole/server/rendezvous_websocket.py index a6289a7..32519b0 100644 --- a/src/wormhole/server/rendezvous_websocket.py +++ b/src/wormhole/server/rendezvous_websocket.py @@ -247,5 +247,6 @@ class WebSocketRendezvousFactory(websocket.WebSocketServerFactory): protocol = WebSocketRendezvous def __init__(self, url, rendezvous): websocket.WebSocketServerFactory.__init__(self, url) + self.setProtocolOptions(autoPingInterval=60, autoPingTimeout=600) self.rendezvous = rendezvous self.reactor = reactor # for tests to control diff --git a/src/wormhole/wormhole.py b/src/wormhole/wormhole.py index 11fbd12..c3b0c6f 100644 --- a/src/wormhole/wormhole.py +++ b/src/wormhole/wormhole.py @@ -354,6 +354,7 @@ class _Wormhole: self._ws_t = self._timing.add("open websocket") p = urlparse(self._ws_url) f = WSFactory(self._ws_url) + f.setProtocolOptions(autoPingInterval=60, autoPingTimeout=600) f.wormhole = self f.d = defer.Deferred() # TODO: if hostname="localhost", I get three factories starting