more tor provider into to own package, fix race condition, minor renaming
这个提交包含在:
父节点
504139e4c6
当前提交
e276c4fbe7
|
@ -1,2 +1,3 @@
|
|||
tor/
|
||||
.idea/
|
||||
coverage.*
|
||||
tor/tor/
|
||||
|
|
12
acn.go
12
acn.go
|
@ -4,6 +4,18 @@ import (
|
|||
"net"
|
||||
)
|
||||
|
||||
// Error captures various common ricochet errors
|
||||
type Error string
|
||||
|
||||
func (e Error) Error() string { return string(e) }
|
||||
|
||||
const (
|
||||
// CannotResolveLocalTCPAddressError is thrown when a local ricochet connection has the wrong format.
|
||||
CannotResolveLocalTCPAddressError = Error("CannotResolveLocalTCPAddressError")
|
||||
// CannotDialLocalTCPAddressError is thrown when a connection to a local ricochet address fails.
|
||||
CannotDialLocalTCPAddressError = Error("CannotDialLocalTCPAddressError")
|
||||
)
|
||||
|
||||
// PrivateKey represents a private key using an unspecified algorithm.
|
||||
type PrivateKey interface{}
|
||||
|
||||
|
|
|
@ -13,6 +13,11 @@ type localListenService struct {
|
|||
type localProvider struct {
|
||||
}
|
||||
|
||||
// NewLocalACN returns a for testing use only local clearnet implementation of a ACN interface
|
||||
func NewLocalACN() ACN {
|
||||
return &localProvider{}
|
||||
}
|
||||
|
||||
func (ls *localListenService) AddressFull() string {
|
||||
return ls.l.Addr().String()
|
||||
}
|
||||
|
@ -70,8 +75,3 @@ func (lp *localProvider) Restart() {
|
|||
func (lp *localProvider) Close() {
|
||||
|
||||
}
|
||||
|
||||
// LocalProvider returns a for testing use only local clearnet implementation of a ACN interface
|
||||
func LocalProvider() ACN {
|
||||
return &localProvider{}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
pwd
|
||||
GORACE="haltonerror=1"
|
||||
go test -race ${1} -coverprofile=tor.cover.out -v ./tor
|
||||
echo "mode: set" > coverage.out && cat *.cover.out | grep -v mode: | sort -r | \
|
||||
awk '{if($1 != last) {print $0;last=$1}}' >> coverage.out
|
||||
rm -rf *.cover.out
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// +build !windows
|
||||
|
||||
package connectivity
|
||||
package tor
|
||||
|
||||
import (
|
||||
"syscall"
|
|
@ -1,6 +1,6 @@
|
|||
// +build windows
|
||||
|
||||
package connectivity
|
||||
package tor
|
||||
|
||||
import (
|
||||
"syscall"
|
|
@ -1,8 +1,9 @@
|
|||
package connectivity
|
||||
package tor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"git.openprivacy.ca/openprivacy/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"github.com/cretz/bine/control"
|
||||
"github.com/cretz/bine/process"
|
||||
|
@ -22,25 +23,16 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// Error captures various common ricochet errors
|
||||
type Error string
|
||||
|
||||
func (e Error) Error() string { return string(e) }
|
||||
|
||||
const (
|
||||
// CannotResolveLocalTCPAddressError is thrown when a local ricochet connection has the wrong format.
|
||||
CannotResolveLocalTCPAddressError = Error("CannotResolveLocalTCPAddressError")
|
||||
// CannotDialLocalTCPAddressError is thrown when a connection to a local ricochet address fails.
|
||||
CannotDialLocalTCPAddressError = Error("CannotDialLocalTCPAddressError")
|
||||
// CannotDialRicochetAddressError is thrown when a connection to a ricochet address fails.
|
||||
CannotDialRicochetAddressError = Error("CannotDialRicochetAddressError")
|
||||
)
|
||||
|
||||
const (
|
||||
minStatusIntervalMs = 200
|
||||
maxStatusIntervalMs = 2000
|
||||
)
|
||||
|
||||
const (
|
||||
// CannotDialRicochetAddressError is thrown when a connection to a ricochet address fails.
|
||||
CannotDialRicochetAddressError = connectivity.Error("CannotDialRicochetAddressError")
|
||||
)
|
||||
|
||||
type onionListenService struct {
|
||||
os *tor.OnionService
|
||||
tp *torProvider
|
||||
|
@ -112,7 +104,7 @@ func (tp *torProvider) WaitTillBootstrapped() {
|
|||
}
|
||||
}
|
||||
|
||||
func (tp *torProvider) Listen(identity PrivateKey, port int) (ListenService, error) {
|
||||
func (tp *torProvider) Listen(identity connectivity.PrivateKey, port int) (connectivity.ListenService, error) {
|
||||
var onion = ""
|
||||
var privkey ed25519.PrivateKey
|
||||
|
||||
|
@ -207,8 +199,8 @@ func (tp *torProvider) SetStatusCallback(callback func(int, string)) {
|
|||
tp.statusCallback = callback
|
||||
}
|
||||
|
||||
// StartTor creates/starts a Tor ACN and returns a usable ACN object
|
||||
func StartTor(appDirectory string, bundledTorPath string) (ACN, error) {
|
||||
// NewTorACN creates/starts a Tor ACN and returns a usable ACN object
|
||||
func NewTorACN(appDirectory string, bundledTorPath string) (connectivity.ACN, error) {
|
||||
tp, err := startTor(appDirectory, bundledTorPath)
|
||||
if err == nil {
|
||||
tp.dialer, err = tp.t.Dialer(nil, &tor.DialConf{})
|
||||
|
@ -293,15 +285,19 @@ func (tp *torProvider) monitorRestart() {
|
|||
prog, status := tp.GetBootstrapStatus()
|
||||
|
||||
if prog == -1 && tp.t != nil {
|
||||
tp.lock.Lock()
|
||||
if tp.statusCallback != nil {
|
||||
tp.statusCallback(prog, status)
|
||||
}
|
||||
tp.lock.Unlock()
|
||||
tp.restart()
|
||||
interval = minStatusIntervalMs
|
||||
} else if prog != lastBootstrapProgress {
|
||||
tp.lock.Lock()
|
||||
if tp.statusCallback != nil {
|
||||
tp.statusCallback(prog, status)
|
||||
}
|
||||
tp.lock.Unlock()
|
||||
interval = minStatusIntervalMs
|
||||
} else {
|
||||
if interval < maxStatusIntervalMs {
|
|
@ -1,4 +1,4 @@
|
|||
package connectivity
|
||||
package tor
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -14,7 +14,7 @@ func getStatusCallback(progChan chan int) func(int, string) {
|
|||
|
||||
func TestTorProvider(t *testing.T) {
|
||||
progChan := make(chan int)
|
||||
acn, err := StartTor(".", "")
|
||||
acn, err := NewTorACN(".", "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
|
@ -1,10 +1,10 @@
|
|||
package connectivity
|
||||
package tor
|
||||
|
||||
import (
|
||||
"encoding/base32"
|
||||
"strings"
|
||||
"golang.org/x/crypto/ed25519"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// V3HostnameLength is the length of a Tor V3 Onion Address (without the .onion suffix)
|
正在加载...
在新工单中引用