Menu

Using multiple threads with different identities?

Kaii
2015-06-25
2016-02-21
  • Kaii

    Kaii - 2015-06-25

    Hi, I am new here. Thanks in advance for your help. I have 2 questions. The first one is

    1) When I want to change my identity, do I just need to create a new NetLayer? as in:
    NetLayer lowerNetLayer = NetFactory.getInstance().getNetLayerById( NetLayerIDs.TOR);

    2) Can I have multiple threads running with different identities? And if not, can I have multiple processes in the same machine running with different identities?

    Thanks
    Kiko

     
  • Tobias Boese

    Tobias Boese - 2015-06-26

    Hi Kiko,

    usually if you are connecting to the same site, the same Circuit will be used till it is not usable or safe to use anymore.

    You can force to get a new identity by casting the NetLayer you get from NetFactory to TorNetLayer and then call method changeIdentity. This will close all open Circuits and build up new ones, usually you will get a new exit point. (It can be that you will get the same again)

    hope this helps,
    regards Tobi

     
    • Kaii

      Kaii - 2015-06-26

      Thank you Tobias

      Like this? (posting the code for the benefit of others)

      NetLayer lowerNetLayer = NetFactory.getInstance().getNetLayerById( NetLayerIDs.TOR);

          TorNetLayer torNetLayer = (TorNetLayer) lowerNetLayer;
          torNetLayer.changeIdentity();
          // wait until TOR is ready (optional):
          lowerNetLayer.waitUntilReady();
      
          NetFactory.getInstance().registerNetLayer( NetLayerIDs.TOR_OVER_TLS_OVER_TCPIP, torNetLayer );
      

      Can I run multiple threads with different circuits in each thread? And if not, can I run them with different circuits in multiple processes (JVMs)?

      Thanks again and have a great weekend
      Kiko

       
      • Vinit Parakh

        Vinit Parakh - 2015-09-21

        Hello Kaii,

        Were you able to run different IP using multithreading? I have a doubt about how to change the IP address for only that thread and not the entire network. From what I understand changeIdentity closes all the open circuits, however I just want to close the particular circuit that thread is connected to. Please let me know.

        Thanks,
        Vinit

         

        Last edit: Vinit Parakh 2015-09-21
  • Tobias Boese

    Tobias Boese - 2015-09-21

    Hi,
    currently it is not possible to influence the public IP at this level.

    As a workaround you could use the URL or IP you want to access + ".xxxxxx.exit" whereas x equals the digest of an exit node. This forces the underlying Tor implementation to only use this exit node. So in theory if this exit nodes is not busy with other requests you will be able to control your public IP.

    You can check the following UnitTest for an example : TorExitHostnameRemoteTest.java

    You can get a valid List of Exitnodes by using the method getValidTorRouters from TorNetLayer with a check on the Router.isExitNode you can easily check if it is a working exitnode, but you cannot see its current usage or availability.

    regards Tobi

     
  • Vinit Parakh

    Vinit Parakh - 2015-09-21
     

    Last edit: Vinit Parakh 2015-09-22
    • Vinit Parakh

      Vinit Parakh - 2015-09-21

      Also, I tried running TOR using multiple java processes (JVM). Whenever I called lowerNetLayer.clear() it only gave me a new IP address for the particular process. I do not understand why the behavior changes when I am using multiple threads from the same process. In this case when I call lowerNetLayer.clear() it closes all the circuits for all the threads and establishes new ones.

      Basically my use case just needs a new IP address for that thread to retry the same server that I am trying to hit.

      Thanks,
      Vinit

       

      Last edit: Vinit Parakh 2015-09-21
  • Tobias Boese

    Tobias Boese - 2016-02-21

    Hi Vinit,

    there is a "Tor-Connection-Manager" implemented as Singleton, this "Manager" is deciding which established route will be used for data. The NetLayer itself is just using the established Tor-Routes when needed. So if you execute clear this will be executed on the whole TorNetLayer and therefore also for the Tor-Connection-Manager.

    Thats why you will see a different behaviour if you start a new JVM. (new JVM -> new "Tor-Manager" instance)

    hope this clarifies it a bit.

    In your other Post about using the exit hashes, option 1 would be what you need to use.
    Only the parts between ":" and "/" will be treated as hostnames.

    regards Tobi

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.