Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1014)

Unified Diff: media/tools/constrained_network_server/cns.py

Issue 10824224: Add CNS function to clean up port matching requester IP address. (Closed) Base URL: http://git.chromium.org/chromium/src.git@cns_apache
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/tools/constrained_network_server/cns_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/tools/constrained_network_server/cns.py
diff --git a/media/tools/constrained_network_server/cns.py b/media/tools/constrained_network_server/cns.py
index 732b032b9234a64d6b24ee39e39367a49e3b52e7..935ea40613355cf0cbee8c70445a48a38c063539 100755
--- a/media/tools/constrained_network_server/cns.py
+++ b/media/tools/constrained_network_server/cns.py
@@ -132,7 +132,7 @@ class PortAllocator(object):
cherrypy.log('Error: %s\nOutput: %s' % (e.msg, e.error))
return False
- def Cleanup(self, all_ports):
+ def Cleanup(self, all_ports, request_ip=None):
"""Cleans up expired ports, or if all_ports=True, all allocated ports.
By default, ports which haven't been used for self._expiry_time_secs are
@@ -140,13 +140,15 @@ class PortAllocator(object):
Args:
all_ports: Should all ports be torn down regardless of expiration?
+ request_ip: Tear ports matching the IP address regarless of expiration.
"""
with self._port_lock:
now = time.time()
# Use .items() instead of .iteritems() so we can delete keys w/o error.
for port, status in self._ports.items():
expired = now - status['last_update'] > self._expiry_time_secs
- if all_ports or expired:
+ matching_ip = request_ip and status['key'][0].startswith(request_ip)
+ if all_ports or expired or matching_ip:
cherrypy.log('Cleaning up port %d' % port)
self._DeletePort(port)
del self._ports[port]
@@ -177,6 +179,19 @@ class ConstrainedNetworkServer(object):
self._port_allocator = port_allocator
@cherrypy.expose
+ def Cleanup(self):
+ """Cleans up all the ports allocated using the request IP address.
+
+ When requesting a constrained port, the cherrypy.request.remote.ip is used
+ as a key for that port (in addition to other request parameters). Such
+ ports created for the same IP address are removed.
+ """
+ cherrypy.log('Cleaning up ports allocated by %s.' %
+ cherrypy.request.remote.ip)
+ self._port_allocator.Cleanup(all_ports=False,
+ request_ip=cherrypy.request.remote.ip)
+
+ @cherrypy.expose
def ServeConstrained(self, f=None, bandwidth=None, latency=None, loss=None,
new_port=False, no_cache=False, **kwargs):
"""Serves the requested file with the requested constraints.
« no previous file with comments | « no previous file | media/tools/constrained_network_server/cns_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698