com.runjva.sourceforge.jsocks.protocol.Socks5Proxy Java Examples

The following examples show how to use com.runjva.sourceforge.jsocks.protocol.Socks5Proxy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SeedPeersSocks5Dns.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Resolves a hostname via remote DNS over socks5 proxy.
 */
@Nullable
public static InetSocketAddress lookup(Socks5Proxy proxy, InetSocketAddress addr) {
    if (!addr.isUnresolved()) {
        return addr;
    }
    try {
        SocksSocket proxySocket = new SocksSocket(proxy, addr.getHostString(), addr.getPort());
        InetAddress addrResolved = proxySocket.getInetAddress();
        proxySocket.close();
        if (addrResolved != null) {
            log.debug("Resolved " + addr.getHostString() + " to " + addrResolved.getHostAddress());
            return new InetSocketAddress(addrResolved, addr.getPort());
        } else {
            // note: .onion nodes fall in here when proxy is Tor. But they have no IP address.
            // Unfortunately bitcoinj crashes in PeerAddress if it finds an unresolved address.
            log.error("Connected to " + addr.getHostString() + ".  But did not resolve to address.");
        }
    } catch (Exception e) {
        log.warn("Error resolving " + addr.getHostString() + ". Exception:\n" + e.toString());
    }
    return null;
}
 
Example #2
Source File: BtcNodesRepositoryTest.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testGetPeerAddressesWhenOnionNodesOnly() {
    BtcNode node = mock(BtcNode.class);
    when(node.hasClearNetAddress()).thenReturn(true);

    BtcNode onionNode = mock(BtcNode.class);
    when(node.hasOnionAddress()).thenReturn(true);

    BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS);
    BtcNodesRepository repository = new BtcNodesRepository(converter,
            Lists.newArrayList(node, onionNode));

    List<PeerAddress> peers = repository.getPeerAddresses(mock(Socks5Proxy.class), false);

    assertEquals(1, peers.size());
}
 
Example #3
Source File: BtcNodesRepositoryTest.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testGetPeerAddressesWhenProxyAndClearNodes() {
    BtcNode node = mock(BtcNode.class);
    when(node.hasClearNetAddress()).thenReturn(true);

    BtcNode onionNode = mock(BtcNode.class);
    when(node.hasOnionAddress()).thenReturn(true);

    BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS);
    BtcNodesRepository repository = new BtcNodesRepository(converter,
            Lists.newArrayList(node, onionNode));

    List<PeerAddress> peers = repository.getPeerAddresses(mock(Socks5Proxy.class), true);

    assertEquals(2, peers.size());
}
 
Example #4
Source File: BtcNodesRepository.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<PeerAddress> getPeerAddresses(@Nullable Socks5Proxy proxy, boolean isUseClearNodesWithProxies) {
    List<PeerAddress> result;
    // We connect to onion nodes only in case we use Tor for BitcoinJ (default) to avoid privacy leaks at
    // exit nodes with bloom filters.
    if (proxy != null) {
        List<PeerAddress> onionHosts = getOnionHosts();
        result = new ArrayList<>(onionHosts);

        if (isUseClearNodesWithProxies) {
            // We also use the clear net nodes (used for monitor)
            List<PeerAddress> torAddresses = getClearNodesBehindProxy(proxy);
            result.addAll(torAddresses);
        }
    } else {
        result = getClearNodes();
    }
    return result;
}
 
Example #5
Source File: SeedPeersSocks5Dns.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Resolves a hostname via remote DNS over socks5 proxy.
 */
@Nullable
public static InetSocketAddress lookup(Socks5Proxy proxy, InetSocketAddress addr) {
    if (!addr.isUnresolved()) {
        return addr;
    }
    try {
        SocksSocket proxySocket = new SocksSocket(proxy, addr.getHostString(), addr.getPort());
        InetAddress addrResolved = proxySocket.getInetAddress();
        proxySocket.close();
        if (addrResolved != null) {
            //log.debug("Resolved " + addr.getHostString() + " to " + addrResolved.getHostAddress());
            return new InetSocketAddress(addrResolved, addr.getPort());
        } else {
            // note: .onion nodes fall in here when proxy is Tor. But they have no IP address.
            // Unfortunately bitcoinj crashes in PeerAddress if it finds an unresolved address.
            log.error("Connected to " + addr.getHostString() + ".  But did not resolve to address.");
        }
    } catch (Exception e) {
        log.warn("Error resolving " + addr.getHostString() + ". Exception:\n" + e.toString());
    }
    return null;
}
 
