pipe2socks

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2025 License: MIT Imports: 10 Imported by: 2

Documentation

Overview

Package pipe2socks implements a pipe to route IP packets stream from io.ReadWriteCloser to socks proxy and back. You need a configured socks5 proxy address for the Copy function.

Basically it is a broad implementation of tun2socks. And yes, io.ReadWriteCloser could be a TUN device.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOpts = &Opts{
	MTU:        1500,
	UDP:        true,
	UDPTimeout: 30 * time.Second,
}

DefaultOpts represent the default connection settings suitable for most cases.

Functions

func Copy

func Copy(ctx context.Context, pipe io.ReadWriteCloser, socks5 string, options *Opts) error

Copy is a one-function version of Pipe.Copy().

Types

type Opts

type Opts struct {
	MTU        int  // MTU should be set according to your configuration to prevent data losses.
	UDP        bool // UDP enables UDP support. Recommended to be turned on.
	UDPTimeout time.Duration
}

Opts contain options for the established connection between pipe and Socks server. DefaultOpts should be used for most cases.

type Pipe

type Pipe struct {
	// contains filtered or unexported fields
}

Pipe represents a pipe that connects io.ReadWriteCloser and sock5 proxy.

func NewPipe

func NewPipe(opts *Opts) (*Pipe, error)

func (*Pipe) Copy

func (p *Pipe) Copy(ctx context.Context, pipe io.ReadWriteCloser, socks5 string) error

Copy connects io.ReadWriteCloser to socks5 server.

It reads IP packets from pipe and routes them to socks5 and back. This function blocks for the duration of the whole transmission, and it is recommended to gracefully unlock it (ending the established connection) by cancelling the ctx.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL