Class UnixTorWrapper

  • All Implemented Interfaces:
    net.freehaven.tor.control.EventHandler, org.briarproject.onionwrapper.TorWrapper

    @NotNullByDefault
    public class UnixTorWrapper
    extends java.lang.Object
    A Tor wrapper for Unix-like operating systems.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.briarproject.onionwrapper.TorWrapper

        org.briarproject.onionwrapper.TorWrapper.HiddenServiceProperties, org.briarproject.onionwrapper.TorWrapper.Observer, org.briarproject.onionwrapper.TorWrapper.TorState
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.Executor eventExecutor  
      protected java.util.concurrent.Executor ioExecutor  
      protected org.briarproject.onionwrapper.AbstractTorWrapper.NetworkState state  
      • Fields inherited from interface org.briarproject.onionwrapper.TorWrapper

        LOG
    • Constructor Summary

      Constructors 
      Constructor Description
      UnixTorWrapper​(java.util.concurrent.Executor ioExecutor, java.util.concurrent.Executor eventExecutor, java.lang.String architecture, java.io.File torDirectory, int torSocksPort, int torControlPort)  
    • Field Detail

      • ioExecutor

        protected final java.util.concurrent.Executor ioExecutor
      • eventExecutor

        protected final java.util.concurrent.Executor eventExecutor
      • state

        protected final org.briarproject.onionwrapper.AbstractTorWrapper.NetworkState state
    • Constructor Detail

      • UnixTorWrapper

        public UnixTorWrapper​(java.util.concurrent.Executor ioExecutor,
                              java.util.concurrent.Executor eventExecutor,
                              java.lang.String architecture,
                              java.io.File torDirectory,
                              int torSocksPort,
                              int torControlPort)
        Parameters:
        ioExecutor - The wrapper will use this executor to run IO tasks, some of which may run for the lifetime of the wrapper, so the executor should have an unlimited thread pool.
        eventExecutor - The wrapper will use this executor to call the observer (if any). To ensure that events are observed in the order they occur, this executor should have a single thread (eg the app's main thread).
        architecture - The processor architecture of the Tor and pluggable transport binaries.
        torDirectory - The directory where the Tor process should keep its state.
        torSocksPort - The port number to use for Tor's SOCKS port.
        torControlPort - The port number to use for Tor's control port.
    • Method Detail

      • getProcessId

        protected int getProcessId()
      • getLastUpdateTime

        protected long getLastUpdateTime()
      • getResourceInputStream

        protected java.io.InputStream getResourceInputStream​(java.lang.String name,
                                                             java.lang.String extension)
      • getTorExecutableFile

        protected java.io.File getTorExecutableFile()
      • getObfs4ExecutableFile

        public java.io.File getObfs4ExecutableFile()
        Specified by:
        getObfs4ExecutableFile in interface org.briarproject.onionwrapper.TorWrapper
      • getSnowflakeExecutableFile

        protected java.io.File getSnowflakeExecutableFile()
      • setObserver

        public void setObserver​(@Nullable
                                org.briarproject.onionwrapper.TorWrapper.Observer arg0)
        Specified by:
        setObserver in interface org.briarproject.onionwrapper.TorWrapper
      • start

        public void start()
                   throws java.io.IOException,
                          java.lang.InterruptedException
        Specified by:
        start in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • extract

        protected void extract​(java.io.InputStream arg0,
                               java.io.File arg1)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • installTorExecutable

        protected void installTorExecutable()
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • installObfs4Executable

        protected void installObfs4Executable()
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • installSnowflakeExecutable

        protected void installSnowflakeExecutable()
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • getExecutableExtension

        protected java.lang.String getExecutableExtension()
      • waitForTorToStart

        protected void waitForTorToStart​(java.lang.Process arg0)
                                  throws java.lang.InterruptedException,
                                         java.io.IOException
        Throws:
        java.lang.InterruptedException
        java.io.IOException
      • publishHiddenService

        public org.briarproject.onionwrapper.TorWrapper.HiddenServiceProperties publishHiddenService​(int arg0,
                                                                                                     int arg1,
                                                                                                     @Nullable
                                                                                                     java.lang.String arg2)
                                                                                              throws java.io.IOException
        Specified by:
        publishHiddenService in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
      • removeHiddenService

        public void removeHiddenService​(java.lang.String arg0)
                                 throws java.io.IOException
        Specified by:
        removeHiddenService in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
      • enableNetwork

        public void enableNetwork​(boolean arg0)
                           throws java.io.IOException
        Specified by:
        enableNetwork in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
      • enableBridges

        public void enableBridges​(java.util.List<java.lang.String> arg0)
                           throws java.io.IOException
        Specified by:
        enableBridges in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
      • disableBridges

        public void disableBridges()
                            throws java.io.IOException
        Specified by:
        disableBridges in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
      • stop

        public void stop()
                  throws java.io.IOException,
                         java.lang.InterruptedException
        Specified by:
        stop in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • circuitStatus

        public void circuitStatus​(java.lang.String arg0,
                                  java.lang.String arg1,
                                  java.lang.String arg2)
        Specified by:
        circuitStatus in interface net.freehaven.tor.control.EventHandler
      • streamStatus

        public void streamStatus​(java.lang.String arg0,
                                 java.lang.String arg1,
                                 java.lang.String arg2)
        Specified by:
        streamStatus in interface net.freehaven.tor.control.EventHandler
      • orConnStatus

        public void orConnStatus​(java.lang.String arg0,
                                 java.lang.String arg1)
        Specified by:
        orConnStatus in interface net.freehaven.tor.control.EventHandler
      • bandwidthUsed

        public void bandwidthUsed​(long arg0,
                                  long arg1)
        Specified by:
        bandwidthUsed in interface net.freehaven.tor.control.EventHandler
      • newDescriptors

        public void newDescriptors​(java.util.List<java.lang.String> arg0)
        Specified by:
        newDescriptors in interface net.freehaven.tor.control.EventHandler
      • message

        public void message​(java.lang.String arg0,
                            java.lang.String arg1)
        Specified by:
        message in interface net.freehaven.tor.control.EventHandler
      • unrecognized

        public void unrecognized​(java.lang.String arg0,
                                 java.lang.String arg1)
        Specified by:
        unrecognized in interface net.freehaven.tor.control.EventHandler
      • controlConnectionClosed

        public void controlConnectionClosed()
        Specified by:
        controlConnectionClosed in interface net.freehaven.tor.control.EventHandler
      • enableConnectionPadding

        public void enableConnectionPadding​(boolean arg0)
                                     throws java.io.IOException
        Specified by:
        enableConnectionPadding in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
      • enableIpv6

        public void enableIpv6​(boolean arg0)
                        throws java.io.IOException
        Specified by:
        enableIpv6 in interface org.briarproject.onionwrapper.TorWrapper
        Throws:
        java.io.IOException
      • getTorState

        public org.briarproject.onionwrapper.TorWrapper.TorState getTorState()
        Specified by:
        getTorState in interface org.briarproject.onionwrapper.TorWrapper
      • isTorRunning

        public boolean isTorRunning()
        Specified by:
        isTorRunning in interface org.briarproject.onionwrapper.TorWrapper