Example #6
Source File: SeedPeersSocks5Dns.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Supports finding peers by hostname over a socks5 proxy.
 */
public SeedPeersSocks5Dns(Socks5Proxy proxy, NetworkParameters params) {

    this.proxy = proxy;
    this.params = params;
    this.seedAddrs = convertAddrsString(params.getDnsSeeds(), params.getPort());

    /*
    // This is an example of how .onion servers could be used.  Unfortunately there is presently no way
    // to hand the onion address (or a connected socket) back to bitcoinj without it crashing in PeerAddress.
    // note:  the onion addresses should be added into bitcoinj NetworkParameters classes, eg for mainnet, testnet
    //        not here!
    this.seedAddrs = new InetSocketAddress[]{InetSocketAddress.createUnresolved("cajrifqkvalh2ooa.onion", 8333),
            InetSocketAddress.createUnresolved("bk7yp6epnmcllq72.onion", 8333)
    };
    */

    //TODO seedAddrsIP is never written; not used method...
    seedAddrsResolved = new InetSocketAddress[seedAddrs.length];
    System.arraycopy(seedAddrsIP, seedAddrs.length, seedAddrsResolved,
            seedAddrs.length, seedAddrsResolved.length - seedAddrs.length);
}
 
Example #7
Source File: Socks5SeedOnionDiscovery.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Supports finding peers by hostname over a socks5 proxy.
 *
 * @param proxy  proxy the socks5 proxy to connect over.
 * @param params param to be used for seed and port information.
 */
public Socks5SeedOnionDiscovery(@SuppressWarnings("UnusedParameters") Socks5Proxy proxy, NetworkParameters params) {
    // We do this because NetworkParameters does not contain any .onion
    // seeds.  Perhaps someday...
    String[] seedAddresses = {};
    switch (params.getId()) {
        case NetworkParameters.ID_MAINNET:
            seedAddresses = mainNetSeeds();
            break;
        case NetworkParameters.ID_TESTNET:
            seedAddresses = testNet3Seeds();
            break;
    }

    this.seedAddrs = convertAddrsString(seedAddresses, params.getPort());
}
 
Example #8
Source File: TorNetworkNode.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public Socks5Proxy getSocksProxy() {
    try {
        String stream = null;
        if (streamIsolation) {
            // create a random string
            byte[] bytes = new byte[512]; // note that getProxy does Sha256 that string anyways
            new SecureRandom().nextBytes(bytes);
            stream = Base64.getEncoder().encodeToString(bytes);
        }

        if (socksProxy == null || streamIsolation) {
            tor = Tor.getDefault();

            // ask for the connection
            socksProxy = tor != null ? tor.getProxy(stream) : null;
        }
        return socksProxy;
    } catch (TorCtlException e) {
        log.error("TorCtlException at getSocksProxy: " + e.toString());
        e.printStackTrace();
        return null;
    } catch (Throwable t) {
        log.error("Error at getSocksProxy: " + t.toString());
        return null;
    }
}
 
Example #9
Source File: HttpClient.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public String requestWithGET(String param, @Nullable String headerKey, @Nullable String headerValue) throws IOException {
    checkNotNull(baseUrl, "baseUrl must be set before calling requestWithGET");

    Socks5Proxy socks5Proxy = null;
    if (socks5ProxyProvider != null) {
        // We use the custom socks5ProxyHttp. If not set we request socks5ProxyProvider.getSocks5ProxyBtc()
        // which delivers the btc proxy if set, otherwise the internal proxy.
        socks5Proxy = socks5ProxyProvider.getSocks5ProxyHttp();
        if (socks5Proxy == null)
            socks5Proxy = socks5ProxyProvider.getSocks5Proxy();
    }
    if (ignoreSocks5Proxy || socks5Proxy == null || baseUrl.contains("localhost")) {
        log.debug("Use clear net for HttpClient. socks5Proxy={}, ignoreSocks5Proxy={}, baseUrl={}",
                socks5Proxy, ignoreSocks5Proxy, baseUrl);
        return requestWithGETNoProxy(param, headerKey, headerValue);
    } else {
        log.debug("Use socks5Proxy for HttpClient: " + socks5Proxy);
        return requestWithGETProxy(param, socks5Proxy, headerKey, headerValue);
    }
}
 
