forked from openprivacy/connectivity
yank out some Tor stuff that sam3 can handle itself
This commit is contained in:
parent
683120487d
commit
0cc0fb9a99
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/eyedeekay/go-i2pcontrol"
|
||||
"github.com/eyedeekay/sam3"
|
||||
"github.com/eyedeekay/sam3/i2pkeys"
|
||||
//"github.com/eyedeekay/sam3/helper"
|
||||
"git.openprivacy.ca/openprivacy/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
|
@ -58,7 +59,7 @@ func (l *logWriter) Write(p []byte) (int, error) {
|
|||
return len(p), nil
|
||||
}
|
||||
|
||||
type onionListenService struct {
|
||||
type garlicListenService struct {
|
||||
os *sam3.StreamListener
|
||||
tp *i2pProvider
|
||||
}
|
||||
|
@ -71,25 +72,25 @@ type i2pProvider struct {
|
|||
bundeledTorPath string
|
||||
lock sync.Mutex
|
||||
breakChan chan bool
|
||||
childListeners map[string]*onionListenService
|
||||
childListeners map[string]*garlicListenService
|
||||
statusCallback func(int, string)
|
||||
lastRestartTime time.Time
|
||||
//authenticator tor.Authenticator
|
||||
}
|
||||
|
||||
func (ols *onionListenService) AddressFull() string {
|
||||
func (ols *garlicListenService) AddressFull() string {
|
||||
return ols.os.Addr().String()
|
||||
}
|
||||
|
||||
func (ols *onionListenService) AddressIdentity() string {
|
||||
func (ols *garlicListenService) AddressIdentity() string {
|
||||
return ols.os.Addr().String()[:56]
|
||||
}
|
||||
|
||||
func (ols *onionListenService) Accept() (net.Conn, error) {
|
||||
func (ols *garlicListenService) Accept() (net.Conn, error) {
|
||||
return ols.os.Accept()
|
||||
}
|
||||
|
||||
func (ols *onionListenService) Close() {
|
||||
func (ols *garlicListenService) Close() {
|
||||
ols.tp.unregisterListener(ols.AddressIdentity())
|
||||
ols.os.Close()
|
||||
}
|
||||
|
@ -143,7 +144,7 @@ func (tp *i2pProvider) WaitTillBootstrapped() {
|
|||
}
|
||||
|
||||
func (tp *i2pProvider) Listen(identity connectivity.PrivateKey, port int) (connectivity.ListenService, error) {
|
||||
var onion = ""
|
||||
var garlic = ""
|
||||
var privkey ed25519.PrivateKey
|
||||
|
||||
tp.lock.Lock()
|
||||
|
@ -158,14 +159,14 @@ func (tp *i2pProvider) Listen(identity connectivity.PrivateKey, port int) (conne
|
|||
privkey = pk
|
||||
gpubk := pk.Public()
|
||||
switch pubk := gpubk.(type) {
|
||||
case ed25519.PublicKey:
|
||||
onion = GetTorV3Hostname(pubk)
|
||||
case i2pkeys.I2PKeys:
|
||||
garlic = pubk.Addr().String()
|
||||
}
|
||||
}
|
||||
|
||||
// Hack around tor detached onions not having a more obvious resume mechanism
|
||||
// Hack around tor detached garlics not having a more obvious resume mechanism
|
||||
// So we use deterministic ports
|
||||
seedbytes := sha3.New224().Sum([]byte(onion))
|
||||
seedbytes := sha3.New224().Sum([]byte(garlic))
|
||||
localport := int(seedbytes[0]) + (int(seedbytes[1]) << 8)
|
||||
if localport < 1024 { // this is not uniformly random, but we don't need it to be
|
||||
localport += 1024
|
||||
|
@ -173,20 +174,20 @@ func (tp *i2pProvider) Listen(identity connectivity.PrivateKey, port int) (conne
|
|||
|
||||
localListener, err := net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(localport))
|
||||
|
||||
conf := &tor.ListenConf{NoWait: true, Version3: true, Key: identity, RemotePorts: []int{port}, Detach: true, DiscardKey: true, LocalListener: localListener}
|
||||
os, err := tp.t.Listen(nil, conf)
|
||||
if err != nil && strings.Contains(err.Error(), "550 Unspecified Tor error: Onion address collision") {
|
||||
os = &tor.OnionService{Tor: tp.t, LocalListener: localListener, ID: onion, Version3: true, Key: bineed255192.FromCryptoPrivateKey(privkey), ClientAuths: make(map[string]string, 0), RemotePorts: []int{port}}
|
||||
err = nil
|
||||
}
|
||||
// conf := &tor.ListenConf{NoWait: true, Version3: true, Key: identity, RemotePorts: []int{port}, Detach: true, DiscardKey: true, LocalListener: localListener}
|
||||
// os, err := tp.t.Listen(nil, conf)
|
||||
// if err != nil && strings.Contains(err.Error(), "550 Unspecified Tor error: garlic address collision") {
|
||||
// os = &tor.garlicService{Tor: tp.t, LocalListener: localListener, ID: garlic, Version3: true, Key: bineed255192.FromCryptoPrivateKey(privkey), ClientAuths: make(map[string]string, 0), RemotePorts: []int{port}}
|
||||
// err = nil
|
||||
// }
|
||||
// Not set in t.Listen if supplied, we want it to handle this however
|
||||
os.CloseLocalListenerOnClose = true
|
||||
//os.CloseLocalListenerOnClose = true
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ols := &onionListenService{os: os, tp: tp}
|
||||
ols := &garlicListenService{os: garlic, tp: tp}
|
||||
tp.childListeners[ols.AddressIdentity()] = ols
|
||||
return ols, nil
|
||||
}
|
||||
|
@ -211,7 +212,7 @@ func (tp *i2pProvider) Open(hostname string) (net.Conn, string, error) {
|
|||
resolvedHostname = addrParts[1]
|
||||
}
|
||||
|
||||
conn, err := tp.dialer.Dial("tcp", resolvedHostname+".onion:9878")
|
||||
conn, err := tp.dialer.Dial("tcp", resolvedHostname+".garlic:9878")
|
||||
return conn, resolvedHostname, err
|
||||
}
|
||||
|
||||
|
@ -292,7 +293,7 @@ func startTor(appDirectory string, bundledTorPath string, controlPort int, authe
|
|||
return nil, fmt.Errorf("Unable to create temp data dir: %v", err)
|
||||
}
|
||||
|
||||
tp := &i2pProvider{authenticator: authenticator, controlPort: controlPort, appDirectory: appDirectory, bundeledTorPath: bundledTorPath, childListeners: make(map[string]*onionListenService), breakChan: make(chan bool), statusCallback: nil, lastRestartTime: time.Now().Add(-restartCooldown)}
|
||||
tp := &i2pProvider{authenticator: authenticator, controlPort: controlPort, appDirectory: appDirectory, bundeledTorPath: bundledTorPath, childListeners: make(map[string]*garlicListenService), breakChan: make(chan bool), statusCallback: nil, lastRestartTime: time.Now().Add(-restartCooldown)}
|
||||
|
||||
log.Debugf("launching system tor")
|
||||
if err := tp.checkVersion(); err == nil {
|
||||
|
|
Loading…
Reference in New Issue