This commit is contained in:
nogoegst 2017-04-05 03:35:17 +00:00 committed by GitHub
commit c3d8438633
1 changed files with 29 additions and 0 deletions

29
conn.go
View File

@ -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)