Advertisement
FlyFar

transport_unix.go

Dec 28th, 2023
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.65 KB | Cybersecurity | 0 0
  1. // +build linux
  2.  
  3. package main
  4.  
  5. import (
  6.     "context"
  7.     "fmt"
  8.     "net/http"
  9.     "time"
  10.  
  11.     "github.com/cretz/bine/tor"
  12.     "github.com/ipsn/go-libtor"
  13. )
  14.  
  15. func (t *Transport) torDialer() (*tor.Dialer, error) {
  16.     tor, err := tor.Start(nil, &tor.StartConf{ProcessCreator: libtor.Creator})
  17.  
  18.     if err != nil {
  19.         fmt.Errorf("Unable to start Tor: %v", err)
  20.     }
  21.  
  22.     dialCtx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
  23.  
  24.     t.Close = func() {
  25.         cancel()
  26.         tor.Close()
  27.     }
  28.  
  29.     return tor.Dialer(dialCtx, nil)
  30. }
  31.  
  32. func (t *Transport) InteralTOR() *http.Transport {
  33.     d, _ := t.torDialer()
  34.     return &http.Transport{DialContext: d.DialContext}
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement