ipsn / go-libtor Goto Github PK
View Code? Open in Web Editor NEWSelf-contained Tor from Go
License: BSD 3-Clause "New" or "Revised" License
Self-contained Tor from Go
License: BSD 3-Clause "New" or "Revised" License
Hi,
A small issue here regarding the signal capture and exit sequence.
Upon receiving the interrupt signal, i can see the Tor process handles it (there is a log line, and the onion respond with 0xF2).
But the Go program, it is not notified, an additional signal is required to get it done.
I also tried to wait, in the hope some timeout would occur, but no luck.
I am a bit concerned by this behavior in the perspective of a service setup (but maybe I should not).
Some logs and data, stripped for clarity.
System
[mh-cbon@Host-001 bootstrap]$ uname -a
Linux Host-001 5.18.17-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Aug 11 14:36:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
[mh-cbon@Host-001 bootstrap]$ cat /etc/fedora-release
Fedora release 36 (Thirty Six)
[mh-cbon@Host-001 bootstrap]$ go version
go version go1.19 linux/amd64
require (
github.com/cretz/bine v0.2.0
github.com/ipsn/go-libtor v1.0.380
)
The Program output
$ go run .
INFO[0002] upnp: found 1 clients
INFO[0002] upnp: configured 192.168.1.78:40003 => 80 for 10h0m0s on device http://192.168.1.254:42990/rootDesc.xml
Using embedded control connection
Starting tor with args [--DataDirectory /tmp/tor --CookieAuthentication 1 --DisableNetwork 1 --SocksPort auto -f /tmp/tor/torrc-1589576849]
Write line: PROTOCOLINFO
Aug 14 20:47:22.967 [notice] Tor 0.3.5.14-dev (git-da728e36f4579907) running on Linux with Libevent 2.2.0-alpha-dev, OpenSSL 1.1.1l-dev, Zlib 1.2.11, Liblzma N/A, and Libzstd N/A.
Aug 14 20:47:22.967 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Aug 14 20:47:22.967 [notice] Read configuration file "/tmp/tor/torrc-1589576849".
....
$568B6913AE5123EDBA304909A569AFE8F9E73C4C~OrwellianNightmare
Write line: SETEVENTS
Read line: 250 OK
INFO[0009] bootstrap: Onion ready at http://vq7emfluv5meujjc5gzs2gad632mnxclmhxwcgkba476hlkx4srkpdyd.onion
INFO[0011] upnp: found 1 clients
INFO[0011] bootstrap: Website ready at http://notshownhere/
INFO[0011] bootstrap: static website running at http://127.0.0.1:40895/
^CAug 14 20:48:53.000 [notice] Interrupt: exiting cleanly.
^C ERROR[0409] bootstrap: Quitting...
Closing onion vq7emfluv5meujjc5gzs2gad632mnxclmhxwcgkba476hlkx4srkpdyd.onion:80
Write line: DEL_ONION vq7emfluv5meujjc5gzs2gad632mnxclmhxwcgkba476hlkx4srkpdyd
INFO[0409] bootstrap: accept tcp 127.0.0.1:36877: use of closed network connection
Failed closing onion: write unix @->@: write: broken pipe
Closing Tor
Write line: SIGNAL HALT
Write line: QUIT
Error while closing Tor: Unable to signal halt: write unix @->@: write: broken pipe
INFO[0409] bootstrap: accept tcp 192.168.1.78:40003: use of closed network connection
INFO[0412] upnp: found 1 clients
INFO[0412] upnp: deleted the port mapping for device http://192.168.1.254:42990/rootDesc.xml
In that log i waited like 5 minutes before giving up.
My code is super boring, I have a small func, which mostly copy paste your examples, with a small wrapper, and some calling code relying on the stdlib to capture the signal and a context to wait on.
package main
import (
"bytes"
"context"
"crypto"
"crypto/ed25519"
"fmt"
"net"
"os"
"path/filepath"
"github.com/cretz/bine/tor"
"github.com/hashicorp/go-multierror"
"github.com/ipsn/go-libtor"
)
type torConfig struct {
Enabled bool
RemotePort int `yaml:"remote-port"`
Key string `yaml:"key-path"`
CreateDataDir bool `yaml:"create-data-dir"`
DataDir string `yaml:"data-dir"`
// KeyFormat string `yaml:"key-format"` // unclear what are the storing formats.
}
func torSocket(ctx context.Context, config torConfig) (*torListener, error) {
if !config.Enabled {
return nil, nil
}
var key crypto.PrivateKey
if keypath := config.Key; keypath != "" {
s, err := os.Stat(keypath)
if err != nil {
return nil, fmt.Errorf("tor could not load the private key at %v: %v", config.Key, err)
}
if s.IsDir() {
keypath = filepath.Join(keypath, "hs_ed25519_secret_key")
}
d, err := os.ReadFile(keypath)
if err != nil {
return nil, fmt.Errorf("tor could not load the private key at %v: %v", config.Key, err)
}
d = bytes.TrimPrefix(d, []byte("== ed25519v1-secret: type0 ==\x00\x00\x00"))
key = ed25519.PrivateKey(d)
}
if config.CreateDataDir {
err := os.MkdirAll(config.DataDir, os.ModePerm)
if err != nil {
return nil, err
}
}
t, err := tor.Start(ctx, &tor.StartConf{
ProcessCreator: libtor.Creator,
DebugWriter: os.Stderr,
UseEmbeddedControlConn: true,
DataDir: config.DataDir,
NoHush: true,
})
if err != nil {
return nil, fmt.Errorf("failed to start tor: %v", err)
}
onion, err := t.Listen(ctx, &tor.ListenConf{
RemotePorts: []int{config.RemotePort},
Key: key,
Version3: true,
})
if err != nil {
return nil, fmt.Errorf("failed to create onion service: %v", err)
}
return &torListener{Listener: onion, torProcess: t}, nil
}
type torListener struct {
net.Listener
torProcess *tor.Tor
}
func (t *torListener) URL() string {
if t.Listener == nil {
return ""
}
return "http://" + t.Listener.(*tor.OnionService).ID + ".onion"
}
func (t *torListener) Close() (out error) {
if t.Listener != nil {
if err := t.Listener.Close(); err != nil {
out = multierror.Append(out, err)
}
}
if t.torProcess != nil {
if err := t.torProcess.Close(); err != nil {
out = multierror.Append(out, err)
}
}
return
}
The caller code is like
// some pile of things here.
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
// some pile of things here.
torln, err := torSocket(context.Background(), config.Tor)
if err != nil {
Logger.Errorf("tor not set up: %v", err)
} else if torln != nil {
Logger.Infof("Onion ready at %v", torln.URL())
defer torln.Close()
}
// some pile of things here.
<-ctx.Done()
Logger.Error("Quitting...")
// return,return,return
originally posted at cretz/bine#68
Thanks for working on this library, it's a really neat approach!
I have seen that some people have added support for iOS and macOS and I am wondering if you could consider upstreaming the changes so that we can consolidate efforts in a single repo: berty/go-libtor#6.
I would be happy to help out in any way I can to aid in the process.
~/go/src/github.com/cloudwizard/testtorgo$ go get -u -v -x github.com/ipsn/go-libtor
# get https://proxy.golang.org/github.com/@v/list
# get https://proxy.golang.org/github.com/ipsn/go-libtor/@v/list
# get https://proxy.golang.org/github.com/ipsn/@v/list
# get https://proxy.golang.org/github.com/@v/list: 410 Gone (0.265s)
# get https://proxy.golang.org/github.com/ipsn/@v/list: 410 Gone (0.356s)
# get https://proxy.golang.org/github.com/ipsn/go-libtor/@v/list: 200 OK (0.375s)
# get https://proxy.golang.org/github.com/ipsn/go-libtor/@v/v1.0.380.info
# get https://proxy.golang.org/github.com/ipsn/go-libtor/@v/v1.0.380.info: 200 OK (0.046s)
# get https://proxy.golang.org/github.com/ipsn/go-libtor/@v/v1.0.380.mod
# get https://proxy.golang.org/github.com/ipsn/go-libtor/@v/v1.0.380.mod: 200 OK (0.178s)
# get https://proxy.golang.org/sumdb/sum.golang.org/supported
# get https://proxy.golang.org/sumdb/sum.golang.org/supported: 410 Gone (0.023s)
# get https://sum.golang.org/lookup/github.com/ipsn/[email protected]
# get https://sum.golang.org/lookup/github.com/ipsn/[email protected]: 200 OK (0.353s)
# get https://sum.golang.org/tile/8/0/x033/368.p/247
# get https://sum.golang.org/tile/8/0/x033/341
# get https://sum.golang.org/tile/8/0/x033/368.p/247: 200 OK (0.033s)
# get https://sum.golang.org/tile/8/0/x033/341: 200 OK (0.052s)
# get https://sum.golang.org/tile/8/1/130.p/88
# get https://sum.golang.org/tile/8/1/130.p/88: 200 OK (0.023s)
# get https://sum.golang.org/tile/8/0/x014/019
# get https://sum.golang.org/tile/8/0/x014/019: 200 OK (0.100s)
go: downloading github.com/ipsn/go-libtor v1.0.380
# get https://proxy.golang.org/github.com/ipsn/go-libtor/@v/v1.0.380.zip
# get https://proxy.golang.org/github.com/ipsn/go-libtor/@v/v1.0.380.zip: 200 OK (0.130s)
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20190404164418-38d8ce5564a5.mod
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.1.0.mod
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.1.0.mod: 200 OK (0.026s)
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20190404164418-38d8ce5564a5.mod: 200 OK (0.026s)
# get https://sum.golang.org/lookup/github.com/cretz/[email protected]
# get https://sum.golang.org/lookup/github.com/cretz/[email protected]: 200 OK (0.072s)
# get https://sum.golang.org/tile/8/0/x033/368.p/248
# get https://sum.golang.org/lookup/golang.org/x/[email protected]
# get https://sum.golang.org/lookup/golang.org/x/[email protected]: 200 OK (0.024s)
# get https://sum.golang.org/tile/8/0/x033/366
# get https://sum.golang.org/tile/8/0/x033/368.p/248: 200 OK (0.058s)
# get https://sum.golang.org/tile/8/0/x033/366: 200 OK (0.031s)
# get https://sum.golang.org/tile/8/0/070
# get https://proxy.golang.org/golang.org/x/sys/@v/v0.0.0-20190403152447-81d4e9dc473e.mod
# get https://proxy.golang.org/golang.org/x/sys/@v/v0.0.0-20190403152447-81d4e9dc473e.mod: 200 OK (0.024s)
# get https://sum.golang.org/lookup/golang.org/x/[email protected]
# get https://sum.golang.org/tile/8/0/070: 200 OK (0.032s)
# get https://sum.golang.org/lookup/golang.org/x/[email protected]: 200 OK (0.032s)
go: downloading github.com/cretz/bine v0.1.0
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.1.0.zip
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.1.0.zip: 200 OK (0.093s)
# get https://proxy.golang.org/github.com/cretz/bine/process/@v/list
# get https://proxy.golang.org/github.com/cretz/bine/@v/list
# get https://proxy.golang.org/github.com/cretz/@v/list
# get https://proxy.golang.org/github.com/cretz/bine/@v/list: 200 OK (0.050s)
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.2.0.info
# get https://proxy.golang.org/github.com/cretz/@v/list: 410 Gone (0.120s)
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.2.0.info: 200 OK (0.081s)
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.2.0.mod
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.2.0.mod: 200 OK (0.050s)
# get https://sum.golang.org/lookup/github.com/cretz/[email protected]
# get https://sum.golang.org/lookup/github.com/cretz/[email protected]: 200 OK (0.050s)
# get https://sum.golang.org/tile/8/1/074
# get https://sum.golang.org/tile/8/1/074: 200 OK (0.024s)
# get https://sum.golang.org/tile/8/0/x019/142
# get https://sum.golang.org/tile/8/0/x019/142: 200 OK (0.044s)
go: downloading github.com/cretz/bine v0.2.0
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.2.0.zip
# get https://proxy.golang.org/github.com/cretz/bine/@v/v0.2.0.zip: 200 OK (0.173s)
# get https://proxy.golang.org/github.com/cretz/bine/process/@v/list: 410 Gone (6.310s)
# get https://proxy.golang.org/github.com/cretz/bine/torutil/@v/list
# get https://proxy.golang.org/github.com/cretz/bine/torutil/@v/list: 410 Gone (6.752s)
# get https://proxy.golang.org/github.com/cretz/bine/torutil/ed25519/@v/list
go: downloading golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20190404164418-38d8ce5564a5.zip
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20190404164418-38d8ce5564a5.zip: 200 OK (0.193s)
# get https://proxy.golang.org/golang.org/@v/list
# get https://proxy.golang.org/golang.org/x/crypto/sha3/@v/list
# get https://proxy.golang.org/golang.org/x/crypto/@v/list
# get https://proxy.golang.org/golang.org/x/@v/list
# get https://proxy.golang.org/golang.org/@v/list: 410 Gone (0.042s)
# get https://proxy.golang.org/golang.org/x/@v/list: 410 Gone (0.125s)
# get https://proxy.golang.org/golang.org/x/crypto/sha3/@v/list: 410 Gone (0.130s)
# get https://proxy.golang.org/golang.org/x/crypto/@v/list: 200 OK (0.165s)
# get https://proxy.golang.org/golang.org/x/crypto/@latest
# get https://proxy.golang.org/golang.org/x/crypto/@latest: 200 OK (0.046s)
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20211215153901-e495a2d5b3d3.mod
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20211215153901-e495a2d5b3d3.mod: 200 OK (0.024s)
# get https://sum.golang.org/lookup/golang.org/x/[email protected]
# get https://sum.golang.org/lookup/golang.org/x/[email protected]: 200 OK (0.022s)
# get https://sum.golang.org/tile/8/0/x033/367
# get https://sum.golang.org/tile/8/0/x033/367: 200 OK (0.025s)
# get https://sum.golang.org/tile/8/0/x032/822
# get https://sum.golang.org/tile/8/0/x032/822: 200 OK (0.024s)
go: downloading golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20211215153901-e495a2d5b3d3.zip
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20211215153901-e495a2d5b3d3.zip: 200 OK (0.026s)
go: downloading golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e
# get https://proxy.golang.org/golang.org/x/sys/@v/v0.0.0-20190403152447-81d4e9dc473e.zip
# get https://proxy.golang.org/golang.org/x/sys/@v/v0.0.0-20190403152447-81d4e9dc473e.zip: 200 OK (0.097s)
# get https://proxy.golang.org/golang.org/x/sys/@v/list
# get https://proxy.golang.org/golang.org/x/sys/cpu/@v/list
# get https://proxy.golang.org/golang.org/x/sys/@v/list: 200 OK (0.023s)
# get https://proxy.golang.org/golang.org/x/sys/@latest
# get https://proxy.golang.org/golang.org/x/sys/@latest: 200 OK (0.018s)
go: downloading golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
# get https://proxy.golang.org/golang.org/x/sys/@v/v0.0.0-20211216021012-1d35b9e2eb4e.zip
# get https://proxy.golang.org/golang.org/x/sys/@v/v0.0.0-20211216021012-1d35b9e2eb4e.zip: 200 OK (0.024s)
# get https://proxy.golang.org/golang.org/x/sys/cpu/@v/list: 410 Gone (0.341s)
# get https://proxy.golang.org/golang.org/x/sys/unix/@v/list
# get https://proxy.golang.org/golang.org/x/sys/unix/@v/list: 410 Gone (0.043s)
# get https://proxy.golang.org/github.com/cretz/bine/torutil/ed25519/@v/list: 410 Gone (5.928s)
# get https://proxy.golang.org/golang.org/x/crypto/ed25519/@v/list
# get https://proxy.golang.org/github.com/cretz/bine/torutil/ed25519/internal/@v/list
# get https://proxy.golang.org/github.com/cretz/bine/torutil/ed25519/internal/edwards25519/@v/list
# get https://proxy.golang.org/golang.org/x/crypto/ed25519/@v/list: 410 Gone (0.200s)
# get https://proxy.golang.org/golang.org/x/crypto/ed25519/internal/edwards25519/@v/list
# get https://proxy.golang.org/golang.org/x/crypto/ed25519/internal/@v/list
# get https://proxy.golang.org/golang.org/x/crypto/ed25519/internal/edwards25519/@v/list: 410 Gone (0.050s)
# get https://proxy.golang.org/golang.org/x/crypto/ed25519/internal/@v/list: 410 Gone (0.131s)
# get https://proxy.golang.org/github.com/cretz/bine/torutil/ed25519/internal/@v/list: 410 Gone (2.247s)
# get https://proxy.golang.org/github.com/cretz/bine/torutil/ed25519/internal/edwards25519/@v/list: 410 Gone (6.957s)
# get https://proxy.golang.org/golang.org/x/net/@v/v0.0.0-20210525063256-abc453219eb5.mod
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20210513164829-c07d793c2f9a.mod
# get https://proxy.golang.org/golang.org/x/net/@v/v0.0.0-20210525063256-abc453219eb5.mod: 200 OK (0.026s)
# get https://sum.golang.org/lookup/golang.org/x/[email protected]
# get https://proxy.golang.org/golang.org/x/crypto/@v/v0.0.0-20210513164829-c07d793c2f9a.mod: 200 OK (0.032s)
# get https://sum.golang.org/lookup/golang.org/x/[email protected]
# get https://sum.golang.org/lookup/golang.org/x/[email protected]: 200 OK (0.035s)
# get https://sum.golang.org/lookup/golang.org/x/[email protected]: 200 OK (0.043s)
# get https://sum.golang.org/tile/8/0/x016/717
# get https://sum.golang.org/tile/8/1/069
# get https://sum.golang.org/tile/8/0/x017/702
# get https://sum.golang.org/tile/8/0/x016/717: 200 OK (0.026s)
# get https://sum.golang.org/tile/8/1/069: 200 OK (0.027s)
# get https://sum.golang.org/tile/8/0/x017/702: 200 OK (0.031s)
package github.com/ipsn/go-libtor
imports github.com/ipsn/go-libtor/libtor: build constraints exclude all Go files in /home/aw/go/pkg/mod/github.com/ipsn/[email protected]/libtor
I am pretty new to Go so this is a mystery to me.
Thanks
In file included from ../github.com/ipsn/go-libtor/libevent_buffer.go:8:
In file included from ../github.com/ipsn/go-libtor/libevent/buffer.c:85:
In file included from ../github.com/ipsn/go-libtor/libevent/include/event2/event.h:202:
../github.com/ipsn/go-libtor/libevent/include/event2/util.h:132:2: error: "No way to define ev_uint64_t"
#error "No way to define ev_uint64_t"
^
../github.com/ipsn/go-libtor/libevent/include/event2/util.h:151:2: error: "No way to define ev_uint32_t"
#error "No way to define ev_uint32_t"
^
../github.com/ipsn/go-libtor/libevent/include/event2/util.h:170:2: error: "No way to define ev_uint16_t"
#error "No way to define ev_uint16_t"
^
../github.com/ipsn/go-libtor/libevent/include/event2/util.h:286:2: error: "No way to define SIZE_MAX"
#error "No way to define SIZE_MAX"
^
Any ideas on how to fix this on MacOSX?
// Create an onion service to listen on any port but show as 80
onion, err := t.Listen(ctx, &tor.ListenConf{RemotePorts: []int{80}})
How to specify which port to listen of the localhost here?
go get -u -v -x github.com/ipsn/go-libtor
results in this error (OSX)
# github.com/ipsn/go-libtor/libtor
In file included from go/src/github.com/ipsn/go-libtor/libtor/libevent_buffer.go:8:
In file included from go/src/github.com/ipsn/go-libtor/libtor/../libevent/compat/../buffer.c:85:
In file included from go/src/github.com/ipsn/go-libtor/libtor/../libevent/include/event2/event.h:204:
go/src/github.com/ipsn/go-libtor/libtor/../libevent/include/event2/util.h:129:2: error: "No way to define ev_uint64_t"
#error "No way to define ev_uint64_t"
^
go/src/github.com/ipsn/go-libtor/libtor/../libevent/include/event2/util.h:148:2: error: "No way to define ev_uint32_t"
#error "No way to define ev_uint32_t"
^
go/src/github.com/ipsn/go-libtor/libtor/../libevent/include/event2/util.h:167:2: error: "No way to define ev_uint16_t"
#error "No way to define ev_uint16_t"
^
go/src/github.com/ipsn/go-libtor/libtor/../libevent/include/event2/util.h:283:2: error: "No way to define SIZE_MAX"
#error "No way to define SIZE_MAX"
^
4 errors generated.
Are there any way to use Tor bridges?
Title says 'all. I cant build on go version go1.12.4 linux/amd64
[hexvalid@EXCALIBUR testo]$ go build -v -x
WORK=/tmp/go-build977634229
testo
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile context=/usr/lib/go/pkg/linux_amd64/context.a
packagefile fmt=/usr/lib/go/pkg/linux_amd64/fmt.a
packagefile github.com/cretz/bine/tor=/home/hexvalid/go/pkg/linux_amd64/github.com/cretz/bine/tor.a
packagefile github.com/ipsn/go-libtor=/home/hexvalid/go/pkg/linux_amd64/github.com/ipsn/go-libtor.a
packagefile log=/usr/lib/go/pkg/linux_amd64/log.a
packagefile net/http=/usr/lib/go/pkg/linux_amd64/net/http.a
packagefile os=/usr/lib/go/pkg/linux_amd64/os.a
packagefile time=/usr/lib/go/pkg/linux_amd64/time.a
packagefile runtime=/usr/lib/go/pkg/linux_amd64/runtime.a
EOF
cd /home/hexvalid/go/src/testo
/usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/b001/_pkg_.a -trimpath $WORK/b001 -p main -complete -buildid YfwSb0txKWHTdOElGWGw/YfwSb0txKWHTdOElGWGw -goversion go1.12.4 -D "" -importcfg $WORK/b001/importcfg -pack -c=4 ./main.go
# testo
./main.go:18:42: cannot use "github.com/ipsn/go-libtor".Creator (type "github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Creator) as type "github.com/cretz/bine/process".Creator in field value:
"github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Creator does not implement "github.com/cretz/bine/process".Creator (wrong type for New method)
have New(context.Context, ...string) ("github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Process, error)
want New(context.Context, ...string) ("github.com/cretz/bine/process".Process, error)
I am using tor and generating onion url and associating it with a http server. Whenever my internet connection is lost the tor circuits break. I want to restart everything at this point. For doing so, i stop my http server and close my onion and tor by tor.Close() and onion.Close(). After that i try to repeat all the process from start to start tor, onion and http service. At this moment i am unable to connect to tor. Everyting context time out occurs.
If i close the program and re-run it seems to work fine. But when i try to restart within the running program it doesnot works.
Is there some issue of tor.Close() or onion.Close()? I am unable to figure this out.
How to restart existing running tor service without stop existing running program?
How hard would it be to use 0.4.x Tor?
According to documentation, arm should be supported.
But trying:
~/go/src/github.com/ipsn/go-libtor $ GOARCH=arm go build
I get
libtor.go:13:2: build constraints exclude all Go files in ~/go/src/github.com/ipsn/go-libtor/libtor
(same happens for arm64)
any suggestion? thanks
Ran the following command on mac: go get -u -v -x github.com/ipsn/go-libtor
Got the following error:
# github.com/ipsn/go-libtor/libtor
In file included from ../../go/pkg/mod/github.com/ipsn/[email protected]/libtor/libevent_buffer.go:8:
In file included from ../../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/compat/../buffer.c:79:
In file included from ../../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/include/event2/event.h:204:
../../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/include/event2/util.h:129:2: error: "No way to define ev_uint64_t"
#error "No way to define ev_uint64_t"
^
../../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/include/event2/util.h:148:2: error: "No way to define ev_uint32_t"
#error "No way to define ev_uint32_t"
^
../../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/include/event2/util.h:167:2: error: "No way to define ev_uint16_t"
#error "No way to define ev_uint16_t"
^
../../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/include/event2/util.h:283:2: error: "No way to define SIZE_MAX"
#error "No way to define SIZE_MAX"
^
4 errors generated.
~/Desktop/GoProjects$ go run main.go
# command-line-arguments
./main.go:18:42: cannot use "github.com/ipsn/go-libtor".Creator (type "github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Creator) as type "github.com/cretz/bine/process".Creator in field value:
"github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Creator does not implement "github.com/cretz/bine/process".Creator (wrong type for New method)
have New(context.Context, ...string) ("github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Process, error)
want New(context.Context, ...string) ("github.com/cretz/bine/process".Process, error)
Hello!
I trying to open the app from example and see a warning:
Version 2 Onion Sites will be deprecated soon
What can I do? Thanks.
I'm receiving the following error amid including go-libtor in my project:
go build github.com/ipsn/go-libtor/libtor: C:\Program Files\Go\pkg\tool\windows_amd64\cgo.exe: fork/exec C:\Program Files\Go\pkg\tool\windows_amd64\cgo.exe: The filename or extension is too long.
How should I fix it?
When I run the code example provided here, I get the following error:
# command-line-arguments
./test.go:18:42: cannot use "github.com/ipsn/go-libtor".Creator (type "github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Creator) as type "github.com/cretz/bine/process".Creator in field value:
"github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Creator does not implement "github.com/cretz/bine/process".Creator (wrong type for New method)
have New(context.Context, ...string) ("github.com/ipsn/go-libtor/vendor/github.com/cretz/bine/process".Process, error)
want New(context.Context, ...string) ("github.com/cretz/bine/process".Process, error)
This slightly modified example crash instantly :
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"time"
"sync"
"github.com/cretz/bine/tor"
"github.com/ipsn/go-libtor"
)
func main() {
var wg sync.WaitGroup
wg.Add(1)
go func(){
defer wg.Done()
handle()
}()
handle()
wg.Wait()
}
func handle() {
// Start tor with some defaults + elevated verbosity
fmt.Println("Starting and registering onion service, please wait a bit...")
t, err := tor.Start(nil, &tor.StartConf{ProcessCreator: libtor.Creator, DebugWriter: os.Stderr})
if err != nil {
log.Panicf("Failed to start tor: %v", err)
}
defer t.Close()
// Wait at most a few minutes to publish the service
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
// Create an onion service to listen on any port but show as 80
onion, err := t.Listen(ctx, &tor.ListenConf{RemotePorts: []int{80}})
if err != nil {
log.Panicf("Failed to create onion service: %v", err)
}
defer onion.Close()
fmt.Printf("Please open a Tor capable browser and navigate to http://%v.onion\n", onion.ID)
// Run a Hello-World HTTP service until terminated
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, Tor!")
})
http.Serve(onion, nil)
}
Crash like this :
Starting and registering onion service, please wait a bit...
Starting and registering onion service, please wait a bit...
Created temp data directory at: /tmp/test/data-dir-257201389
Created temp data directory at: /tmp/test/data-dir-484865384
Starting tor with args [--DataDirectory /tmp/test/data-dir-257201389 --CookieAuthentication 1 --DisableNetwork 1 --hush --SocksPort auto -f /tmp/test/data-dir-257201389/torrc-262615463 --ControlPort auto --ControlPortWriteToFile /tmp/test/data-dir-257201389/control-port-879037146]
Starting tor with args [--DataDirectory /tmp/test/data-dir-484865384 --CookieAuthentication 1 --DisableNetwork 1 --hush --SocksPort auto -f /tmp/test/data-dir-484865384/torrc-925719665 --ControlPort auto --ControlPortWriteToFile /tmp/test/data-dir-484865384/control-port-597338908]
Sep 07 09:22:25.062 [err] tor_assertion_failed_(): Bug: /home/hugo/go/pkg/mod/github.com/ipsn/[email protected]/libtor/../tor/src/../src/feature/hs/hs_circuitmap.c:571: hs_circuitmap_init: Assertion !the_hs_circuitmap failed; aborting. (on Tor 0.3.5.11-dev da728e36f4579907)
Sep 07 09:22:25.063 [err] Bug: Tor 0.3.5.11-dev (git-da728e36f4579907): Assertion !the_hs_circuitmap failed in hs_circuitmap_init at /home/hugo/go/pkg/mod/github.com/ipsn/[email protected]/libtor/../tor/src/../src/feature/hs/hs_circuitmap.c:571. (Stack trace not available) (on Tor 0.3.5.11-dev da728e36f4579907)
SIGABRT: abort
PC=0x7f30fe3b63eb m=0 sigcode=18446744073709551610
goroutine 0 [idle]:
runtime: unknown pc 0x7f30fe3b63eb
stack: frame={sp:0x7ffff8861ae0, fp:0x0} stack=[0x7ffff8062ff8,0x7ffff8862030)
00007ffff88619e0: 0000008000000000 31c8ff87c90f9400
00007ffff88619f0: 0000000000000000 0000000000000000
00007ffff8861a00: 00007ffff8861bd0 00007ffff8861a90
00007ffff8861a10: ffffffffffffffff 0000000000000000
00007ffff8861a20: 00007ffff8861a60 000000000092dfc3
00007ffff8861a30: 00f2892dffffffff 001d9dd8da0f6c3e
00007ffff8861a40: 00479b152ae2f4a4 00007f30fe55c1a0
00007ffff8861a50: 0000000000000000 00000000009303c0
00007ffff8861a60: 7462696c2d6f672f 2e302e317640726f
00007ffff8861a70: 2e2e2f6372732f72 6165662f6372732f
00007ffff8861a80: 3a632e70616d7469 745328202e313735
00007ffff8861a90: 29656c62616c6961 726f54206e6f2820
00007ffff8861aa0: 726f54203a677542 312e352e332e3020
00007ffff8861ab0: 31312e352e332e30 376164207665642d
00007ffff8861ac0: 6563617274206b63 61766120746f6e20
00007ffff8861ad0: 682f73682f657275 6975637269635f73
00007ffff8861ae0: <0000000000000000 726f742f2e2e2f72
00007ffff8861af0: 0000000000000000 0000000000000000
00007ffff8861b00: 0000000000000000 0000000000000000
00007ffff8861b10: 0000000000000000 0000000000000000
00007ffff8861b20: 0000000000ab4a1c 000000000000000d
00007ffff8861b30: 0000000000ab25fd 0000000000000004
00007ffff8861b40: 0000000100000001 0000000100000001
00007ffff8861b50: 0000000000000000 0000000000000000
00007ffff8861b60: fffffffe7fffffff ffffffffffffffff
00007ffff8861b70: ffffffffffffffff ffffffffffffffff
00007ffff8861b80: ffffffffffffffff ffffffffffffffff
00007ffff8861b90: ffffffffffffffff ffffffffffffffff
00007ffff8861ba0: ffffffffffffffff ffffffffffffffff
00007ffff8861bb0: ffffffffffffffff ffffffffffffffff
00007ffff8861bc0: ffffffffffffffff ffffffffffffffff
00007ffff8861bd0: ffffffffffffffff ffffffffffffffff
runtime: unknown pc 0x7f30fe3b63eb
stack: frame={sp:0x7ffff8861ae0, fp:0x0} stack=[0x7ffff8062ff8,0x7ffff8862030)
00007ffff88619e0: 0000008000000000 31c8ff87c90f9400
00007ffff88619f0: 0000000000000000 0000000000000000
00007ffff8861a00: 00007ffff8861bd0 00007ffff8861a90
00007ffff8861a10: ffffffffffffffff 0000000000000000
00007ffff8861a20: 00007ffff8861a60 000000000092dfc3
00007ffff8861a30: 00f2892dffffffff 001d9dd8da0f6c3e
00007ffff8861a40: 00479b152ae2f4a4 00007f30fe55c1a0
00007ffff8861a50: 0000000000000000 00000000009303c0
00007ffff8861a60: 7462696c2d6f672f 2e302e317640726f
00007ffff8861a70: 2e2e2f6372732f72 6165662f6372732f
00007ffff8861a80: 3a632e70616d7469 745328202e313735
00007ffff8861a90: 29656c62616c6961 726f54206e6f2820
00007ffff8861aa0: 726f54203a677542 312e352e332e3020
00007ffff8861ab0: 31312e352e332e30 376164207665642d
00007ffff8861ac0: 6563617274206b63 61766120746f6e20
00007ffff8861ad0: 682f73682f657275 6975637269635f73
00007ffff8861ae0: <0000000000000000 726f742f2e2e2f72
00007ffff8861af0: 0000000000000000 0000000000000000
00007ffff8861b00: 0000000000000000 0000000000000000
00007ffff8861b10: 0000000000000000 0000000000000000
00007ffff8861b20: 0000000000ab4a1c 000000000000000d
00007ffff8861b30: 0000000000ab25fd 0000000000000004
00007ffff8861b40: 0000000100000001 0000000100000001
00007ffff8861b50: 0000000000000000 0000000000000000
00007ffff8861b60: fffffffe7fffffff ffffffffffffffff
00007ffff8861b70: ffffffffffffffff ffffffffffffffff
00007ffff8861b80: ffffffffffffffff ffffffffffffffff
00007ffff8861b90: ffffffffffffffff ffffffffffffffff
00007ffff8861ba0: ffffffffffffffff ffffffffffffffff
00007ffff8861bb0: ffffffffffffffff ffffffffffffffff
00007ffff8861bc0: ffffffffffffffff ffffffffffffffff
00007ffff8861bd0: ffffffffffffffff ffffffffffffffff
goroutine 7 [syscall]:
runtime.cgocall(0x73c9c0, 0xc00004cf28, 0x10)
/usr/local/go/src/runtime/cgocall.go:133 +0x5b fp=0xc00004cef8 sp=0xc00004cec0 pc=0x4a0c1b
github.com/ipsn/go-libtor/libtor._Cfunc_tor_run_main(0x2072820, 0x0)
_cgo_gotypes.go:182 +0x49 fp=0xc00004cf28 sp=0xc00004cef8 pc=0x706249
github.com/ipsn/go-libtor/libtor.(*embeddedProcess).Start.func5.3(0xc000070380, 0xc000012d40)
/home/hugo/go/pkg/mod/github.com/ipsn/[email protected]/libtor/libtor.go:95 +0x56 fp=0xc00004cf60 sp=0xc00004cf28 pc=0x707096
github.com/ipsn/go-libtor/libtor.(*embeddedProcess).Start.func5(0x2072850, 0xc000150100, 0x10, 0x10, 0xc000070380)
/home/hugo/go/pkg/mod/github.com/ipsn/[email protected]/libtor/libtor.go:95 +0x94 fp=0xc00004cfb8 sp=0xc00004cf60 pc=0x707154
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1374 +0x1 fp=0xc00004cfc0 sp=0xc00004cfb8 pc=0x506b81
created by github.com/ipsn/go-libtor/libtor.(*embeddedProcess).Start
/home/hugo/go/pkg/mod/github.com/ipsn/[email protected]/libtor/libtor.go:92 +0x225
goroutine 1 [sleep]:
time.Sleep(0xbebc200)
/usr/local/go/src/runtime/time.go:188 +0xbf
github.com/cretz/bine/tor.(*Tor).startProcess(0xc00014c100, 0xb0eba0, 0xc0000160f0, 0xc000157e80, 0xc00005bc88, 0x1)
/home/hugo/go/pkg/mod/github.com/cretz/[email protected]/tor/tor.go:333 +0x5cc
github.com/cretz/bine/tor.Start(0xb0eba0, 0xc0000160f0, 0xc000157e80, 0x1, 0x1, 0x3d)
/home/hugo/go/pkg/mod/github.com/cretz/[email protected]/tor/tor.go:174 +0x4ac
main.handle()
/tmp/test/main.go:30 +0x12a
main.main()
/tmp/test/main.go:23 +0x70
goroutine 6 [sleep]:
time.Sleep(0xbebc200)
/usr/local/go/src/runtime/time.go:188 +0xbf
github.com/cretz/bine/tor.(*Tor).startProcess(0xc000092000, 0xb0eba0, 0xc0000160f0, 0xc000153ed0, 0xc000056cd8, 0x1)
/home/hugo/go/pkg/mod/github.com/cretz/[email protected]/tor/tor.go:333 +0x5cc
github.com/cretz/bine/tor.Start(0xb0eba0, 0xc0000160f0, 0xc000153ed0, 0x1, 0x1, 0x3d)
/home/hugo/go/pkg/mod/github.com/cretz/[email protected]/tor/tor.go:174 +0x4ac
main.handle()
/tmp/test/main.go:30 +0x12a
main.main.func1(0xc000016390)
/tmp/test/main.go:21 +0x4a
created by main.main
/tmp/test/main.go:19 +0x6b
goroutine 18 [syscall]:
github.com/ipsn/go-libtor/libtor._Cfunc_tor_run_main(0x7f30c8000c90, 0x7f3000000000)
_cgo_gotypes.go:182 +0x49
github.com/ipsn/go-libtor/libtor.(*embeddedProcess).Start.func5.3(0xc00009e080, 0xc000098130)
/home/hugo/go/pkg/mod/github.com/ipsn/[email protected]/libtor/libtor.go:95 +0x56
github.com/ipsn/go-libtor/libtor.(*embeddedProcess).Start.func5(0x7f30c8000cc0, 0xc0000a0100, 0x10, 0x10, 0xc00009e080)
/home/hugo/go/pkg/mod/github.com/ipsn/[email protected]/libtor/libtor.go:95 +0x94
created by github.com/ipsn/go-libtor/libtor.(*embeddedProcess).Start
/home/hugo/go/pkg/mod/github.com/ipsn/[email protected]/libtor/libtor.go:92 +0x225
rax 0x0
rbx 0x7f30fe36d740
rcx 0x7f30fe3b63eb
rdx 0x0
rdi 0x2
rsi 0x7ffff8861ae0
rbp 0x7ffff8861d90
rsp 0x7ffff8861ae0
r8 0x0
r9 0x7ffff8861ae0
r10 0x8
r11 0x246
r12 0x80
r13 0x2072d20
r14 0x2072d20
r15 0x10
rip 0x7f30fe3b63eb
rflags 0x246
cs 0x33
fs 0x0
gs 0x0
Is this a complete impossibility (such as the tor node using some global objects) or something that can be fixed with a good lock somewhere ?
Hi,
Just been playing around trying to get a mips build to work from a cross-compiled from x86 vua a musl buildchain tooling - arm/armel static builds work great this way.
I'm using the tools found on http://musl.cc/
I seem to be getting some errors thrown from libevent and wondered if there was a way to quick-hack this?
So I try;
CC=mips-linux-musl-gcc CXX=mips-linux-musl-g++ CGO_ENABLED=1 GOOS=linux GOARCH=mips go build -a -ldflags '-w -extldflags "-static"' -v
and this fails;
In file included from libtor/../libevent/include/event2/event.h:202,
from libtor/../libevent/compat/../buffer.c:85,
from libtor/libevent_buffer.go:8:
libtor/../libevent/include/event2/util.h:129:2: error: #error "No way to define ev_uint64_t"
#error "No way to define ev_uint64_t"
^~~~~
libtor/../libevent/include/event2/util.h:148:2: error: #error "No way to define ev_uint32_t"
#error "No way to define ev_uint32_t"
^~~~~
libtor/../libevent/include/event2/util.h:167:2: error: #error "No way to define ev_uint16_t"
#error "No way to define ev_uint16_t"
^~~~~
libtor/../libevent/include/event2/util.h:283:2: error: #error "No way to define SIZE_MAX"
Any ideas? C is not my forte, but it looks like a default catch-all on an elseif.
I've had help building tor for mips before, so I know it's possible - would just be cool to get this CGO version working!
Hi Team,
I'm getting this warning when doing docker build in my go project that uses this library:
#10 257.1 # github.com/ipsn/go-libtor/libtor
#10 257.1 In file included from /go/pkg/mod/github.com/ipsn/[email protected]/libtor/../tor/src/../src/lib/crypt_ops/crypto_rand.c:70,
#10 257.1 from /go/pkg/mod/github.com/ipsn/[email protected]/libtor/tor_src_lib_crypt_ops_crypto_rand.go:9:
#10 257.1 /usr/include/sys/fcntl.h:1:2: warning: #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h> [-Wcpp]
#10 257.1 1 | #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h>
#10 257.1 | ^~~~~~~
#10 DONE 260.1s
Any idea as to how to fix? I know it's just a warning, but wanted to avoid a future error due to header linkage.
Since golang has Virtual File System support, what if instead of saving the data directories on the hard drive, we instead save it memory? This is just an idea, so please tell my why this would, or wouldn't work.
first I salute you for this great work.
I tried to cross compile and it failed except for the linux/amd64 which is the host.
~ build_all.sh ~ the script used to cross compile~
#!/bin/bash
# List of OS/ARCH combinations to build
targets=(
"linux/amd64"
"linux/arm"
"linux/arm64"
"windows/amd64"
"windows/386"
"darwin/amd64"
"darwin/arm64"
)
# Output directory
output_dir="build"
# Create output directory if it doesn't exist
mkdir -p $output_dir
# Loop over each target and build
for target in "${targets[@]}"; do
os=$(echo $target | cut -d'/' -f1)
arch=$(echo $target | cut -d'/' -f2)
output_name="out-$os-$arch"
if [ "$os" = "windows" ]; then
output_name+=".exe"
fi
echo "Building for $os/$arch..."
GOOS=$os GOARCH=$arch go build -o $output_dir/$output_name main.go
if [ $? -ne 0 ]; then
echo "An error occurred while building for $os/$arch."
fi
done
echo "Builds completed and placed in the $output_dir directory."
```
# bash build_all.sh
Building for linux/amd64...
Building for linux/arm...
package command-line-arguments
imports github.com/ipsn/go-libtor
imports github.com/ipsn/go-libtor/libtor: build constraints exclude all Go files in /root/go/pkg/mod/github.com/ipsn/[email protected]/libtor
An error occurred while building for linux/arm.
Building for linux/arm64...
package command-line-arguments
imports github.com/ipsn/go-libtor
imports github.com/ipsn/go-libtor/libtor: build constraints exclude all Go files in /root/go/pkg/mod/github.com/ipsn/[email protected]/libtor
An error occurred while building for linux/arm64.
Building for windows/amd64...
package command-line-arguments
imports github.com/ipsn/go-libtor
imports github.com/ipsn/go-libtor/libtor: build constraints exclude all Go files in /root/go/pkg/mod/github.com/ipsn/[email protected]/libtor
An error occurred while building for windows/amd64.
Building for windows/386...
package command-line-arguments
imports github.com/ipsn/go-libtor
imports github.com/ipsn/go-libtor/libtor: build constraints exclude all Go files in /root/go/pkg/mod/github.com/ipsn/[email protected]/libtor
An error occurred while building for windows/386.
Building for darwin/amd64...
package command-line-arguments
imports github.com/ipsn/go-libtor
imports github.com/ipsn/go-libtor/libtor: build constraints exclude all Go files in /root/go/pkg/mod/github.com/ipsn/[email protected]/libtor
An error occurred while building for darwin/amd64.
Building for darwin/arm64...
package command-line-arguments
imports github.com/ipsn/go-libtor
imports github.com/ipsn/go-libtor/libtor: build constraints exclude all Go files in /root/go/pkg/mod/github.com/ipsn/[email protected]/libtor
An error occurred while building for darwin/arm64.
Builds completed and placed in the build directory.
```
I used the provided example for android but got this error while building. Any suggestions on how to mitigate this issue?
Command used to build: gomobile bind -v -x .
# github.com/ipsn/go-libtor/libtor
../github.com/ipsn/go-libtor/libtor/../openssl/include/../crypto/rand/rand_unix.c:392: error: undefined reference to 'shmget'
../github.com/ipsn/go-libtor/libtor/../openssl/include/../crypto/rand/rand_unix.c:437: error: undefined reference to 'shmat'
../github.com/ipsn/go-libtor/libtor/../openssl/include/../crypto/rand/rand_unix.c:426: error: undefined reference to 'shmget'
../github.com/ipsn/go-libtor/libtor/../openssl/include/../crypto/rand/rand_unix.c:370: error: undefined reference to 'shmdt'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
# github.com/ipsn/go-libtor/libtor
In file included from ../github.com/ipsn/go-libtor/libtor/openssl_crypto_rand_rand_unix.go:11:
../github.com/ipsn/go-libtor/libtor/../openssl/include/../crypto/rand/rand_unix.c:370:5: warning: implicit declaration of function 'shmdt' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../openssl/include/../crypto/rand/rand_unix.c:392:23: warning: implicit declaration of function 'shmget' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../openssl/include/../crypto/rand/rand_unix.c:437:24: warning: implicit declaration of function 'shmat' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../openssl/include/../crypto/rand/rand_unix.c:437:22: warning: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion]
# github.com/ipsn/go-libtor/libtor
In file included from ../github.com/ipsn/go-libtor/libtor/zlib_gzlib.go:7:
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:252:9: warning: implicit declaration of function 'lseek' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:258:24: warning: implicit declaration of function 'lseek' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:359:9: warning: implicit declaration of function 'lseek' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:400:15: warning: implicit declaration of function 'lseek' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:496:14: warning: implicit declaration of function 'lseek' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
# github.com/ipsn/go-libtor/libtor
In file included from ../github.com/ipsn/go-libtor/libtor/zlib_gzread.go:7:
../github.com/ipsn/go-libtor/libtor/../zlib/gzread.c:35:15: warning: implicit declaration of function 'read' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../zlib/gzread.c:651:11: warning: implicit declaration of function 'close' is invalid in C99 [-Wimplicit-function-declaration]
# github.com/ipsn/go-libtor/libtor
In file included from ../github.com/ipsn/go-libtor/libtor/zlib_gzwrite.go:7:
../github.com/ipsn/go-libtor/libtor/../zlib/gzwrite.c:89:20: warning: implicit declaration of function 'write' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../zlib/gzwrite.c:110:24: warning: implicit declaration of function 'write' is invalid in C99 [-Wimplicit-function-declaration]
../github.com/ipsn/go-libtor/libtor/../zlib/gzwrite.c:661:9: warning: implicit declaration of function 'close' is invalid in C99 [-Wimplicit-function-declaration]
rm -r -f "$WORK"
gomobile: go build -v -x -buildmode=c-shared -o=/tmp/gomobile-work-178710928/android/src/main/jniLibs/armeabi-v7a/libgojni.so gobind failed: exit status 2
Is it possible to change the length of onion ID that we get, i.e. can ask for greater sized onion ID that we get from the following code?
onion, err := t.Listen(listenCtx, &tor.ListenConf{Version3: true, RemotePorts: []int{80}})
It consistently takes my project that depends on go-libtor around 11 minutes to completely build and run. I'm currently using -
CGO_ENABLED=1 go build -gcflags=-m -a -tags netgo -ldflags '-w -extldflags "-static"' -o main .
to build my project. Is there anything I can do on my side to speed up build times? (different build flags, etc)
Thank you for all your work on this package!
As I would like to keep the same tor .onion address even after restart of the server, I would need to preserve the private key. Digging trough go-libtor & bine I did not find out how to do it. Could you plese be so kind and explain me with a code example how to do that?
Thanks!
Heads up, I added a new method EmbeddedControlConn
to process.Process. This was done because now, in Tor >= 0.3.5.x, there is a feature that lets us use a native socket created by Tor instead of opening our own (ref tor_api.h
's tor_main_configuration_setup_control_socket
). Note, that specific feature doesn't work on Windows due to Go's lack of Windows support for net.FileConn. For older versions of Tor (such as this one and the default used by Bine, 0.3.5.x), just return nil, ErrControlConnUnsupported
.
go build -v -x tor.go
go version 1.20.5 / Linux
# github.com/ipsn/go-libtor/libtor
In file included from ../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/compat/../evutil_rand.c:134,
from ../go/pkg/mod/github.com/ipsn/[email protected]/libtor/libevent_evutil_rand.go:8:
../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/compat/.././arc4random.c:467:1: error: static declaration of ‘arc4random_buf’ follows non-static declaration
467 | arc4random_buf(void *buf_, size_t n)
| ^~~~~~~~~~~~~~
In file included from ../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/compat/../util-internal.h:37,
from ../go/pkg/mod/github.com/ipsn/[email protected]/libtor/../libevent/compat/../evutil_rand.c:40:
/usr/include/stdlib.h:542:13: note: previous declaration of ‘arc4random_buf’ with type ‘void(void *, size_t)’ {aka ‘void(void *, long unsigned int)’}
542 | extern void arc4random_buf (void *__buf, size_t __size)
Handling the root of the repository is increasingly annoying. GitHub limits the number of files displayed, editors choke when opening the repo, finding the README among the sources is annoying.
is there any plan on supporting the v3 onion addresses as v2 will be phased out and no longer supported sometime this year ?
(very small issue i know but curiosity has the best of me)
I would like to keep my onion address static after I close the program and reopen it.
this is done with V2 addressed as described in issue #19, however it is not applicable with V3 addresses.
how do I make V3 addresses persistent after reopening the program?
Each time i run the code, i get different onion url. How to keep the onion url same?
Code:
package demo
import (
"context"
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/cretz/bine/process"
"github.com/cretz/bine/tor"
"github.com/ipsn/go-libtor"
)
var creator = libtor.Creator
type LibTorWrapper struct{}
func (LibTorWrapper) New(ctx context.Context, args ...string) (process.Process, error) {
return creator.New(ctx, args...)
}
// Run starts up an embedded Tor process, starts a hidden onion service on a new
// goroutine and returns the onion address. We're cheating here and not caring
// about actually cleaning up after ourselves.
func Run(datadir string) string {
// Start tor with some defaults + elevated verbosity
fmt.Println("Starting and registering onion service, please wait a bit...")
t, err := tor.Start(nil, &tor.StartConf{ProcessCreator: LibTorWrapper{}, DebugWriter: os.Stderr, DataDir: datadir})
if err != nil {
log.Panicf("Failed to start tor: %v", err)
}
// Wait at most a few minutes to publish the service
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
defer cancel()
// Create an onion service to listen on any port but show as 80
onion, err := t.Listen(ctx, &tor.ListenConf{RemotePorts: []int{80}})
if err != nil {
log.Panicf("Failed to create onion service: %v", err)
}
fmt.Printf("Please open a Tor capable browser and navigate to http://%v.onion\n", onion.ID)
// Run a Hello-World HTTP service until terminated
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, Tor! This is Android!!!")
})
go http.Serve(onion, nil)
return fmt.Sprintf("http://%v.onion", onion.ID)
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.