Skip to content

wasip1: make pure Go resolver the default#16

Merged
chriso merged 3 commits intomainfrom
pure-go-resolver-default
Jun 30, 2023
Merged

wasip1: make pure Go resolver the default#16
chriso merged 3 commits intomainfrom
pure-go-resolver-default

Conversation

@chriso
Copy link
Contributor

@chriso chriso commented Jun 30, 2023

Now that https://go-review.googlesource.com/c/go/+/500579 has landed, we can enable the pure Go resolver as the default name resolution mechanism. This means that the standard library net package works as expected. It also means that name resolution is non-blocking.

Example

package main

import (
	"fmt"
	"net"

	_ "github.com/stealthrocket/net/wasip1"
)

func main() {
	ips, err := net.LookupIP("example.com")
	if err != nil {
		panic(err)
	}
	fmt.Printf("%v\n", ips)
}
$ GOOS=wasip1 GOARCH=wasm gotip build -o main.wasm main.go
$ wasirun --dir / main.wasm
[93.184.216.34 2606:2800:220:1:248:1893:25c8:1946]
Trace of system calls:
$ wasirun --dir / --trace main.wasm
RandomGet([32]byte) => [32]byte("&S\x16k\2\xfe\x9f\xb4\x8fD-y]^\xd2\x83\xf9\4V@@\1+\xca\x0bfxP=7-\6")
RandomGet([8]byte) => [8]byte("\x1a]i\xb9'\xfd\x11\xdd")
ClockTimeGet(1, 0) => 229647185
ArgsSizesGet() => 1, 10
ArgsGet() => ["main.wasm"]
EnvironSizesGet() => 0, 0
ClockTimeGet(1, 0) => 234908567
ClockTimeGet(1, 0) => 234917926
ClockTimeGet(1, 0) => 235012813
FDStatGet(0) => {FileType:CharacterDeviceType,RightsBase:TTYRights}
FDStatSetFlags(0, NonBlock) => ok
FDStatGet(1) => {FileType:CharacterDeviceType,RightsBase:TTYRights}
FDStatSetFlags(1, NonBlock) => ok
FDStatGet(2) => {FileType:CharacterDeviceType,RightsBase:TTYRights}
FDStatSetFlags(2, NonBlock) => ok
FDPreStatGet(3) => {Type:PreOpenDir,PreStatDir.NameLength:1}
FDPreStatDirName(3) => "/"
FDPreStatGet(4) => EBADF (Bad file number)
ClockTimeGet(1, 0) => 235734439
FDStatGet(0) => {FileType:CharacterDeviceType,Flags:NonBlock,RightsBase:TTYRights}
FDStatGet(1) => {FileType:CharacterDeviceType,Flags:NonBlock,RightsBase:TTYRights}
FDStatGet(2) => {FileType:CharacterDeviceType,Flags:NonBlock,RightsBase:TTYRights}
PathOpen(3, SymlinkFollow, "etc/resolv.conf", OpenFlags(0), FDReadRight|FDSeekRight|FDStatSetFlagsRight|FDSyncRight|FDTellRight|FDAdviseRight|PathCreateDirectoryRight|PathCreateFileRight|PathLinkSourceRight|PathLinkTargetRight|PathOpenRight|FDReadDirRight|PathReadLinkRight|PathRenameSourceRight|PathRenameTargetRight|PathFileStatGetRight|PathFileStatSetTimesRight|FDFileStatGetRight|FDFileStatSetSizeRight|FDFileStatSetTimesRight|PathSymlinkRight|PathRemoveDirectoryRight|PathUnlinkFileRight|PollFDReadWriteRight, DirectoryRights|FileRights, FDFlags(0)) => 4
FDStatGet(4) => {FileType:RegularFileType,RightsBase:FDReadRight|FDSeekRight|FDStatSetFlagsRight|FDSyncRight|FDTellRight|FDAdviseRight|PathCreateDirectoryRight|PathCreateFileRight|PathLinkSourceRight|PathLinkTargetRight|PathOpenRight|FDReadDirRight|PathReadLinkRight|PathRenameSourceRight|PathRenameTargetRight|PathFileStatGetRight|PathFileStatSetTimesRight|FDFileStatGetRight|FDFileStatSetSizeRight|FDFileStatSetTimesRight|PathSymlinkRight|PathRemoveDirectoryRight|PathUnlinkFileRight|PollFDReadWriteRight,RightsInheriting:DirectoryRights|FileRights}
FDStatSetFlags(4, NonBlock) => ok
FDFileStatGet(4) => wasi.FileStat{Device:0x18, INode:0x6c5, FileType:0x4, NLink:0x1, Size:0x398, AccessTime:0x176d535dc14815a7, ModifyTime:0x176d535dc016e8a7, ChangeTime:0x176d535dc016e8a7}
FDRead(4, [1]IOVec{[65536]Byte}) => [920]byte: [1]IOVec{[920]byte("# This is /run/systemd/resolve/s"...)}
FDRead(4, [1]IOVec{[64616]Byte}) => [0]byte: [1]IOVec{[64616]Byte}
FDRead(4, [1]IOVec{[65536]Byte}) => [0]byte: [1]IOVec{[65536]Byte}
FDClose(4) => ok
ClockTimeGet(0, 0) => 1688098909735646708
ClockTimeGet(1, 0) => 236509003
ClockTimeGet(0, 0) => 1688098909735658788
ClockTimeGet(1, 0) => 236520943
PathOpen(3, SymlinkFollow, "etc/nsswitch.conf", OpenFlags(0), FDReadRight|FDSeekRight|FDStatSetFlagsRight|FDSyncRight|FDTellRight|FDAdviseRight|PathCreateDirectoryRight|PathCreateFileRight|PathLinkSourceRight|PathLinkTargetRight|PathOpenRight|FDReadDirRight|PathReadLinkRight|PathRenameSourceRight|PathRenameTargetRight|PathFileStatGetRight|PathFileStatSetTimesRight|FDFileStatGetRight|FDFileStatSetSizeRight|FDFileStatSetTimesRight|PathSymlinkRight|PathRemoveDirectoryRight|PathUnlinkFileRight|PollFDReadWriteRight, DirectoryRights|FileRights, FDFlags(0)) => 4
FDStatGet(4) => {FileType:RegularFileType,RightsBase:FDReadRight|FDSeekRight|FDStatSetFlagsRight|FDSyncRight|FDTellRight|FDAdviseRight|PathCreateDirectoryRight|PathCreateFileRight|PathLinkSourceRight|PathLinkTargetRight|PathOpenRight|FDReadDirRight|PathReadLinkRight|PathRenameSourceRight|PathRenameTargetRight|PathFileStatGetRight|PathFileStatSetTimesRight|FDFileStatGetRight|FDFileStatSetSizeRight|FDFileStatSetTimesRight|PathSymlinkRight|PathRemoveDirectoryRight|PathUnlinkFileRight|PollFDReadWriteRight,RightsInheriting:DirectoryRights|FileRights}
FDStatSetFlags(4, NonBlock) => ok
FDFileStatGet(4) => wasi.FileStat{Device:0x10302, INode:0x12001a7, FileType:0x4, NLink:0x1, Size:0x252, AccessTime:0x176d5d03511e14fb, ModifyTime:0x175721b929caea00, ChangeTime:0x1768ccf40e47902c}
FDRead(4, [1]IOVec{[65536]Byte}) => [594]byte: [1]IOVec{[594]byte("# /etc/nsswitch.conf\n#\n# Example"...)}
FDRead(4, [1]IOVec{[64942]Byte}) => [0]byte: [1]IOVec{[64942]Byte}
FDRead(4, [1]IOVec{[65536]Byte}) => [0]byte: [1]IOVec{[65536]Byte}
FDClose(4) => ok
ClockTimeGet(0, 0) => 1688098909735945428
ClockTimeGet(1, 0) => 236807853
ClockTimeGet(0, 0) => 1688098909735956658
ClockTimeGet(1, 0) => 236818433
ClockTimeGet(0, 0) => 1688098909735978807
ClockTimeGet(1, 0) => 236840602
PathFileStatGet(3, SymlinkFollow, "etc/hosts") => wasi.FileStat{Device:0x10302, INode:0x1200187, FileType:0x4, NLink:0x1, Size:0xdc, AccessTime:0x176d5d03bb73c309, ModifyTime:0x1768cd088ae81a9d, ChangeTime:0x1768cd088ae81a9d}
PathOpen(3, SymlinkFollow, "etc/hosts", OpenFlags(0), FDReadRight|FDSeekRight|FDStatSetFlagsRight|FDSyncRight|FDTellRight|FDAdviseRight|PathCreateDirectoryRight|PathCreateFileRight|PathLinkSourceRight|PathLinkTargetRight|PathOpenRight|FDReadDirRight|PathReadLinkRight|PathRenameSourceRight|PathRenameTargetRight|PathFileStatGetRight|PathFileStatSetTimesRight|FDFileStatGetRight|FDFileStatSetSizeRight|FDFileStatSetTimesRight|PathSymlinkRight|PathRemoveDirectoryRight|PathUnlinkFileRight|PollFDReadWriteRight, DirectoryRights|FileRights, FDFlags(0)) => 4
FDStatGet(4) => {FileType:RegularFileType,RightsBase:FDReadRight|FDSeekRight|FDStatSetFlagsRight|FDSyncRight|FDTellRight|FDAdviseRight|PathCreateDirectoryRight|PathCreateFileRight|PathLinkSourceRight|PathLinkTargetRight|PathOpenRight|FDReadDirRight|PathReadLinkRight|PathRenameSourceRight|PathRenameTargetRight|PathFileStatGetRight|PathFileStatSetTimesRight|FDFileStatGetRight|FDFileStatSetSizeRight|FDFileStatSetTimesRight|PathSymlinkRight|PathRemoveDirectoryRight|PathUnlinkFileRight|PollFDReadWriteRight,RightsInheriting:DirectoryRights|FileRights}
FDStatSetFlags(4, NonBlock) => ok
FDRead(4, [1]IOVec{[65536]Byte}) => [220]byte: [1]IOVec{[220]byte("127.0.0.1 localhost\n127.0.1.1 be"...)}
FDRead(4, [1]IOVec{[65316]Byte}) => [0]byte: [1]IOVec{[65316]Byte}
FDRead(4, [1]IOVec{[65536]Byte}) => [0]byte: [1]IOVec{[65536]Byte}
FDClose(4) => ok
ClockTimeGet(0, 0) => 1688098909736393933
ClockTimeGet(1, 0) => 237257858
ClockTimeGet(1, 0) => 237288757
ClockTimeGet(1, 0) => 237296097
SockOpen(InetFamily, DatagramSocket, IPProtocol, SockConnectionRights|SockListenRights, SockConnectionRights) => 4
FDStatGet(4) => {FileType:SocketDGramType,RightsBase:SockConnectionRights|SockListenRights,RightsInheriting:SockConnectionRights}
FDStatSetFlags(4, NonBlock) => ok
SockSetOpt(4, SocketLevel, Broadcast, 1) => ok
SockConnect(4, 127.0.0.53:53) => 127.0.0.1:47025
SockLocalAddress(4) => 127.0.0.1:47025
SockRemoteAddress(4) => 127.0.0.53:53
FDStatGet(4) => {FileType:SocketDGramType,Flags:NonBlock,RightsBase:SockConnectionRights|SockListenRights,RightsInheriting:SockConnectionRights}
ClockTimeGet(1, 0) => 237475811
ClockTimeGet(1, 0) => 237482680
FDWrite(4, [1]IOVec{[40]byte("\xd0\xa5\1 \0\1\0\0\0\0\0\1\7example\3com\0\0\x1c\0\1\0\0)"...)}) => 40
SockRecvFrom(4, [1]IOVec{[1232]Byte}, RIFlags(0)) => EAGAIN (Try again)
ClockTimeGet(1, 0) => 237677224
ClockTimeGet(1, 0) => 237688013
ClockTimeGet(0, 0) => 1688098909736879897
ClockTimeGet(1, 0) => 237742782
ClockTimeGet(1, 0) => 237754531
ClockTimeGet(1, 0) => 237758531
SockOpen(InetFamily, DatagramSocket, IPProtocol, SockConnectionRights|SockListenRights, SockConnectionRights) => 5
FDStatGet(5) => {FileType:SocketDGramType,RightsBase:SockConnectionRights|SockListenRights,RightsInheriting:SockConnectionRights}
FDStatSetFlags(5, NonBlock) => ok
SockSetOpt(5, SocketLevel, Broadcast, 1) => ok
SockConnect(5, 127.0.0.53:53) => 127.0.0.1:34778
SockLocalAddress(5) => 127.0.0.1:34778
SockRemoteAddress(5) => 127.0.0.53:53
FDStatGet(5) => {FileType:SocketDGramType,Flags:NonBlock,RightsBase:SockConnectionRights|SockListenRights,RightsInheriting:SockConnectionRights}
ClockTimeGet(1, 0) => 237847318
ClockTimeGet(1, 0) => 237852028
FDWrite(5, [1]IOVec{[40]byte("\xcd\xbc\1 \0\1\0\0\0\0\0\1\7example\3com\0\0\1\0\1\0\0)"...)}) => 40
SockRecvFrom(5, [1]IOVec{[1232]Byte}, RIFlags(0)) => EAGAIN (Try again)
ClockTimeGet(1, 0) => 237938045
PollOneoff({EventType:ClockEvent,UserData:0x0,ID:Monotonic,Timeout:0,Precision:1000},{EventType:FDReadEvent,UserData:0x1340ba8,FD:4},{EventType:FDReadEvent,UserData:0x1340ab0,FD:5}) => {EventType:ClockEvent,UserData:0x0
PollOneoff({EventType:ClockEvent,UserData:0x0,ID:Monotonic,Timeout:4999326682,Precision:1000},{EventType:FDReadEvent,UserData:0x1340ba8,FD:4},{EventType:FDReadEvent,UserData:0x1340ab0,FD:5}) => {EventType:FDReadEvent,UserData:0x1340ba8,NBytes:0}
ClockTimeGet(1, 0) => 238049691
ClockTimeGet(1, 0) => 238058061
ClockTimeGet(1, 0) => 238061511
SockRecvFrom(4, [1]IOVec{[1232]Byte}, RIFlags(0)) => [68]byte: [1]IOVec{[68]byte("\xd0\xa5\x81\x80\0\1\0\1\0\0\0\1\7example\3com\0\0\x1c\0\1\xc0\x0c\0"...)}, ROFlags(0), 127.0.0.53:53
FDClose(4) => ok
ClockTimeGet(1, 0) => 238217926
ClockTimeGet(1, 0) => 238242145
PollOneoff({EventType:ClockEvent,UserData:0x0,ID:Monotonic,Timeout:0,Precision:1000},{EventType:FDReadEvent,UserData:0x1340ab0,FD:5}) => {EventType:ClockEvent,UserData:0x0,{EventType:FDReadEvent,UserData:0x1340ab0,NBytes:0}
SockRecvFrom(5, [1]IOVec{[1232]Byte}, RIFlags(0)) => [56]byte: [1]IOVec{[56]byte("\xcd\xbc\x81\x80\0\1\0\1\0\0\0\1\7example\3com\0\0\1\0\1\xc0\x0c\0"...)}, ROFlags(0), 127.0.0.53:53
FDClose(5) => ok
ClockTimeGet(1, 0) => 238354861
ClockTimeGet(1, 0) => 238364861
ClockTimeGet(1, 0) => 238371970
FDWrite(1, [1]IOVec{[51]byte("[2606:2800:220:1:248:1893:25c8:1"...)}) => [2606:2800:220:1:248:1893:25c8:1946 93.184.216.34]
51
ProcExit(0) => Close() => ok

Copy link
Contributor

@achille-roussel achille-roussel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might be able to remove the definition of the lookup function in the postgres example? https://github.com/stealthrocket/net/blob/main/postgres/postgres_wasip1_test.go#L26-L28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants