Merge 0b4fc1eff8
into 85d80d893c
This commit is contained in:
commit
c3d8438633
29
conn.go
29
conn.go
|
@ -16,6 +16,8 @@ import (
|
|||
"net"
|
||||
"net/textproto"
|
||||
"sync"
|
||||
|
||||
bulbUtils "github.com/yawning/bulb/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -219,6 +221,33 @@ func Dial(network, addr string) (*Conn, error) {
|
|||
return NewConn(c), nil
|
||||
}
|
||||
|
||||
const(
|
||||
torControlPort = "9051"
|
||||
tbbControlPort = "9151"
|
||||
)
|
||||
|
||||
// DialURL connects to a given control string (URL) and returns a new Conn for the
|
||||
// connection. If control string is "default://" DialURL tries to connect to the
|
||||
// system-wide tor daemon and if not succedes tries to connect to tor from
|
||||
// TorBrowser Bundle.
|
||||
func DialURL(URL string) (c *Conn, err error) {
|
||||
if URL == "default://" {
|
||||
for _, u := range []string{torControlPort, tbbControlPort} {
|
||||
c, err = DialURL(u)
|
||||
if err == nil {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
// It is a non-default control string
|
||||
network, addr, err := bulbUtils.ParseControlPortString(URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return Dial(network, addr)
|
||||
}
|
||||
|
||||
// NewConn returns a new Conn using c for I/O.
|
||||
func NewConn(c io.ReadWriteCloser) *Conn {
|
||||
conn := new(Conn)
|
||||
|
|
Reference in New Issue