profile
viewpoint

Ask questionsSegmentation fault when running example client on linux

linux 4.19, tor 0.4.0.5. I was trying to run the example client code to create communicating hidden services, but i couldn't get the example code to run on my manjaro linux.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x63cf53]

goroutine 24 [running]:
golang.org/x/net/proxy.(*socks5).Dial(0xc00009ec30, 0x6f2455, 0x3, 0xc0000966a0, 0xf, 0xf, 0x0, 0x28a, 0x0)
	/home/h/go/src/golang.org/x/net/proxy/socks5.go:71 +0x63
github.com/cretz/bine/tor.(*Dialer).DialContext.func1(0xc000085180, 0x6f2455, 0x3, 0xc0000966a0, 0xf, 0xc00009aa80, 0x754200, 0xc000096010, 0xc00009aae0)
	/home/h/go/src/github.com/cretz/bine/tor/dialer.go:95 +0x7e
created by github.com/cretz/bine/tor.(*Dialer).DialContext
	/home/h/go/src/github.com/cretz/bine/tor/dialer.go:94 +0xfa
exit status 2

the code was:

package main

import (
	"context"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"time"

	"github.com/cretz/bine/tor"
)

func main() {
	if err := run(); err != nil {
		log.Fatal(err)
	}
}

func run() error {
	// Start tor with default config (can set start conf's DebugWriter to os.Stdout for debug logs)
	fmt.Println("Starting tor and fetching title of https://eludemaillhqfkh5.onion, please wait a few seconds...")
	t, err := tor.Start(nil, nil)
	if err != nil {
		return err
	}
	defer t.Close()
	// Wait at most a minute to start network and get
	dialCtx, dialCancel := context.WithTimeout(context.Background(), time.Minute)
	defer dialCancel()
	// Make connection
	dialer, err := t.Dialer(dialCtx, nil)
	if err != nil {
		return err
	}
	httpClient := &http.Client{Transport: &http.Transport{DialContext: dialer.DialContext}}
	// Get /
	resp, err := httpClient.Get("https://example.com")
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if err != nil {
		return err
	}
	bodyBytes, err := ioutil.ReadAll(resp.Body)
	fmt.Println(string(bodyBytes))
	return nil
}

A slight variation on the example client.

cretz/bine

Answer questions cretz

Closing old issue. Let mw know if this issue persists.

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List