proxyrelay

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package proxyrelay implements both components of the relayed SOCKS5 proxy.

Index

Constants

View Source
const (
	// TypeError signifies an error event with the error message stored in the Data attribute.
	TypeError = "error"

	// TypeRelayConnected is generated when RunProxy is started. The relay
	// connection's remote address is stored in the Data attribute.
	TypeRelayConnected = "relay connected"

	// TypeRelayDisconnected is generated when the relay connection is closed.
	// The Data attribute may contain a related error message.
	TypeRelayDisconnected = "relay disconnected"

	// TypeSOCKS5Active is generated when the SOCKS5 server is started. The Data
	// attribute is always empty.
	TypeSOCKS5Active = "SOCKS5 server active"

	// TypeSOCKS5Inactive is generated when the SOCKS5 server is stopped. The Data
	// attribute is always empty.
	TypeSOCKS5Inactive = "SOCKS5 server inactive"

	// TypeSOCKS5ConnectionOpened is generate whenever a new connection is opened
	// through the SOCKS5 server. The IP of host that initiated the connection
	// is stored in the Data attribute.
	TypeSOCKS5ConnectionOpened = "SOCKS5 connection opened"

	// TypeSOCKS5ConnectionClosed is generate whenever a connection through the
	// SOCKS5 server is closed. The IP of host that initiated the connection is
	// stored in the Data attribute.
	TypeSOCKS5ConnectionClosed = "SOCKS5 connection closed"
)

Variables

View Source
var DefaultEventCallback = func(e Event) {
	switch e.Type {
	case TypeError:
		fmt.Fprintf(os.Stderr, "error: %s\n", e.Data)
	case TypeRelayConnected:
		fmt.Printf("relay %s connected\n", e.Data)
	case TypeRelayDisconnected:
		fmt.Print("relay disconnected")
		if e.Data != "" {
			fmt.Print(": " + e.Data)
		}

		fmt.Println()
	case TypeSOCKS5Active:
		fmt.Println("SOCKS5 server active")
	case TypeSOCKS5Inactive:
		fmt.Println("SOCKS5 server inactive")
	case TypeSOCKS5ConnectionOpened, TypeSOCKS5ConnectionClosed:

	default:
		fmt.Fprintf(os.Stderr, "unexpected event %q: %s\n", e.Type, e.Data)
	}
}

DefaultEventCallback prints all events to stdout except for error events, which are printed to stderr. SOCKS5ConnectionOpened and SOCKS5ConnectionClosed events are ignored.

Functions

func RunProxy

func RunProxy(ctx context.Context, relayConn net.Conn, socks5listenAddr string) (err error)

RunProxy starts a SOCKS server on socks5listenAddr that tunnels all incoming connections through relayConn. The opposite site of the relayConn connection should be handled by RunRelay.

func RunProxyWithEventCallback

func RunProxyWithEventCallback(
	ctx context.Context, relayConn net.Conn, socks5ListenAddr string, callback func(Event),
) error

RunProxyWithEventCallback is like RunProxy but it allows to specify a custom event callback instead of DefaultEventCallback. If callback is nil, events are ignored.

func RunRelay

func RunRelay(ctx context.Context, conn net.Conn) error

RunRelay is the counterpart of RunProxy and acts as an exit node for the proxy connections tunneled through the provided connection.

func RunRelayWithEventCallback

func RunRelayWithEventCallback(ctx context.Context, conn net.Conn, callback func(Event)) error

RunRelayWithEventCallback is like RunRelay but it allows to specify a custom event callback instead of DefaultEventCallback. If callback is nil, events are ignored.

Types

type Event

type Event struct {
	Type string
	Data string
}

Event holds the events that are generated by RunProxy and RunRelay.

Jump to

Keyboard shortcuts

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