tidying up code paths and making detport selection a little better
This commit is contained in:
parent
5c98fd575b
commit
fb8c0cac27
|
@ -13,10 +13,10 @@ import (
|
|||
// An example of how to setup a v3 onion service in go
|
||||
func main() {
|
||||
cpubk, cprivk, _ := ed25519.GenerateKey(rand.Reader)
|
||||
l, err := application.SetupOnionV3("127.0.0.1:9051", "tcp4", "", cprivk, 9878)
|
||||
l, err := application.SetupOnionV3("127.0.0.1:9051", "tcp4", "", cprivk, "", 9878)
|
||||
utils.CheckError(err)
|
||||
log.Printf("Got Listener %v", l.Addr().String())
|
||||
decodedPub, err := base32.StdEncoding.DecodeString(strings.ToUpper(l.Addr().String()[:56]))
|
||||
log.Printf("Decoded Public Key: %x %v", decodedPub[:32], err)
|
||||
log.Printf("ed25519 Public Key: %x", cpubk)
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ import (
|
|||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||
"io"
|
||||
"net"
|
||||
)
|
||||
)
|
||||
|
||||
// Open establishes a protocol session on an established net.Conn, and returns a new
|
||||
// OpenConnection instance representing this connection. On error, the connection
|
||||
|
|
|
@ -5,6 +5,8 @@ import (
|
|||
"golang.org/x/net/proxy"
|
||||
"net"
|
||||
"strings"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -54,28 +56,42 @@ func (nr *NetworkResolver) Resolve(hostname string) (net.Conn, string, error) {
|
|||
|
||||
conn, err := torDialer.Dial("tcp", resolvedHostname+".onion:9878")
|
||||
if err != nil {
|
||||
NewNym("127.0.0.1:9051", "tcp4", "", 9878)
|
||||
conn, err = torDialer.Dial("tcp", resolvedHostname+".onion:9878")
|
||||
torc, err := bulb.Dial("tcp4", "127.0.0.1:9051")
|
||||
if err != nil {
|
||||
log.Printf("%v\n", err)
|
||||
return nil, "", err
|
||||
}
|
||||
err = torc.Authenticate("")
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
NewNym(torc)
|
||||
conn, err = torDialer.Dial("tcp", resolvedHostname+".onion:9878")
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
return conn, resolvedHostname, nil
|
||||
}
|
||||
|
||||
|
||||
func GetTorVersion(c *bulb.Conn) (string, error) {
|
||||
resp, err := c.Request("GETINFO version")
|
||||
if err != nil {
|
||||
fmt.Printf("error getting tor version: %v\n", err)
|
||||
return "", nil
|
||||
}
|
||||
if len(resp.Data) > 0 {
|
||||
return resp.Data[0], nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// runs SIGNAL NEWNYM on the tor control port to flush the onion descriptors cache
|
||||
func NewNym(torControlAddress string, torControlSocketType string, authentication string, onionport uint16) error {
|
||||
c, err := bulb.Dial(torControlSocketType, torControlAddress)
|
||||
func NewNym(c *bulb.Conn) error {
|
||||
_, err := c.Request("SIGNAL NEWNYM")
|
||||
if err != nil {
|
||||
return err
|
||||
c.Close()
|
||||
}
|
||||
|
||||
err = c.Authenticate(authentication)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = c.Request("SIGNAL NEWNYM")
|
||||
return err
|
||||
}
|
||||
|
|
Reference in New Issue