Live video on the AT Protocol

iroh: readd iroh-test

+105 -1
+1 -1
.vscode/settings.json
··· 11 "mesonbuild.configureOnOpen": false, 12 "cSpell.words": ["Devplace", "streamplace", "webrtc"], 13 "go.lintTool": "golangci-lint-v2", 14 - "go.lintFlags": ["--path-mode=abs"], 15 "go.formatTool": "custom", 16 "go.alternateTools": { 17 "customFormatter": "golangci-lint-v2"
··· 11 "mesonbuild.configureOnOpen": false, 12 "cSpell.words": ["Devplace", "streamplace", "webrtc"], 13 "go.lintTool": "golangci-lint-v2", 14 + "go.lintFlags": ["--path-mode=abs", "--fast-only"], 15 "go.formatTool": "custom", 16 "go.alternateTools": { 17 "customFormatter": "golangci-lint-v2"
+7
Makefile
··· 304 LD_LIBRARY_PATH=$(shell realpath $(BUILDDIR))/lib \ 305 bash -euo pipefail -c "go test -p 1 -timeout 300s ./pkg/... -v | tee /dev/stderr | go-junit-report -out test.xml" 306 307 # _ _____ _ _ _______ _____ _ _ _____ 308 # | | |_ _| \ | |__ __|_ _| \ | |/ ____| 309 # | | | | | \| | | | | | | \| | | __
··· 304 LD_LIBRARY_PATH=$(shell realpath $(BUILDDIR))/lib \ 305 bash -euo pipefail -c "go test -p 1 -timeout 300s ./pkg/... -v | tee /dev/stderr | go-junit-report -out test.xml" 306 307 + .PHONY: iroh-test 308 + iroh-test: 309 + $(MAKE) dev-rust 310 + PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) \ 311 + LD_LIBRARY_PATH=$(shell realpath $(BUILDDIR))/lib \ 312 + go build -o $(BUILDDIR)/iroh-test ./pkg/iroh/iroh_test/... 313 + 314 # _ _____ _ _ _______ _____ _ _ _____ 315 # | | |_ _| \ | |__ __|_ _| \ | |/ ____| 316 # | | | | | \| | | | | | | \| | | __
+97
pkg/iroh/iroh_test/main.go
···
··· 1 + package main 2 + 3 + import ( 4 + "crypto/rand" 5 + "fmt" 6 + "os" 7 + "reflect" 8 + 9 + iroh "stream.place/streamplace/pkg/iroh/generated/iroh_streamplace" 10 + _ "stream.place/streamplace/pkg/streamplacedeps" 11 + ) 12 + 13 + func isNilError(err error) bool { 14 + if err == nil { 15 + return true 16 + } 17 + 18 + v := reflect.ValueOf(err) 19 + return v.Kind() == reflect.Ptr && v.IsNil() 20 + } 21 + 22 + func panicIfErr(err error) { 23 + if !isNilError(err) { 24 + panic(err) 25 + } 26 + } 27 + 28 + func main() { 29 + tickets := os.Args[1:] 30 + 31 + secret := make([]byte, 32) 32 + _, err := rand.Read(secret) 33 + panicIfErr(err) 34 + 35 + fmt.Println("Starting with tickets", tickets) 36 + config := iroh.Config{ 37 + Key: secret, 38 + Topic: make([]byte, 32), // all zero topic for testing 39 + MaxSendDuration: 1000_000_000, // 1s 40 + } 41 + fmt.Printf("Config created %+v\n", config) 42 + node, err := iroh.NodeSender(config) 43 + panicIfErr(err) 44 + 45 + db := node.Db() 46 + w := node.NodeScope() 47 + 48 + node_id, err := node.NodeId() 49 + panicIfErr(err) 50 + fmt.Println("Node ID:", node_id) 51 + 52 + ticket, err := node.Ticket() 53 + panicIfErr(err) 54 + fmt.Println("Ticket:", ticket) 55 + 56 + if len(tickets) > 0 { 57 + err = node.JoinPeers(tickets) 58 + panicIfErr(err) 59 + } 60 + 61 + err = w.Put(nil, []byte("hello"), []byte("world")) 62 + panicIfErr(err) 63 + stream := []byte("stream1") 64 + err = w.Put(&stream, []byte("subscribed"), []byte("true")) 65 + panicIfErr(err) 66 + 67 + filter := iroh.NewFilter() 68 + items, err := db.IterWithOpts(filter) 69 + panicIfErr(err) 70 + fmt.Printf("Iter items: %+v\n", items) 71 + 72 + filter2 := iroh.NewFilter().Global() 73 + items2, err := db.IterWithOpts(filter2) 74 + panicIfErr(err) 75 + fmt.Printf("Iter items: %+v\n", items2) 76 + 77 + filter3 := iroh.NewFilter().Stream(stream) 78 + items3, err := db.IterWithOpts(filter3) 79 + panicIfErr(err) 80 + fmt.Printf("Iter items: %+v\n", items3) 81 + 82 + sub := db.Subscribe(iroh.NewFilter()) 83 + for { 84 + ev, err := sub.NextRaw() 85 + panicIfErr(err) 86 + switch (*ev).(type) { 87 + case iroh.SubscribeItemEntry: 88 + fmt.Printf("%+v\n", (*ev).(iroh.SubscribeItemEntry)) 89 + case iroh.SubscribeItemCurrentDone: 90 + fmt.Printf("Got current done event: %+v\n", (*ev).(iroh.SubscribeItemCurrentDone)) 91 + case iroh.SubscribeItemExpired: 92 + fmt.Printf("Got expired event: %+v\n", (*ev).(iroh.SubscribeItemExpired)) 93 + case iroh.SubscribeItemOther: 94 + fmt.Printf("Got other event: %+v\n", (*ev).(iroh.SubscribeItemOther)) 95 + } 96 + } 97 + }