/** * Initialize proxy chain. * * @throws SocketException If a SOCKS protocol error occurred. * @throws IOException If an I/O error occurred. */ private void initProxyChain() throws SocketException, IOException { List<SocksProxy> proxyChain = new ArrayList<SocksProxy>(); SocksProxy temp = proxy; while (temp.getChainProxy() != null) { temp.getChainProxy().setProxySocket(proxySocket); proxyChain.add(temp.getChainProxy()); temp = temp.getChainProxy(); } logger.debug("Proxy chain has:{} proxy", proxyChain.size()); if (proxyChain.size() > 0) { SocksProxy pre = proxy; for (int i = 0; i < proxyChain.size(); i++) { SocksProxy chain = proxyChain.get(i); pre.requestConnect(chain.getInetAddress(), chain.getPort()); proxy.getChainProxy().buildConnection(); pre = chain; } } }
/** * Initialize proxy chain. * * @throws SocketException If a SOCKS protocol error occurred. * @throws IOException If an I/O error occurred. */ private void initProxyChain() throws SocketException, IOException { List<SocksProxy> proxyChain = new ArrayList<SocksProxy>(); SocksProxy temp = proxy; while (temp.getChainProxy() != null) { temp.getChainProxy().setProxySocket(proxySocket); proxyChain.add(temp.getChainProxy()); temp = temp.getChainProxy(); } logger.debug("Proxy chain has:{} proxy", proxyChain.size()); if (proxyChain.size() > 0) { SocksProxy pre = proxy; for (int i = 0; i < proxyChain.size(); i++) { SocksProxy chain = proxyChain.get(i); pre.requestConnect(chain.getInetAddress(), chain.getPort()); proxy.getChainProxy().buildConnection(); pre = chain; } } }
/** * Constructs a datagram socket with a {@link SocksProxy}. <br> * <b>Notice:</b> The proxy must be {@link Socks5}, because only SOCKS5 protocol supports UDP * ASSOCIATE. It will throw {@link SocksException} if you give other {@link SocksProxy} * implementation which not supports SOCKS5 protocol. * * @param proxy {@link Socks5} instance. * @throws SocksException If any error about SOCKS protocol occurs. * @throws IOException If any I/O error occurs. * @see <a href="http://www.ietf.org/rfc/rfc1928.txt">SOCKS Protocol Version 5</a> */ public Socks5DatagramSocket(SocksProxy proxy) throws SocksException, IOException { super(); this.proxy = proxy.copy(); if (this.proxy.getChainProxy() != null) { throw new SocksException("Proxy chain not support UDP ASSOCIATE"); } if (!(this.proxy instanceof Socks5)) { throw new SocksException("Only SOCKS5 protocol support UDP ASSOCIATE"); } this.proxy.buildConnection(); CommandReplyMessage message = this.proxy.requestUdpAssociate(this.getLocalAddress(), this.getLocalPort()); logger.debug("build datagram socket at[{}:{}]", this.getLocalAddress(), this.getLocalPort()); this.relayServerInetAddress = message.getIp(); this.relayServerPort = message.getPort(); logger.info("relay server's address[{}:{}]", relayServerInetAddress, relayServerPort); }
/** * Constructs a datagram socket with a {@link SocksProxy}. <br> * <b>Notice:</b> The proxy must be {@link Socks5}, because only SOCKS5 protocol supports UDP * ASSOCIATE. It will throw {@link SocksException} if you give other {@link SocksProxy} * implementation which not supports SOCKS5 protocol. * * @param proxy {@link Socks5} instance. * @throws SocksException If any error about SOCKS protocol occurs. * @throws IOException If any I/O error occurs. * @see <a href="http://www.ietf.org/rfc/rfc1928.txt">SOCKS Protocol Version 5</a> */ public Socks5DatagramSocket(SocksProxy proxy) throws SocksException, IOException { super(); this.proxy = proxy.copy(); if (this.proxy.getChainProxy() != null) { throw new SocksException("Proxy chain not support UDP ASSOCIATE"); } if (!(this.proxy instanceof Socks5)) { throw new SocksException("Only SOCKS5 protocol support UDP ASSOCIATE"); } this.proxy.buildConnection(); CommandReplyMessage message = this.proxy.requestUdpAssociate(this.getLocalAddress(), this.getLocalPort()); logger.debug("build datagram socket at[{}:{}]", this.getLocalAddress(), this.getLocalPort()); this.relayServerInetAddress = message.getIp(); this.relayServerPort = message.getPort(); logger.info("relay server's address[{}:{}]", relayServerInetAddress, relayServerPort); }