tunnel

package
v0.0.0-...-72292b6 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tunnel

func Tunnel(option Option)
Example
package main

import (
	"fmt"
	"net"
	"time"

	"github.com/penndev/socks5/core/tunnel"
)

func main() {
	remoteConn, err := net.Dial("tcp", "www.baidu.com:80")
	if err != nil {
		panic(err)
	}

	lr, lw := net.Pipe()

	go tunnel.Tunnel(tunnel.Option{
		Src:     remoteConn,
		Dst:     lw,
		BufLen:  1024,
		Timeout: 10 * time.Second,
	})

	if _, err = lr.Write([]byte("get / \r\n")); err != nil {
		panic(err)
	}
	buf := make([]byte, 1024)
	n, err := lr.Read(buf)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(buf[:n]))
}
Output:

HTTP/1.1 400 Bad Request

Types

type Option

type Option struct {
	Src        net.Conn
	SrcReadLen func(int)
	Dst        net.Conn
	DstReadLen func(int)
	BufLen     int
	Timeout    time.Duration
}

Jump to

Keyboard shortcuts

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