Client.do calls didTimeout() on the error path (line 461), and the contract is
that send() returns a non-nil didTimeout whenever err != nil. TinyGo dropped
setRequestCancel but left the roundTrip error path returning the nil named
return value, so any http.Client{Timeout: ...} request whose dial failed (e.g.
connection refused) panicked with a nil func-value dereference instead of
returning the error. Return alwaysFalse on those error paths, matching the
other error returns in send().
Verified: http.Client{Timeout}.Get to a refused port now returns
"connection refused" instead of panicking.
* http: add ErrUseLastResponse and Client.CloseIdleConnections
Both are API-compatibility fills. ErrUseLastResponse is a sentinel a
CheckRedirect func returns to stop following redirects; nothing here has
to act on it beyond existing. CloseIdleConnections delegates to the
Transport when it has the method, which is what net/http does.
Programs that reference either currently fail to compile against this
package for want of a name, which is the whole cost.
Rewrite the bash upgrade script as a standalone Go program for better
portability and maintainability. The tool preserves all existing behavior:
three-category file classification, dry-run mode, Go source resolution
(gvm/GOROOT/download), 3-way merge via diff3, and colored output.
Build: cd tools/upgrade && go build -o upgrade .
Run: ./tools/upgrade/upgrade --dry-run
Signed-off-by: deadprogram <ron@hybridgroup.com>
The TinyGo net/http Transport was missing TLSHandshakeTimeout, so callers that
set it (e.g. skywire's skysocks HTTPS-over-mesh client) fail to compile. Add the
field; the TinyGo transport does the handshake inline so it is advisory, but it
lets standard net/http source build unchanged under TinyGo.
Make the net package address-family aware instead of IPv4-only: DialTCP,
listenTCP and DialUDP now choose AF_INET or AF_INET6 from the target address
(socketFamily), the "only ipv4 supported" guard is replaced by a 4-or-16 byte
check, and "tcp6"/"udp6" network names are accepted.
In the host netdev, sockaddrFromParts builds a SockaddrInet6 for IPv6 addresses
(SockaddrInet4 otherwise), Accept decodes both families, GetHostByName and the
/etc/hosts lookup accept IPv6, and the stub resolver now queries AAAA after A.
Name resolution still prefers IPv4, so the "4"/"6" suffix is advisory for host
names; this is documented on Dial/Listen. Link-local IPv6 zones are not mapped
to a scope id.
Verified on linux/amd64 with tinygo: IPv6 loopback Listen/Accept/Dial over
[::1], AAAA fallback for an IPv6-only host name, and IPv4 behaviour unchanged.
On the native linux target the net package defaulted to a NOP netdev that
returns "Netdev not set" for every operation, so net.Dial/Listen, DNS and
anything built on them (net/http, tls) failed at runtime.
Native linux does not override the syscall package, and the TinyGo compiler
lowers syscall.Syscall/RawSyscall into real system calls, so the standard
library socket functions work directly (musl's omitted network module is not
needed). Register a default netdev implementing the netdever interface on top
of syscall.Socket/Connect/Bind/Listen/Accept/Send/Recv/SetSockOpt, plus a
small UDP DNS resolver (/etc/hosts, /etc/resolv.conf) for GetHostByName. Also
restore the net.DNSError type used by resolution errors.
Blocking sockets under the threads scheduler; IPv4 only. This avoids the
internal/poll netpoller dependency that blocked the upstream-net approach.
Refs tinygo-org/net#28
* net: add UDP listen, resolver, DNSError, and TCP listener APIs for wasm
TinyGo's net package was missing several symbols that upstream Go's
js/wasm net declares, blocking builds that pull pion/transport, pion/dtls,
and similar (via netbird's WASM client). Add them, backed by the existing
netdev abstraction so they compile for all targets and no-op cleanly under
nopNetdev (matching Go's js runtime behavior):
- DNSError type (dnserror.go), copied from Go 1.26.2.
- Resolver + DefaultResolver with LookupHost/LookupIP/LookupIPAddr/
LookupNetIP/LookupPort; LookupHost/LookupIP package funcs; Dialer.Resolver
field for API compatibility.
- UDPConn: ListenUDP, ReadFromUDP(AddrPort), WriteToUDP(AddrPort),
SetReadBuffer, SetWriteBuffer.
- TCPConn: CloseRead, SetNoDelay, SetReadBuffer, SetWriteBuffer,
ReadFrom(io.Reader).
- TCPListener: ListenTCP, AcceptTCP, SetDeadline; ListenPacket package func.
- Interface: Addrs, MulticastAddrs stubs.
* more complete PR for adding more net support (#64)
* format unixsock
The js/wasm RoundTrip fallback called t.roundTrip(req), an upstream
Go private method that was never backported to TinyGo's Transport stub.
Replace the call with an explicit error return, since the empty
Transport has no dial capability and cannot perform a fallback
round-trip.
Fixes#52
Signed-off-by: deadprogram <ron@hybridgroup.com>
internal/strconv was added in Go 1.26. For older Go versions, use
internal/itoa (already present in TinyGo) via a build tag shim.
Fixes TinyGo #5332
Signed-off-by: deadprogram <ron@hybridgroup.com>
- upgrade.sh: automates backporting upstream Go net package changes
- Downloads Go source tarballs for CUR and UPSTREAM versions
- Copies unmodified files directly from upstream
- Performs 3-way merge (diff3) for TinyGo-modified files
- Detects per-file CUR version from TINYGO headers
- Generates detailed diff reports in .upgrade-report/
- Supports --dry-run mode for previewing changes
- .gitignore: add .upgrade-work/ and .upgrade-report/ directories
This change introduces a CheckRedirect field to the http.Client struct in TinyGo,
mirroring the behavior of Go's standard library http.Client.
The purpose of this addition is to resolve build errors in projects that rely
on packages (such as golang.org/x/oauth2) expecting the Client to have a
CheckRedirect field. The field provides no functional change within TinyGo’s
HTTP client at this time — it is only included for API compatibility and
compilation success. There is no effect on runtime behavior unless explicitly
used by downstream code.
This fixes a problem with https://github.com/tinygo-org/net/pull/36
which causes the Windows TinyGO build to fail. The problem is the
function lookupProtocol was missing for Windows build. This PR adds the
function for Windows.
I can't really test this because I don't have a Windows system, but by
inspection is seems like it's correct.
This is a rework of PR#24 based on review comments. The rework mostly
involved moving changes to the proper files, aligning with upstream Go
src/net file layout.
Initialize netdev to dummy NOP netdev that gracefully errors out all netdev
interface calls. This is to catch cases where useNetdev() was not
called by the app to set netdev.
According to man page accept(2), accept returns new client sockfd and
remote peer ip:port. This patch corrects the Accept() prototype in the
netdever interface to not take in an ip:port arg, but rather return an
ip:port for remote peer.
* stub out more types/funcs to compile against golang.org/x/net/internal/socket
These are changes need to compile github.com/domainr/dnsr/ with TinyGo. See issue tinygo-org/net#14.
These change are mostly to fix missing symbols in src/net. Missing types and functions are cut-and-pasted from go1.21.4. Functions are stubbed out returning errors.New("not implemented").
DNRS is compiled by running tinygo test:
sfeldma@nuc:~/work/dnsr$ tinygo test -target=wasi
With this patch, and a corresponding patch for tinygo/ to fixup crypto/tls, you should get a clean compile.
Need to return the same error structure/content as regular Go for
net.Conn Read/Write operations. Found/fixed when testing deadlines
on Read/Write operations.
This PR adds a network device driver model called netdev. There will be a companion PR for TinyGo drivers to update the netdev drivers and network examples. This PR covers the core "net" package.
An RFC for the work is here: #tinygo-org/drivers#487. Some things have changed from the RFC, but nothing major.
The "net" package is a partial port of Go's "net" package, version 1.19.3. The src/net/README file has details on what is modified from Go's "net" package.
Most "net" features are working as they would in normal Go. TCP/UDP/TLS protocol support is there. As well as HTTP client and server support. Standard Go network packages such as golang.org/x/net/websockets and Paho MQTT client work as-is. Other packages are likely to work as-is.
Testing results are here (https://docs.google.com/spreadsheets/d/e/2PACX-1vT0cCjBvwXf9HJf6aJV2Sw198F2ief02gmbMV0sQocKT4y4RpfKv3dh6Jyew8lQW64FouZ8GwA2yjxI/pubhtml?gid=1013173032&single=true).