mirror of
https://github.com/quarkslab/proxyblob
synced 2026-06-08 16:52:59 +00:00
5b21bc7cda
Compile the agent to WebAssembly for deployment in JS runtimes (Bun, Node.js, or any runtime implementing the TCPDial/UDPListen interface). - Split network and UDP code with js/native build tags - Extract UDP relay into a platform-agnostic shared layer - Expose runtime-agnostic TCPDial and UDPListen JS hooks - Add azure-sdk-for-go fork as submodule for WASM-compatible mmf fallback - Bump aznet dependency - Document WASM build and JS interface in README
42 lines
751 B
Go
42 lines
751 B
Go
//go:build !js
|
|
|
|
package proxy
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
type nativeUDPConn struct {
|
|
conn *net.UDPConn
|
|
}
|
|
|
|
func listenUDP() (UDPRelayConn, error) {
|
|
c, err := net.ListenUDP("udp", &net.UDPAddr{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &nativeUDPConn{c}, nil
|
|
}
|
|
|
|
func (c *nativeUDPConn) LocalPort() int {
|
|
return c.conn.LocalAddr().(*net.UDPAddr).Port
|
|
}
|
|
|
|
func (c *nativeUDPConn) ReadFrom(b []byte) (int, *net.UDPAddr, error) {
|
|
return c.conn.ReadFromUDP(b)
|
|
}
|
|
|
|
func (c *nativeUDPConn) WriteTo(b []byte, addr *net.UDPAddr) error {
|
|
_, err := c.conn.WriteToUDP(b, addr)
|
|
return err
|
|
}
|
|
|
|
func (c *nativeUDPConn) SetReadDeadline(t time.Time) error {
|
|
return c.conn.SetReadDeadline(t)
|
|
}
|
|
|
|
func (c *nativeUDPConn) Close() error {
|
|
return c.conn.Close()
|
|
}
|