Example #10
Source File: Socks5ProxyProvider.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Nullable
private Socks5Proxy getProxyFromAddress(String socks5ProxyAddress) {
    if (!socks5ProxyAddress.isEmpty()) {
        String[] tokens = socks5ProxyAddress.split(":");
        if (tokens.length == 2) {
            try {
                return new Socks5Proxy(tokens[0], Integer.valueOf(tokens[1]));
            } catch (UnknownHostException e) {
                log.error(e.getMessage());
                e.printStackTrace();
            }
        } else {
            log.error("Incorrect format for socks5ProxyAddress. Should be: host:port.\n" +
                    "socks5ProxyAddress=" + socks5ProxyAddress);
        }
    }
    return null;
}
 
Example #11
Source File: PeerAddressesRepositoryTest.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testGetPeerAddressesWhenOnionNodesOnly() {
    BtcNode node = mock(BtcNode.class);
    when(node.hasClearNetAddress()).thenReturn(true);

    BtcNode onionNode = mock(BtcNode.class);
    when(node.hasOnionAddress()).thenReturn(true);

    BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS);
    PeerAddressesRepository repository = new PeerAddressesRepository(converter,
            Lists.newArrayList(node, onionNode));

    List<PeerAddress> peers = repository.getPeerAddresses(mock(Socks5Proxy.class), false);

    assertEquals(1, peers.size());
}
 
Example #12
Source File: PeerAddressesRepositoryTest.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testGetPeerAddressesWhenProxyAndClearNodes() {
    BtcNode node = mock(BtcNode.class);
    when(node.hasClearNetAddress()).thenReturn(true);

    BtcNode onionNode = mock(BtcNode.class);
    when(node.hasOnionAddress()).thenReturn(true);

    BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS);
    PeerAddressesRepository repository = new PeerAddressesRepository(converter,
            Lists.newArrayList(node, onionNode));

    List<PeerAddress> peers = repository.getPeerAddresses(mock(Socks5Proxy.class), true);

    assertEquals(2, peers.size());
}
 
Example #13
Source File: SeedPeersSocks5Dns.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Supports finding peers by hostname over a socks5 proxy.
 */
public SeedPeersSocks5Dns(Socks5Proxy proxy, NetworkParameters params) {

    this.proxy = proxy;
    this.params = params;
    this.seedAddrs = convertAddrsString(params.getDnsSeeds(), params.getPort());

    /*
    // This is an example of how .onion servers could be used.  Unfortunately there is presently no way
    // to hand the onion address (or a connected socket) back to bitcoinj without it crashing in PeerAddress.
    // note:  the onion addresses should be added into bitcoinj NetworkParameters classes, eg for mainnet, testnet
    //        not here!
    this.seedAddrs = new InetSocketAddress[]{InetSocketAddress.createUnresolved("cajrifqkvalh2ooa.onion", 8333),
            InetSocketAddress.createUnresolved("bk7yp6epnmcllq72.onion", 8333)
    };
    */

    //TODO seedAddrsIP is never written; not used method...
    seedAddrsResolved = new InetSocketAddress[seedAddrs.length];
    System.arraycopy(seedAddrsIP, seedAddrs.length, seedAddrsResolved,
            seedAddrs.length, seedAddrsResolved.length - seedAddrs.length);
}
 
