@@ -120,6 +120,10 @@ type Controller struct {
120120 // controller connections on.
121121 controlAddr string
122122
123+ // controlAddrType is the type of address the Tor server is listening
124+ // locally for controller connections on.
125+ controlAddrType string
126+
123127 // password, if non-empty, signals that the controller should attempt to
124128 // authenticate itself with the backing Tor daemon through the
125129 // HASHEDPASSWORD authentication method with this value.
@@ -141,9 +145,16 @@ type Controller struct {
141145// a Tor server.
142146func NewController (controlAddr string , targetIPAddress string ,
143147 password string ) * Controller {
144-
148+ cleanedControlAddr := controlAddr
149+ controlAddrType := "tcp"
150+ if strings .HasPrefix (controlAddr , "unix://" ) {
151+ controlAddrType = "unix"
152+ cleanedControlAddr = strings .Replace (controlAddr , "unix://" , "" , - 1 )
153+ }
154+ log .Infof ("Tor controller controlAddr: %s" , controlAddr )
145155 return & Controller {
146- controlAddr : controlAddr ,
156+ controlAddr : cleanedControlAddr ,
157+ controlAddrType : controlAddrType ,
147158 targetIPAddress : targetIPAddress ,
148159 password : password ,
149160 }
@@ -159,7 +170,7 @@ func (c *Controller) Start() error {
159170
160171 log .Info ("Starting tor controller" )
161172
162- conn , err := textproto .Dial ("tcp" , c .controlAddr )
173+ conn , err := textproto .Dial (c . controlAddrType , c .controlAddr )
163174 if err != nil {
164175 return fmt .Errorf ("unable to connect to Tor server: %v" , err )
165176 }
@@ -222,7 +233,7 @@ func (c *Controller) Reconnect() error {
222233 }
223234
224235 // Make a new connection and authenticate.
225- conn , err := textproto .Dial ("tcp" , c .controlAddr )
236+ conn , err := textproto .Dial (c . controlAddrType , c .controlAddr )
226237 if err != nil {
227238 return fmt .Errorf ("unable to connect to Tor server: %w" , err )
228239 }
0 commit comments