-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
137 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/src/main/java/ru/krlvm/powertunnel/adapters/UpstreamChainedProxyAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package ru.krlvm.powertunnel.adapters; | ||
|
||
import org.littleshoot.proxy.ChainedProxyAdapter; | ||
|
||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import java.net.UnknownHostException; | ||
|
||
import ru.krlvm.powertunnel.PowerTunnel; | ||
|
||
public class UpstreamChainedProxyAdapter extends ChainedProxyAdapter { | ||
|
||
private InetSocketAddress cachedAddress = null; | ||
|
||
public UpstreamChainedProxyAdapter() { | ||
if (PowerTunnel.UPSTREAM_PROXY_CACHE) { | ||
try { | ||
cachedAddress = getAddress(); | ||
} catch (UnknownHostException ex) { | ||
System.out.println("[x] Failed to cache upstream proxy address: " + ex.getMessage()); | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public InetSocketAddress getChainedProxyAddress() { | ||
try { | ||
return cachedAddress == null ? getAddress() : cachedAddress; | ||
} catch (UnknownHostException ex) { | ||
System.out.println("[x] Failed to resolve upstream proxy address: " + ex.getMessage()); | ||
ex.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
private InetSocketAddress getAddress() throws UnknownHostException { | ||
return new InetSocketAddress(InetAddress.getByName(PowerTunnel.UPSTREAM_PROXY_IP), PowerTunnel.UPSTREAM_PROXY_PORT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Maybe change this to "Do not resolve address on each request"?