1 /* 2 * Created on 06-Dec-2004 3 * Created by Paul Gardner 4 * Copyright (C) Azureus Software, Inc, All Rights Reserved. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 */ 19 20 package com.aelitis.azureus.core.proxy; 21 22 import java.net.Proxy; 23 import java.net.URL; 24 import java.util.List; 25 import java.util.Map; 26 27 import org.gudy.azureus2.plugins.PluginInterface; 28 29 import com.aelitis.azureus.core.proxy.impl.*; 30 import com.aelitis.azureus.plugins.dht.DHTPluginInterface; 31 32 /** 33 * @author parg 34 * 35 */ 36 37 public class 38 AEProxyFactory 39 { 40 /** 41 * @param port 0 = free port 42 * @param connect_timeout 0 = no timeout 43 * @param read_timeout 0 = no timeout 44 * @return 45 * @throws AEProxyException 46 */ 47 48 public static AEProxy create( int port, long connect_timeout, long read_timeout, AEProxyHandler state_factory )49 create( 50 int port, 51 long connect_timeout, 52 long read_timeout, 53 AEProxyHandler state_factory ) 54 55 throws AEProxyException 56 { 57 return( new AEProxyImpl(port,connect_timeout,read_timeout,state_factory)); 58 } 59 60 public static AEProxyAddressMapper getAddressMapper()61 getAddressMapper() 62 { 63 return( AEProxyAddressMapperImpl.getSingleton()); 64 } 65 66 public static final String PO_PEER_NETWORKS = "peer_networks"; 67 68 public static PluginProxy getPluginProxy( String reason, URL target )69 getPluginProxy( 70 String reason, 71 URL target ) 72 { 73 return( getPluginProxy( reason, target, false)); 74 } 75 76 public static PluginProxy getPluginProxy( String reason, URL target, boolean can_wait )77 getPluginProxy( 78 String reason, 79 URL target, 80 boolean can_wait ) 81 { 82 return( getPluginProxy( reason, target, null, can_wait )); 83 } 84 85 public static PluginProxy getPluginProxy( String reason, URL target, Map<String,Object> proxy_options, boolean can_wait )86 getPluginProxy( 87 String reason, 88 URL target, 89 Map<String,Object> proxy_options, 90 boolean can_wait ) 91 { 92 return( AEPluginProxyHandler.getPluginProxy( reason, target, proxy_options, can_wait )); 93 } 94 95 public static PluginProxy getPluginProxy( String reason, String host, int port )96 getPluginProxy( 97 String reason, 98 String host, 99 int port ) 100 { 101 return( getPluginProxy( reason, host, port, null )); 102 } 103 104 public static PluginProxy getPluginProxy( String reason, String host, int port, Map<String,Object> proxy_options )105 getPluginProxy( 106 String reason, 107 String host, 108 int port, 109 Map<String,Object> proxy_options ) 110 { 111 return( AEPluginProxyHandler.getPluginProxy( reason, host, port, proxy_options )); 112 } 113 114 public static PluginProxy getPluginProxy( Proxy proxy )115 getPluginProxy( 116 Proxy proxy ) 117 { 118 return( AEPluginProxyHandler.getPluginProxy( proxy )); 119 } 120 121 public static Boolean testPluginHTTPProxy( URL target, boolean can_wait )122 testPluginHTTPProxy( 123 URL target, 124 boolean can_wait ) 125 { 126 return( AEPluginProxyHandler.testPluginHTTPProxy( target, can_wait )); 127 128 } 129 130 public static PluginHTTPProxy getPluginHTTPProxy( String reason, URL target, boolean can_wait )131 getPluginHTTPProxy( 132 String reason, 133 URL target, 134 boolean can_wait ) 135 { 136 return( AEPluginProxyHandler.getPluginHTTPProxy( reason, target, can_wait )); 137 } 138 139 public static List<PluginInterface> getPluginHTTPProxyProviders( boolean can_wait )140 getPluginHTTPProxyProviders( 141 boolean can_wait ) 142 { 143 return( AEPluginProxyHandler.getPluginHTTPProxyProviders( can_wait )); 144 } 145 146 public static boolean hasPluginProxy()147 hasPluginProxy() 148 { 149 return( AEPluginProxyHandler.hasPluginProxy()); 150 } 151 152 public static final String SP_HOST = "host"; 153 public static final String SP_PORT = "port"; 154 155 public static Map<String,Object> getPluginServerProxy( String reason, String network, String server_uid, Map<String,Object> options )156 getPluginServerProxy( 157 String reason, 158 String network, 159 String server_uid, 160 Map<String,Object> options ) 161 { 162 return( AEPluginProxyHandler.getPluginServerProxy( reason, network, server_uid, options )); 163 } 164 165 public static final String DP_DOWNLOAD = "download"; 166 public static final String DP_NETWORKS = "networks"; 167 168 169 public static DHTPluginInterface getPluginDHTProxy( String reason, String network, Map<String,Object> options )170 getPluginDHTProxy( 171 String reason, 172 String network, 173 Map<String,Object> options ) 174 { 175 return( AEPluginProxyHandler.getPluginDHTProxy( reason, network, options )); 176 177 } 178 179 public interface 180 PluginProxy 181 { 182 public String getTarget()183 getTarget(); 184 185 public PluginProxy getChildProxy( String reason, URL url )186 getChildProxy( 187 String reason, 188 URL url ); 189 190 public Proxy getProxy()191 getProxy(); 192 193 public URL getURL()194 getURL(); 195 196 public String getURLHostRewrite()197 getURLHostRewrite(); 198 199 public String getHost()200 getHost(); 201 202 public int getPort()203 getPort(); 204 205 public void setOK( boolean good )206 setOK( 207 boolean good ); 208 } 209 210 public interface 211 PluginHTTPProxy 212 { 213 public Proxy getProxy()214 getProxy(); 215 216 public String proxifyURL( String url )217 proxifyURL( 218 String url ); 219 220 public void destroy()221 destroy(); 222 } 223 224 225 public static class 226 UnknownHostException 227 extends RuntimeException 228 { 229 public UnknownHostException( String host )230 UnknownHostException( 231 String host ) 232 { 233 super( host ); 234 } 235 } 236 } 237