From 0ac2b99f6a3efef1e31c696d245a479b80fb0209 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 12 Jun 2012 12:56:58 +0200 Subject: [PATCH] Final pass at the implementation of a reverse SPDY proxy. --- jetty-spdy/spdy-jetty-http-webapp/pom.xml | 41 +++++++++ .../src/main/config/etc/jetty-spdy-proxy.xml | 88 +++++++++++++++++++ .../eclipse/jetty/spdy/proxy/ProxyEngine.java | 13 +++ .../jetty/spdy/proxy/SPDYProxyEngine.java | 12 +-- 4 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 jetty-spdy/spdy-jetty-http-webapp/src/main/config/etc/jetty-spdy-proxy.xml diff --git a/jetty-spdy/spdy-jetty-http-webapp/pom.xml b/jetty-spdy/spdy-jetty-http-webapp/pom.xml index f7d04ac3643..a09295bc922 100644 --- a/jetty-spdy/spdy-jetty-http-webapp/pom.xml +++ b/jetty-spdy/spdy-jetty-http-webapp/pom.xml @@ -60,4 +60,45 @@ --> + + + diff --git a/jetty-spdy/spdy-jetty-http-webapp/src/main/config/etc/jetty-spdy-proxy.xml b/jetty-spdy/spdy-jetty-http-webapp/src/main/config/etc/jetty-spdy-proxy.xml new file mode 100644 index 00000000000..7d848686196 --- /dev/null +++ b/jetty-spdy/spdy-jetty-http-webapp/src/main/config/etc/jetty-spdy-proxy.xml @@ -0,0 +1,88 @@ + + + + + + + src/main/resources/keystore.jks + storepwd + src/main/resources/truststore.jks + storepwd + TLSv1 + + + + + + + + + 9090 + + + spdy/2 + + + + + + + + + + + + + + + + + localhost + + + 2 + 127.0.0.1 + 9090 + + + + + + + + + + + + + 8080 + + + + + + + + + 8443 + + + + + + diff --git a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/ProxyEngine.java b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/ProxyEngine.java index 21f91c2ee85..1013430f17f 100644 --- a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/ProxyEngine.java +++ b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/ProxyEngine.java @@ -19,6 +19,8 @@ package org.eclipse.jetty.spdy.proxy; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -84,6 +86,17 @@ public abstract class ProxyEngine extends ServerSessionFrameListener.Adapter imp // TODO: add Via header } + public Map getProxyInfos() + { + return new HashMap<>(proxyInfos); + } + + public void setProxyInfos(Map proxyInfos) + { + this.proxyInfos.clear(); + this.proxyInfos.putAll(proxyInfos); + } + public void putProxyInfo(String host, ProxyInfo proxyInfo) { proxyInfos.put(host, proxyInfo); diff --git a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/SPDYProxyEngine.java b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/SPDYProxyEngine.java index b4413b8f323..23b38b0cdbb 100644 --- a/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/SPDYProxyEngine.java +++ b/jetty-spdy/spdy-jetty-http/src/main/java/org/eclipse/jetty/spdy/proxy/SPDYProxyEngine.java @@ -98,14 +98,8 @@ public class SPDYProxyEngine extends ProxyEngine { @SuppressWarnings("unchecked") Set sessions = (Set)serverSession.getAttribute(CLIENT_SESSIONS_ATTRIBUTE); - for (Session session : sessions) - { - if (session == clientSession) - { - sessions.remove(session); - return; - } - } + if (sessions.remove(clientSession)) + break; } } @@ -207,6 +201,7 @@ public class SPDYProxyEngine extends ProxyEngine SPDYClient client = factory.newSPDYClient(version); session = client.connect(address, sessionListener).get(getConnectTimeout(), TimeUnit.MILLISECONDS); session.setAttribute(CLIENT_SESSIONS_ATTRIBUTE, Collections.newSetFromMap(new ConcurrentHashMap())); + logger.debug("Proxy session connected to {}", address); Session existing = serverSessions.putIfAbsent(host, session); if (existing != null) { @@ -505,6 +500,7 @@ public class SPDYProxyEngine extends ProxyEngine @Override public void onGoAway(Session serverSession, GoAwayInfo goAwayInfo) { + serverSessions.values().remove(serverSession); @SuppressWarnings("unchecked") Set sessions = (Set)serverSession.removeAttribute(CLIENT_SESSIONS_ATTRIBUTE); for (Session session : sessions)