Example #14
Source File: PeerAddressesRepository.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
List<PeerAddress> getPeerAddresses(@Nullable Socks5Proxy proxy, boolean isUseClearNodesWithProxies) {
    List<PeerAddress> result;
    // We connect to onion nodes only in case we use Tor for BitcoinJ (default) to avoid privacy leaks at
    // exit nodes with bloom filters.
    if (proxy != null) {
        List<PeerAddress> onionHosts = getOnionHosts();
        result = new ArrayList<>(onionHosts);

        if (isUseClearNodesWithProxies) {
            // We also use the clear net nodes (used for monitor)
            List<PeerAddress> torAddresses = getClearNodesBehindProxy(proxy);
            result.addAll(torAddresses);
        }
    } else {
        result = getClearNodes();
    }
    return result;
}
 
Example #15
Source File: HttpClient.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Make an HTTP Get request routed over socks5 proxy.
 */
private String requestWithGETProxy(String param, Socks5Proxy socks5Proxy, @Nullable String headerKey, @Nullable String headerValue) throws IOException {
    log.debug("requestWithGETProxy param=" + param);
    // This code is adapted from:
    //  http://stackoverflow.com/a/25203021/5616248

    // Register our own SocketFactories to override createSocket() and connectSocket().
    // connectSocket does NOT resolve hostname before passing it to proxy.
    Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create()
            .register("http", new SocksConnectionSocketFactory())
            .register("https", new SocksSSLConnectionSocketFactory(SSLContexts.createSystemDefault())).build();

    // Use FakeDNSResolver if not resolving DNS locally.
    // This prevents a local DNS lookup (which would be ignored anyway)
    PoolingHttpClientConnectionManager cm = socks5Proxy.resolveAddrLocally() ?
            new PoolingHttpClientConnectionManager(reg) :
            new PoolingHttpClientConnectionManager(reg, new FakeDnsResolver());
    try (CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build()) {
        InetSocketAddress socksAddress = new InetSocketAddress(socks5Proxy.getInetAddress(), socks5Proxy.getPort());

        // remove me: Use this to test with system-wide Tor proxy, or change port for another proxy.
        // InetSocketAddress socksAddress = new InetSocketAddress("127.0.0.1", 9050);

        HttpClientContext context = HttpClientContext.create();
        context.setAttribute("socks.address", socksAddress);

        HttpGet request = new HttpGet(baseUrl + param);
        if (headerKey != null && headerValue != null)
            request.setHeader(headerKey, headerValue);

        log.debug("Executing request " + request + " proxy: " + socksAddress);
        try (CloseableHttpResponse response = httpclient.execute(request, context)) {
            return convertInputStreamToString(response.getEntity().getContent());
        }
    } catch (Throwable t) {
        throw new IOException("Error at requestWithGETProxy with URL: " + (baseUrl + param) + ". Throwable=" + t.getMessage());
    }
}
 
Example #16
Source File: WalletNetworkConfig.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
WalletNetworkConfig(WalletConfig delegate, NetworkParameters parameters, int socks5DiscoverMode,
                    @Nullable Socks5Proxy proxy) {
    this.delegate = delegate;
    this.parameters = parameters;
    this.socks5DiscoverMode = socks5DiscoverMode;
    this.proxy = proxy;
}
 
Example #17
Source File: BtcNodeConverterTest.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testConvertWithTor() throws DnsLookupException {
    InetAddress expected = mock(InetAddress.class);

    Facade facade = mock(Facade.class);
    when(facade.torLookup(any(), anyString())).thenReturn(expected);

    BtcNode node = mock(BtcNode.class);
    when(node.getHostNameOrAddress()).thenReturn("aaa.onion");

    PeerAddress peerAddress = new BtcNodeConverter(facade).convertWithTor(node, mock(Socks5Proxy.class));

    // noinspection ConstantConditions
    assertEquals(expected, peerAddress.getAddr());
}
 
Example #18
Source File: BtcNetworkConfigTest.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testProposePeersWhenProxyPresentAndNoPeers() {
    BtcNetworkConfig config = new BtcNetworkConfig(delegate, mock(NetworkParameters.class), MODE,
            mock(Socks5Proxy.class));
    config.proposePeers(Collections.emptyList());

    verify(delegate, never()).setPeerNodes(any());
    verify(delegate).setDiscovery(any(Socks5MultiDiscovery.class));
}
 
