Documentation ¶
Overview ¶
Package netwrap allows for stacking multiple layers of address onto each other and wrapping connections accordingly to these. Imagine multiple hops of a proxied connection or adding a public key to an expected endpoint.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dial ¶
Dial first opens a network connection to the supplied addr, and then applies all the passed connection wrappers.
func GetAddr ¶
GetAddr returns, if available, the concrete address addr with netw == addr.Network() from inside the stack. If no such address exists, it returns nil.
Example ¶
tcpAddr := &net.TCPAddr{ IP: net.IPv4(127, 0, 0, 1), Port: 8008, } ta := testAddr{ net: "foo", str: "some-info", } wrappedAddr := WrapAddr(tcpAddr, ta) fmt.Println("wrapped:", wrappedAddr.String()) unwrappedFoo := GetAddr(wrappedAddr, "foo") fmt.Println("foo:", unwrappedFoo.String()) unwrappedTCP := GetAddr(wrappedAddr, "tcp") fmt.Println("tcp:", unwrappedTCP.String())
Output: wrapped: 127.0.0.1:8008|some-info foo: some-info tcp: 127.0.0.1:8008
Types ¶
type Addr ¶
type Addr interface { net.Addr // Head returns the address of the highest element of the protocol stack. // This should not return a stack address Head() net.Addr // Inner returns everything below the highest element. Might be stack address itself. Inner() net.Addr }
Addr is a stack address, representing the protocol stack.
type ConnWrapper ¶
ConnWrapper wraps a network connection, e.g. to encrypt the transmitted content.
type Dialer ¶
Dialer is Dial() but as a function type for alternative dialers (like using a socks proxy)
type ListenerWrapper ¶
ListenerWrapper wraps a network listener.
func NewListenerWrapper ¶
func NewListenerWrapper(addr net.Addr, cws ...ConnWrapper) ListenerWrapper
NewListenerWrapper creates a new ListenerWrapper by wrapping all accepted connections with the supplied connection wrapper and wrapping the listener's address with the supplied address.