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