Example #19
Source File: BtcNetworkConfig.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public BtcNetworkConfig(WalletConfig delegate, NetworkParameters parameters, int socks5DiscoverMode,
                        @Nullable Socks5Proxy proxy) {
    this.delegate = delegate;
    this.parameters = parameters;
    this.socks5DiscoverMode = socks5DiscoverMode;
    this.proxy = proxy;
}
 
Example #20
Source File: BtcNodeConverter.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
private PeerAddress create(Socks5Proxy proxy, String host, int port) {
    try {
        // We use DnsLookupTor to not leak with DNS lookup
        // Blocking call. takes about 600 ms ;-(
        InetAddress lookupAddress = facade.torLookup(proxy, host);
        InetSocketAddress address = new InetSocketAddress(lookupAddress, port);
        return new PeerAddress(address.getAddress(), address.getPort());
    } catch (Exception e) {
        log.error("Failed to create peer address", e);
        return null;
    }
}
 
Example #21
Source File: BtcNodeConverter.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
PeerAddress convertWithTor(BtcNode node, Socks5Proxy proxy) {
    int port = node.getPort();

    PeerAddress result = create(proxy, node.getHostNameOrAddress(), port);
    if (result == null) {
        String address = node.getAddress();
        if (address != null) {
            result = create(proxy, address, port);
        } else {
            log.warn("Lookup failed, no address for node", node);
        }
    }
    return result;
}
 
Example #22
Source File: BtcNodeConverter.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
PeerAddress convertWithTor(BtcNode node, Socks5Proxy proxy) {
    int port = node.getPort();

    PeerAddress result = create(proxy, node.getHostNameOrAddress(), port);
    if (result == null) {
        String address = node.getAddress();
        if (address != null) {
            result = create(proxy, address, port);
        } else {
            log.warn("Lookup failed, no address for node", node);
        }
    }
    return result;
}
 
Example #23
Source File: WalletsSetup.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private void configPeerNodes(@Nullable Socks5Proxy proxy) {
    BtcNodesSetupPreferences btcNodesSetupPreferences = new BtcNodesSetupPreferences(preferences);

    List<BtcNode> nodes = btcNodesSetupPreferences.selectPreferredNodes(btcNodes);
    int minBroadcastConnections = btcNodesSetupPreferences.calculateMinBroadcastConnections(nodes);
    walletConfig.setMinBroadcastConnections(minBroadcastConnections);

    BtcNodesRepository repository = new BtcNodesRepository(nodes);
    boolean isUseClearNodesWithProxies = (useAllProvidedNodes || btcNodesSetupPreferences.isUseCustomNodes());
    List<PeerAddress> peers = repository.getPeerAddresses(proxy, isUseClearNodesWithProxies);

    BtcNetworkConfig networkConfig = new BtcNetworkConfig(walletConfig, params, socks5DiscoverMode, proxy);
    networkConfig.proposePeers(peers);
}
 
Example #24
Source File: BtcNodeConverter.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
private PeerAddress create(Socks5Proxy proxy, String host, int port) {
    try {
        // We use DnsLookupTor to not leak with DNS lookup
        // Blocking call. takes about 600 ms ;-(
        InetAddress lookupAddress = facade.torLookup(proxy, host);
        InetSocketAddress address = new InetSocketAddress(lookupAddress, port);
        return new PeerAddress(address.getAddress(), address.getPort());
    } catch (Exception e) {
        log.error("Failed to create peer address", e);
        return null;
    }
}
 
Example #25
Source File: WalletNetworkConfigTest.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testProposePeersWhenProxyPresentAndNoPeers() {
    WalletNetworkConfig config = new WalletNetworkConfig(delegate, mock(NetworkParameters.class), MODE,
            mock(Socks5Proxy.class));
    config.proposePeers(Collections.emptyList());

    verify(delegate, never()).setPeerNodes(any());
    verify(delegate).setDiscovery(any(Socks5MultiDiscovery.class));
}
 
Example #26
Source File: Socks5MultiDiscovery.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Supports finding peers by hostname over a socks5 proxy.
 *
 * @param proxy  proxy the socks5 proxy to connect over.
 * @param params param to be used for seed and port information.
 * @param mode   specify discovery mode, OR'd together. one or more of:
 *               SOCKS5_DISCOVER_ADDR
 *               SOCKS5_DISCOVER_DNS
 *               SOCKS5_DISCOVER_ONION
 *               SOCKS5_DISCOVER_ALL
 */
