Documentation ¶
Overview ¶
Package proxyrelay implements both components of the relayed SOCKS5 proxy.
Index ¶
- Constants
- Variables
- func RunProxy(ctx context.Context, relayConn net.Conn, socks5listenAddr string) (err error)
- func RunProxyWithEventCallback(ctx context.Context, relayConn net.Conn, socks5ListenAddr string, ...) error
- func RunRelay(ctx context.Context, conn net.Conn) error
- func RunRelayWithEventCallback(ctx context.Context, conn net.Conn, callback func(Event)) error
- type Event
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 ¶
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.
Types ¶
Click to show internal directories.
Click to hide internal directories.