Documentation
¶
Overview ¶
Package tornado provides support for an easy launch of tor proxy on golang.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextDialer ¶
type ContextDialer interface { // DialContext connects to the address on the named network using // the provided context. DialContext(ctx context.Context, network, address string) (net.Conn, error) }
A ContextDialer dials using a context.
type FloatingProxy ¶
type FloatingProxy struct {
// contains filtered or unexported fields
}
A FloatingProxy is an abstraction for making it easy to create connections through different proxies but within the same instance of the dial function.
But do not forget that different implementations of clients for network interaction can keep the connection open for different requests while using one common Proxy chain, for example http.Client with http.DefaultTransport.
func NewFloatingProxy ¶
func NewFloatingProxy(pool *Pool) *FloatingProxy
NewFloatingProxy creates new instance of FloatingProxy.
func (*FloatingProxy) Dial ¶
func (p *FloatingProxy) Dial(network, address string) (c net.Conn, err error)
Dial connects to the address on the named network.
Dial uses context.Background internally; to specify the context, use DialContext.
See func Dial of the net package of standard library for a description of the network and address parameters.
func (*FloatingProxy) DialContext ¶
DialContext connects to the address on the named network using the provided context.
See func Dial of the net package of standard library for a description of the network and address parameters.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is an abstraction on the options.
func WithForwardContextDialer ¶
func WithForwardContextDialer(dialer ContextDialer) Option
WithForwardContextDialer allows to specify the optional dial function for establishing the transport connection.
func WithTorrcOption ¶
WithTorrcOption allows adding arbitrary parameters to torrc.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
A Pool is an abstraction for creating multiple proxy instances using a single tor process to reduce resource usage.
Also, Pool provides a minimal interface for managing a set of proxies and their reuse.
func NewPool ¶
NewPool creates new instance of proxy Pool.
Pool must be closed wia using Close method after end usage to prevent memory leak and tor demon process leak, but keep in mind that all proxies will stop working immediately after the Pool is closed.
func (*Pool) Close ¶
Close stops the tor demon running in the background.
This operation will not wait for active connections to close, they will be aborted.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy returns a ContextDialer that makes connections to the given address over tor network.
func NewProxy ¶
NewProxy creates new instance of Proxy.
If the Proxy was created using NewProxy, it must be closed wia using Close method after end usage to prevent memory leak and tor demon process leak.
Example ¶
package main import ( "context" "log" "net/http" "net/http/httputil" "time" "github.com/xorcare/tornado" ) func main() { const proxyServerStartupTimeout = 15 * time.Second ctx, done := context.WithTimeout(context.Background(), proxyServerStartupTimeout) defer done() prx, err := tornado.NewProxy(ctx) if err != nil { log.Panicln("failed to create new instance of proxy:", err) } // After usage Proxy must be closed to prevent memory leak and tor // demon process leak. defer prx.Close() httpcli := &http.Client{ Transport: &http.Transport{ DialContext: prx.DialContext, }, Timeout: time.Second * 15, } resp, err := httpcli.Get("https://check.torproject.org/api/ip") if err != nil { log.Panicln("failed to execute http request to tor project api:", err) } text, err := httputil.DumpResponse(resp, true) if err != nil { log.Panicln("failed to dump full response info:", err) } log.Println(string(text)) }
Output:
func (*Proxy) Close ¶
Close stops the tor demon running in the background. If the Proxy was created using NewPool directly instead of NewProxy, Close has no effect.
This operation will not wait for active connections to close, they will be aborted.
func (*Proxy) Dial ¶
Dial connects to the address on the named network over tor network.
See func Dial of the net package of standard library for a description of the network and address parameters.
Dial uses context.Background internally; to specify the context, use DialContext.
func (*Proxy) DialContext ¶
DialContext connects to the address on the named network over tor network using the provided context.
The provided Context must be non-nil. If the context expires before the connection is complete, an error is returned. Once successfully connected, any expiration of the context will not affect the connection.
See func Dial of the net package of standard library for a description of the network and address parameters.