This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 178
/
main.go
106 lines (89 loc) · 1.71 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"io"
"math/rand"
"time"
shell "github.com/ipfs/go-ipfs-api"
u "github.com/ipfs/boxo/util"
)
var sh *shell.Shell
var ncalls int
var _ = time.ANSIC
func sleep() {
ncalls++
//time.Sleep(time.Millisecond * 5)
}
func randString() string {
alpha := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
l := rand.Intn(10) + 2
var s string
for i := 0; i < l; i++ {
s += string([]byte{alpha[rand.Intn(len(alpha))]})
}
return s
}
func makeRandomObject() (string, error) {
// do some math to make a size
x := rand.Intn(120) + 1
y := rand.Intn(120) + 1
z := rand.Intn(120) + 1
size := x * y * z
r := io.LimitReader(u.NewTimeSeededRand(), int64(size))
sleep()
return sh.Add(r)
}
func makeRandomDir(depth int) (string, error) {
if depth <= 0 {
return makeRandomObject()
}
sleep()
empty, err := sh.NewObject("unixfs-dir")
if err != nil {
return "", err
}
curdir := empty
for i := 0; i < rand.Intn(8)+2; i++ {
var obj string
if rand.Intn(2) == 1 {
obj, err = makeRandomObject()
if err != nil {
return "", err
}
} else {
obj, err = makeRandomDir(depth - 1)
if err != nil {
return "", err
}
}
name := randString()
sleep()
nobj, err := sh.PatchLink(curdir, name, obj, true)
if err != nil {
return "", err
}
curdir = nobj
}
return curdir, nil
}
func main() {
sh = shell.NewShell("localhost:5001")
for i := 0; i < 200; i++ {
_, err := makeRandomObject()
if err != nil {
fmt.Println("err: ", err)
return
}
}
fmt.Println("we're okay")
out, err := makeRandomDir(10)
fmt.Printf("%d calls\n", ncalls)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(out)
for {
time.Sleep(time.Second * 1000)
}
}