Giter Club home page Giter Club logo

Comments (10)

SpiReCZ avatar SpiReCZ commented on August 16, 2024 1

I created a PR: bisq-network/netlayer#13
These contain some fixes and also required changes for my use case.

Desired behavior can be made by:

@Configuration
class TorConfig {

    @Bean
    @Throws(IOException::class)
    fun torrc(): Torrc {
        val ports = obtainFreePorts()
        val overrides = LinkedHashMap<String, String>()
        // It is required to set ports manually
        overrides["ControlPort"] = ports.first.toString()
        overrides["SOCKSPort"] = ports.second.toString()
        return Torrc(overrides)
    }

}

and extension function:

    fun Tor.reload() {
        val torControllerField: Field = Tor::class.java.getDeclaredField("torController")
        torControllerField.isAccessible = true
        val torController: TorController = torControllerField.get(this) as TorController
        torController.setConf("DisableNetwork", "1")
        torController.setConf("DisableNetwork", "0")
    }

from bitcoin-spring-boot-starter.

theborakompanioni avatar theborakompanioni commented on August 16, 2024

Thank you for your request. I appreciate all the thought you put into it and you took the time to lay them out in a very comprehensible way.

I also tried using NEWNYM, but that does not provide deterministic outcome, since the new circuits provided can ultimately have the same IP or the signal is ignored by Tor at some point.

Yeah, it seems this is the way how Tor inherently works. On the document you linked, you can find this quote:

An important thing to note is that a new circuit does not necessarily mean a new IP address. Paths are randomly selected based on heuristics like speed and stability. There are only so many large exits in the Tor network, so it's not uncommon to reuse an exit you have had previously.

Also:

Tor does not have a method for cycling your IP address. This is on purpose, and done for a couple reasons. The first is that this capability is usually requested for not-so-nice reasons such as ban evasion or SEO. Second, repeated circuit creation puts a very high load on the Tor network, so please don't!

Then, it mentions torrc config MaxCircuitDirtiness, which states the time in seconds when a circuit becomes "dirty" and hence a new one is built.

But from stackoverflow#66634188:

Please note that MaxCircuitDirtiness only ensures that a new Tor circuit is created and used, but that does not always imply a new IP (i.e. does not always imply a different "end node" on the new circuit).

So, I think there is no real way to do what you want to achieve, at least not with Tor. Maybe I2P is better suited? I really don't know, as I am not familiar with it.

But, you are right, at first glance, the underlying lib currently does not provide much flexibility in terms of control and customization.
I will see what can be done about this.

from bitcoin-spring-boot-starter.

SpiReCZ avatar SpiReCZ commented on August 16, 2024

Check this out: https://github.com/setnicka/ulozto-downloader/blob/0e3b810f7676f543bf403f2f6b998c9ea02fb893/uldlib/page.py#L242
It is my exact use case scenario.
It also leads to this: https://github.com/setnicka/ulozto-downloader/blob/0e3b810f7676f543bf403f2f6b998c9ea02fb893/uldlib/torrunner.py#L59
(as mentioned in the stem documentation)

Change of the IP may be only a side effect in the end, but in the linked case it is used as change of the IP.

from bitcoin-spring-boot-starter.

theborakompanioni avatar theborakompanioni commented on August 16, 2024

I think you can accomplish it by yourself if you access the torController var of an instance of the Tor class, e.g.:

Field torControllerField = Tor.class.getDeclaredField("torController");
torControllerField.setAccessible(true);
TorController torController = (TorController) torControllerField.get(yourTorInstance);
// use "signal" to send commands
torController.signal("RELOAD");
torController.signal("HUP");

I am very reluctant to expose this object as a spring managed bean, as it is a protected member and not intended to be used like this. Maybe this issue is better placed in the library repo: https://github.com/bisq-network/netlayer
If this mechanism is made available for downstream consumers, I am happy to expose it!

What do you say? Does this sound reasonable to you?

from bitcoin-spring-boot-starter.

SpiReCZ avatar SpiReCZ commented on August 16, 2024

I figured RELOAD/HUP does not work with Tor being in Daemon mode..
I will fiddle with it a bit more, but yes the bisq-network library is the one where everything that could be changed is.
It's sad they do not have enabled issues on their github fork and their implementations are pretty locked up and non-configurable.

from bitcoin-spring-boot-starter.

theborakompanioni avatar theborakompanioni commented on August 16, 2024

I figured RELOAD/HUP does not work with Tor being in Daemon mode..

Ah, thanks for the info.

I will fiddle with it a bit more, but yes the bisq-network library is the one where everything that could be changed is. It's sad they do not have enabled issues on their github fork and their implementations are pretty locked up and non-configurable.

Damn.. you are right. Issues not enabled.. strange. You might be better of writing your own.
Or, if you find a suitable library, let me know - might be beneficial to others as well.

Thank you.

from bitcoin-spring-boot-starter.

SpiReCZ avatar SpiReCZ commented on August 16, 2024

The issue with this and dependant Tor libraries is that they do very little, yet they are seperated. If it was just 1 multi-module separate project just for Tor Java/Kotlin integration it would be cool.
I was lucky to find this library, took me a long time. There are a lot of forks of the original java impl, but every library seems dead and undocumented.

from bitcoin-spring-boot-starter.

SpiReCZ avatar SpiReCZ commented on August 16, 2024

Have you considered to separate the tor library from this project?

from bitcoin-spring-boot-starter.

theborakompanioni avatar theborakompanioni commented on August 16, 2024

Have you considered to separate the tor library from this project?

Yes, I thought about that. But in fact, the project is already independent from the other modules and also published to maven central. Do you refer to better discoverability and/or documentation if it is a standalone project? I am certainly not against that at all! Currently, it is all done in a single repo as it is just easier for me to update dependencies or publish releases.

from bitcoin-spring-boot-starter.

theborakompanioni avatar theborakompanioni commented on August 16, 2024

Have you considered to separate the tor library from this project?

spring-tor has been externalized to https://github.com/theborakompanioni/tor-spring-boot-starter

from bitcoin-spring-boot-starter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.