public Socks5MultiDiscovery(Socks5Proxy proxy, NetworkParameters params, int mode) {
    if ((mode & SOCKS5_DISCOVER_ONION) != 0)
        discoveryList.add(new Socks5SeedOnionDiscovery(proxy, params));

    // Testnet has no addrSeeds so SeedPeers is not supported (would throw a nullPointer)
    if ((mode & SOCKS5_DISCOVER_ADDR) != 0 && params == MainNetParams.get())
        // note:  SeedPeers does not perform any network operations, so does not use proxy.
        discoveryList.add(new SeedPeers(params));

    if ((mode & SOCKS5_DISCOVER_DNS) != 0)
        discoveryList.add(new Socks5DnsDiscovery(proxy, params));
}
 
Example #27
Source File: WalletsSetup.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
private void configPeerNodes(@Nullable Socks5Proxy proxy) {
    WalletSetupPreferences walletSetupPreferences = new WalletSetupPreferences(preferences);

    List<BtcNode> nodes = walletSetupPreferences.selectPreferredNodes(bitcoinNodes);
    int minBroadcastConnections = walletSetupPreferences.calculateMinBroadcastConnections(nodes);
    walletConfig.setMinBroadcastConnections(minBroadcastConnections);

    PeerAddressesRepository repository = new PeerAddressesRepository(nodes);
    boolean isUseClearNodesWithProxies = (useAllProvidedNodes || walletSetupPreferences.isUseCustomNodes());
    List<PeerAddress> peers = repository.getPeerAddresses(proxy, isUseClearNodesWithProxies);

    WalletNetworkConfig networkConfig = new WalletNetworkConfig(walletConfig, params, socks5DiscoverMode, proxy);
    networkConfig.proposePeers(peers);
}
 
Example #28
Source File: BtcNodeConverterTest.java    From bisq-core with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testConvertWithTor() throws DnsLookupException {
    InetAddress expected = mock(InetAddress.class);

    Facade facade = mock(Facade.class);
    when(facade.torLookup(any(), anyString())).thenReturn(expected);

    BtcNode node = mock(BtcNode.class);
    when(node.getHostNameOrAddress()).thenReturn("aaa.onion");

    PeerAddress peerAddress = new BtcNodeConverter(facade).convertWithTor(node, mock(Socks5Proxy.class));

    // noinspection ConstantConditions
    assertEquals(expected, peerAddress.getAddr());
}
 
Example #29
Source File: TorClientSocks5withAuth.java    From T0rlib4j with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, InterruptedException {
    String fileStorageLocation = "torfiles";
    OnionProxyManager onionProxyManager = new JavaOnionProxyManager(
            new JavaOnionProxyContext(new File(fileStorageLocation)));


    int totalSecondsPerTorStartup = 4 * 60;
    int totalTriesPerTorStartup = 5;

    // Start the Tor Onion Proxy
    if (onionProxyManager.startWithRepeat(totalSecondsPerTorStartup, totalTriesPerTorStartup) == false) {
        return;
    }
    // Start a hidden service listener
    int hiddenServicePort = 80;
    int localPort = onionProxyManager.getIPv4LocalHostSocksPort();
    String OnionAdress = "doqj3fyb5qjka7bb.onion";
    Authentication auth = new UserPasswordAuthentication("username", "password");

    Socks5Proxy proxy = onionProxyManager.SetupSocks5Proxy(localPort);
    proxy.setAuthenticationMethod(2, auth);


    Socket clientSocket = Utilities.Socks5connection(proxy, OnionAdress, localPort);

    ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
    out.flush();
    out.writeObject("i am workingg");
    out.flush();
}
 
Example #30
Source File: Socks5ProxyProvider.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
@Nullable
public Socks5Proxy getSocks5Proxy() {
    if (socks5ProxyBtc != null)
        return socks5ProxyBtc;
    else if (socks5ProxyInternalFactory != null)
        return getSocks5ProxyInternal();
    else
        return null;
}