Documentation ¶
Index ¶
- func NewDialer(c *water.Config) (water.Dialer, error)deprecated
- func NewDialerWithContext(ctx context.Context, c *water.Config) (water.Dialer, error)
- func NewListener(c *water.Config) (water.Listener, error)deprecated
- func NewListenerWithContext(ctx context.Context, c *water.Config) (water.Listener, error)
- func NewRelay(c *water.Config) (water.Relay, error)deprecated
- func NewRelayWithContext(ctx context.Context, c *water.Config) (water.Relay, error)
- type Conn
- func (c *Conn) Close() (err error)
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (n int, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) (err error)
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(b []byte) (n int, err error)
- type Dialer
- type Listener
- type ManagedDialer
- type Relay
- type TransportModule
- func (tm *TransportModule) AcceptFor(reverseCallerConn net.Conn) (sourceConn net.Conn, err error)
- func (tm *TransportModule) Associate() error
- func (tm *TransportModule) Cancel() error
- func (tm *TransportModule) Cleanup()
- func (tm *TransportModule) Close() error
- func (tm *TransportModule) Core() water.Core
- func (tm *TransportModule) Defer(f func())
- func (tm *TransportModule) DeferAll()
- func (tm *TransportModule) DialFrom(reverseCallerConn net.Conn) (destConn net.Conn, err error)
- func (tm *TransportModule) GetPushedConn(fd int32) net.Conn
- func (tm *TransportModule) Initialize() error
- func (tm *TransportModule) LinkNetworkInterface(dialer *ManagedDialer, listener net.Listener) error
- func (tm *TransportModule) PushConn(conn net.Conn) (fd int32, err error)
- func (tm *TransportModule) Worker() error
- func (tm *TransportModule) WorkerErrored() <-chan error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDialer
deprecated
NewDialer creates a new water.Dialer from the given water.Config.
Deprecated: use NewDialerWithContext instead.
func NewDialerWithContext ¶
NewDialerWithContext creates a new water.Dialer from the given water.Config with the given context.Context.
The context is used as the default context for call to Dialer.Dial.
func NewListener
deprecated
NewListener creates a new water.Listener from the given water.Config.
Deprecated: use NewListenerWithContext instead.
func NewListenerWithContext ¶
NewListenerWithContext creates a new water.Listener from the water.Config with the given context.Context.
The context is passed to water.NewCoreWithContext to control the lifetime of the call to function calls into the WebAssembly module. If the context is canceled or reaches its deadline, any current and future function call will return with an error. Call water.WazeroRuntimeConfigFactory.SetCloseOnContextDone with false to disable this behavior.
func NewRelay
deprecated
NewRelay creates a new water.Relay from the given water.Config without starting it. To start the relay, call Relay.RelayTo or Relay.ListenAndRelayTo.
Deprecated: use NewRelayWithContext instead.
func NewRelayWithContext ¶
NewRelayWithContext creates a new water.Relay from the water.Config with the given context.Context without starting it. To start the relay, call Relay.RelayTo or Relay.ListenAndRelayTo.
The context is passed to water.NewCoreWithContext to control the lifetime of the call to function calls into the WebAssembly module. If the context is canceled or reaches its deadline, any current and future function call will return with an error. Call water.WazeroRuntimeConfigFactory.SetCloseOnContextDone with false to disable this behavior.
Types ¶
type Conn ¶
type Conn struct { water.UnimplementedConn // embedded to ensure forward compatibility // contains filtered or unexported fields }
Conn is the first experimental version of Conn implementation.
func (*Conn) Close ¶
Close implements the net.Conn interface.
It will close both the network connection AND the WASM module, then the user-facing net.Conn will be closed.
func (*Conn) LocalAddr ¶
LocalAddr implements the net.Conn interface.
It calls to the underlying network connection's net.Conn.LocalAddr method. For Listener and Relay, the network connection of interest is the srcConn. And for Dialer, the network connection of interest is the dstConn.
func (*Conn) Read ¶
Read implements the net.Conn interface.
It calls to the underlying user-oriented connection's net.Conn.Read method.
func (*Conn) RemoteAddr ¶
RemoteAddr implements the net.Conn interface.
It calls to the underlying network connection's net.Conn.RemoteAddr method. For Listener and Relay, the network connection of interest is the srcConn. And for Dialer, the network connection of interest is the dstConn.
func (*Conn) SetDeadline ¶
SetDeadline implements the net.Conn interface.
It calls to the underlying connections' net.Conn.SetDeadline method.
func (*Conn) SetReadDeadline ¶
SetReadDeadline implements the net.Conn interface.
It calls to the underlying user-oriented connection's net.Conn.SetReadDeadline method.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline implements the net.Conn interface.
It calls to the underlying user-oriented connection's net.Conn.SetWriteDeadline method.
type Dialer ¶
type Dialer struct { water.UnimplementedDialer // embedded to ensure forward compatibility // contains filtered or unexported fields }
Dialer implements water.Dialer utilizing Water WATM API v0.
Example ¶
ExampleDialer demonstrates how to use v0.Dialer as a water.Dialer.
config := &water.Config{ TransportModuleBin: wasmReverse, ModuleConfigFactory: water.NewWazeroModuleConfigFactory(), } waterDialer, err := v0.NewDialerWithContext(context.Background(), config) if err != nil { panic(err) } // create a local TCP listener tcpListener, err := net.Listen("tcp", "localhost:0") if err != nil { panic(err) } defer tcpListener.Close() // skipcq: GO-S2307 waterConn, err := waterDialer.DialContext(context.Background(), "tcp", tcpListener.Addr().String()) if err != nil { panic(err) } defer waterConn.Close() // skipcq: GO-S2307 tcpConn, err := tcpListener.Accept() if err != nil { panic(err) } defer tcpConn.Close() // skipcq: GO-S2307 var msg = []byte("hello") n, err := waterConn.Write(msg) if err != nil { panic(err) } if n != len(msg) { panic("short write") } buf := make([]byte, 1024) n, err = tcpConn.Read(buf) if err != nil { panic(err) } if n != len(msg) { panic("short read") } fmt.Println(string(buf[:n]))
Output: olleh
func (*Dialer) Dial ¶
Dial dials the network address using the dialerFunc specified in config.
Implements water.Dialer.
func (*Dialer) DialContext ¶
func (d *Dialer) DialContext(ctx context.Context, network, address string) (conn water.Conn, err error)
DialContext dials the network address using the dialerFunc specified in config.
The context is passed to water.NewCoreWithContext to control the lifetime of the call to function calls into the WebAssembly module. If the context is canceled or reaches its deadline, any current and future function call will return with an error. Call water.WazeroRuntimeConfigFactory.SetCloseOnContextDone with false to disable this behavior.
Implements water.Dialer.
type Listener ¶
type Listener struct { water.UnimplementedListener // embedded to ensure forward compatibility // contains filtered or unexported fields }
Listener implements water.Listener utilizing Water WATM API v0.
Example ¶
ExampleListener demonstrates how to use v0.Listener as a water.Listener.
wrappedTcpListener, err := net.Listen("tcp", "localhost:0") if err != nil { panic(fmt.Sprintf("failed to listen: %v", err)) } // start using W.A.T.E.R. API below this line, have fun! config := &water.Config{ TransportModuleBin: wasmReverse, NetworkListener: wrappedTcpListener, ModuleConfigFactory: water.NewWazeroModuleConfigFactory(), } waterListener, err := v0.NewListenerWithContext(context.Background(), config) if err != nil { panic(fmt.Sprintf("failed to listen: %v", err)) } defer waterListener.Close() // skipcq: GO-S2307 tcpConn, err := net.Dial("tcp", waterListener.Addr().String()) if err != nil { panic(err) } defer tcpConn.Close() // skipcq: GO-S2307 waterConn, err := waterListener.Accept() if err != nil { panic(err) } defer waterConn.Close() // skipcq: GO-S2307 var msg = []byte("hello") n, err := tcpConn.Write(msg) if err != nil { panic(err) } if n != len(msg) { panic("short write") } buf := make([]byte, 1024) n, err = waterConn.Read(buf) if err != nil { panic(err) } if n != len(msg) { panic("short read") } fmt.Println(string(buf[:n]))
Output: olleh
func (*Listener) Accept ¶
Accept waits for and returns the next connection after processing the data with the WASM module.
The returned net.Conn implements net.Conn and could be seen as the inbound connection with a wrapping transport protocol handled by the WASM module.
Implements net.Listener.
func (*Listener) AcceptWATER ¶
AcceptWATER waits for and returns the next connection to the listener as a water.Conn.
Implements water.Listener.
type ManagedDialer ¶
type ManagedDialer struct {
// contains filtered or unexported fields
}
ManagedDialer restricts the network and address to be used by the dialerFunc.
func NewManagedDialer ¶
func NewManagedDialer(network, address string, dialerFunc func(network, address string) (net.Conn, error)) *ManagedDialer
NewManagedDialer creates a new ManagedDialer.
type Relay ¶
type Relay struct { water.UnimplementedRelay // embedded to ensure forward compatibility // contains filtered or unexported fields }
Relay implements water.Relay utilizing Water WATM API v0.
Example ¶
ExampleRelay demonstrates how to use v0.Relay as a water.Relay.
// Relay destination: a local TCP server tcpListener, err := net.Listen("tcp", "localhost:0") if err != nil { panic(err) } defer tcpListener.Close() // skipcq: GO-S2307 config := &water.Config{ TransportModuleBin: wasmReverse, ModuleConfigFactory: water.NewWazeroModuleConfigFactory(), } waterRelay, err := v0.NewRelayWithContext(context.Background(), config) if err != nil { panic(err) } defer waterRelay.Close() // skipcq: GO-S2307 // in a goroutine, start relay go func() { err := waterRelay.ListenAndRelayTo("tcp", "localhost:0", "tcp", tcpListener.Addr().String()) if err != nil { panic(err) } }() time.Sleep(100 * time.Millisecond) // 100ms to spin up relay // test source: a local TCP client clientConn, err := net.Dial("tcp", waterRelay.Addr().String()) if err != nil { panic(err) } defer clientConn.Close() // skipcq: GO-S2307 serverConn, err := tcpListener.Accept() if err != nil { panic(err) } defer serverConn.Close() // skipcq: GO-S2307 var msg = []byte("hello") n, err := clientConn.Write(msg) if err != nil { panic(err) } if n != len(msg) { panic("short write") } buf := make([]byte, 1024) n, err = serverConn.Read(buf) if err != nil { panic(err) } if n != len(msg) { panic("short read") } fmt.Println(string(buf[:n]))
Output: olleh
func (*Relay) ListenAndRelayTo ¶
ListenAndRelayTo implements water.Relay.
type TransportModule ¶
type TransportModule struct {
// contains filtered or unexported fields
}
TransportModule acts like a "managed core". It was build to provide WebAssembly Transport Module API-facing functions and utilities that are exclusive to version 0.
func UpgradeCore ¶
func UpgradeCore(core water.Core) *TransportModule
UpgradeCore upgrades a water.Core to a v0 TransportModule.
func (*TransportModule) AcceptFor ¶
AcceptFor is used to make the Transport Module act as a listener and accept a network connection.
func (*TransportModule) Associate ¶
func (tm *TransportModule) Associate() error
Associate is used to make the Transport Module act as a relay and associate two network connections, where one is from a source via a listener, and the other is to a destination via a dialer.
func (*TransportModule) Cancel ¶
func (tm *TransportModule) Cancel() error
Cancel cancels the worker thread if it is running and returns the error returned by the worker thread. This call is designed to block until the worker thread exits.
func (*TransportModule) Cleanup ¶
func (tm *TransportModule) Cleanup()
Clean up the Transport Module by closing all connections pushed into the Transport Module.
func (*TransportModule) Close ¶
func (tm *TransportModule) Close() error
func (*TransportModule) Core ¶
func (tm *TransportModule) Core() water.Core
func (*TransportModule) Defer ¶
func (tm *TransportModule) Defer(f func())
func (*TransportModule) DeferAll ¶
func (tm *TransportModule) DeferAll()
func (*TransportModule) DialFrom ¶
DialFrom is used to make the Transport Module act as a dialer and dial a network connection.
Takes the reverse caller connection as an argument, which is used to communicate with the caller.
func (*TransportModule) GetPushedConn ¶
func (tm *TransportModule) GetPushedConn(fd int32) net.Conn
func (*TransportModule) Initialize ¶
func (tm *TransportModule) Initialize() error
Initialize initializes the WASMv0 runtime by getting all the exported functions from the WASM module.
All imports must be set before calling this function.
func (*TransportModule) LinkNetworkInterface ¶
func (tm *TransportModule) LinkNetworkInterface(dialer *ManagedDialer, listener net.Listener) error
func (*TransportModule) PushConn ¶
func (tm *TransportModule) PushConn(conn net.Conn) (fd int32, err error)
PushConn pushes a net.Conn into the Transport Module.
func (*TransportModule) Worker ¶
func (tm *TransportModule) Worker() error
Worker spins up a worker thread for the WATM to run a blocking function, which is expected to be the mainloop.
This function is non-blocking UNLESS the error occurred before entering the worker thread. In that case, the error will be returned immediately.
func (*TransportModule) WorkerErrored ¶
func (tm *TransportModule) WorkerErrored() <-chan error
WorkerErrored returns a channel that will be closed when the worker thread exits.