Add sharness tests and documentation
Antonio Navarro Perez committed
Dec 6, 2022 at 11:36 UTC
7f5adb5e071e5a9d5cc750a9d7e88ccfec2f92fa
3 files changed
+182
docs/config.md
+10
@@ -141,6 +141,10 @@ config file at runtime.
141
- [`Swarm.ConnMgr.HighWater`](#swarmconnmgrhighwater)
142
- [`Swarm.ConnMgr.GracePeriod`](#swarmconnmgrgraceperiod)
143
- [`Swarm.ResourceMgr`](#swarmresourcemgr)
144
+ - [Levels of Configuration](#levels-of-configuration)
145
+ - [Default Limits](#default-limits)
146
+ - [Active Limits](#active-limits)
147
+ - [libp2p resource monitoring](#libp2p-resource-monitoring)
148
- [`Swarm.ResourceMgr.Enabled`](#swarmresourcemgrenabled)
149
- [`Swarm.ResourceMgr.MaxMemory`](#swarmresourcemgrmaxmemory)
150
- [`Swarm.ResourceMgr.MaxFileDescriptors`](#swarmresourcemgrmaxfiledescriptors)
@@ -1342,6 +1346,7 @@ It specifies the routing type that will be created.
1346
Currently supported types:
1347
1348
- `reframe` **(DEPRECATED)** (delegated routing based on the [reframe protocol](https://github.com/ipfs/specs/tree/main/reframe#readme))
1349
+- `http` simple delegated routing based on HTTP protocol. <!-- TODO add link to specs when we have them merged. -->
1350
- `dht`
1351
- `parallel` and `sequential`: Helpers that can be used to run several routers sequentially or in parallel.
1352
@@ -1356,6 +1361,11 @@ Parameters needed to create the specified router. Supported params per router ty
1361
Reframe **(DEPRECATED)**:
1362
- `Endpoint` (mandatory): URL that will be used to connect to a specified router.
1363
1364
+HTTP:
1365
+ - `Endpoint` (mandatory): URL that will be used to connect to a specified router.
1366
+ - `MaxProvideBatchSize`: This number determines the maximum amount of CIDs sent per batch. Servers might not accept more than 100 elements per batch. 100 elements by default.
1367
+ - `MaxProvideConcurrency`: It determines the number of threads used when providing content. GOMAXPROCS by default.
1368
+
1369
DHT:
1370
- `"Mode"`: Mode used by the DHT. Possible values: "server", "client", "auto"
1371
- `"AcceleratedDHTClient"`: Set to `true` if you want to use the experimentalDHT.
test/sharness/t0702-delegated-routing-http.sh
new
+171
@@ -0,0 +1,171 @@
1
+#!/usr/bin/env bash
2
+
3
+test_description="Test delegated routing via HTTP endpoint"
4
+
5
+. lib/test-lib.sh
6
+
7
+if ! test_have_prereq SOCAT; then
8
+ skip_all="skipping '$test_description': socat is not available"
9
+ test_done
10
+fi
11
+
12
+# simple http routing server mock
13
+# local endpoint responds with deterministic application/vnd.ipfs.rpc+dag-json; version=1
14
+HTTP_ROUTING_PORT=5098
15
+function start_http_routing_mock_endpoint() {
16
+ REMOTE_SERVER_LOG="http-routing-server.log"
17
+ rm -f $REMOTE_SERVER_LOG
18
+
19
+ touch response
20
+ socat tcp-listen:$HTTP_ROUTING_PORT,fork,bind=127.0.0.1,reuseaddr 'SYSTEM:cat response'!!CREATE:$REMOTE_SERVER_LOG &
21
+ REMOTE_SERVER_PID=$!
22
+
23
+ socat /dev/null tcp:127.0.0.1:$HTTP_ROUTING_PORT,retry=10
24
+ return $?
25
+}
26
+function serve_http_routing_response() {
27
+ local body=$1
28
+ local status_code=${2:-"200 OK"}
29
+ local length=$((1 + ${#body}))
30
+ echo -e "HTTP/1.1 $status_code\nContent-Length: $length\nContent-Type: text/plain; charset=utf-8\n\n$body" > response
31
+}
32
+function stop_http_routing_mock_endpoint() {
33
+ exec 7<&-
34
+ kill $REMOTE_SERVER_PID > /dev/null 2>&1
35
+ wait $REMOTE_SERVER_PID || true
36
+}
37
+
38
+# daemon running in online mode to ensure Pin.origins/PinStatus.delegates work
39
+test_init_ipfs
40
+
41
+# based on static, synthetic http routing messages:
42
+# t0702-delegated-routing-http/FindProvidersRequest
43
+# t0702-delegated-routing-http/FindProvidersResponse
44
+FINDPROV_CID="baeabep4vu3ceru7nerjjbk37sxb7wmftteve4hcosmyolsbsiubw2vr6pqzj6mw7kv6tbn6nqkkldnklbjgm5tzbi4hkpkled4xlcr7xz4bq"
45
+EXPECTED_PROV="12D3KooWARYacCc6eoCqvsS9RW9MA2vo51CV75deoiqssx3YgyYJ"
46
+
47
+test_expect_success "default Routing config has no Routers defined" '
48
+ echo null > expected &&
49
+ ipfs config show | jq .Routing.Routers > actual &&
50
+ test_cmp expected actual
51
+'
52
+
53
+# turn off all implicit routers
54
+ipfs config Routing.Type none || exit 1
55
+test_launch_ipfs_daemon
56
+test_expect_success "disabling default router (dht) works" '
57
+ ipfs config Routing.Type > actual &&
58
+ echo none > expected &&
59
+ test_cmp expected actual
60
+'
61
+test_expect_success "no routers means findprovs returns no results" '
62
+ ipfs routing findprovs "$FINDPROV_CID" > actual &&
63
+ echo -n > expected &&
64
+ test_cmp expected actual
65
+'
66
+
67
+test_kill_ipfs_daemon
68
+
69
+ipfs config Routing.Type --json '"custom"' || exit 1
70
+ipfs config Routing.Methods --json '{
71
+ "find-peers": {
72
+ "RouterName": "TestDelegatedRouter"
73
+ },
74
+ "find-providers": {
75
+ "RouterName": "TestDelegatedRouter"
76
+ },
77
+ "get-ipns": {
78
+ "RouterName": "TestDelegatedRouter"
79
+ },
80
+ "provide": {
81
+ "RouterName": "TestDelegatedRouter"
82
+ }
83
+ }' || exit 1
84
+
85
+test_expect_success "missing method params makes daemon fails" '
86
+ echo "Error: constructing the node (see log for full detail): method name \"put-ipns\" is missing from Routing.Methods config param" > expected_error &&
87
+ GOLOG_LOG_LEVEL=fatal ipfs daemon 2> actual_error || exit 0 &&
88
+ test_cmp expected_error actual_error
89
+'
90
+
91
+ipfs config Routing.Methods --json '{
92
+ "find-peers": {
93
+ "RouterName": "TestDelegatedRouter"
94
+ },
95
+ "find-providers": {
96
+ "RouterName": "TestDelegatedRouter"
97
+ },
98
+ "get-ipns": {
99
+ "RouterName": "TestDelegatedRouter"
100
+ },
101
+ "provide": {
102
+ "RouterName": "TestDelegatedRouter"
103
+ },
104
+ "put-ipns": {
105
+ "RouterName": "TestDelegatedRouter"
106
+ },
107
+ "NOT_SUPPORTED": {
108
+ "RouterName": "TestDelegatedRouter"
109
+ }
110
+ }' || exit 1
111
+
112
+test_expect_success "having wrong methods makes daemon fails" '
113
+ echo "Error: constructing the node (see log for full detail): method name \"NOT_SUPPORTED\" is not a supported method on Routing.Methods config param" > expected_error &&
114
+ GOLOG_LOG_LEVEL=fatal ipfs daemon 2> actual_error || exit 0 &&
115
+ test_cmp expected_error actual_error
116
+'
117
+
118
+# set Routing config to only use delegated routing via mocked http routing endpoint
119
+
120
+ipfs config Routing.Type --json '"custom"' || exit 1
121
+ipfs config Routing.Routers.TestDelegatedRouter --json '{
122
+ "Type": "http",
123
+ "Parameters": {
124
+ "Endpoint": "http://127.0.0.1:5098/routing/v1"
125
+ }
126
+}' || exit 1
127
+ipfs config Routing.Methods --json '{
128
+ "find-peers": {
129
+ "RouterName": "TestDelegatedRouter"
130
+ },
131
+ "find-providers": {
132
+ "RouterName": "TestDelegatedRouter"
133
+ },
134
+ "get-ipns": {
135
+ "RouterName": "TestDelegatedRouter"
136
+ },
137
+ "provide": {
138
+ "RouterName": "TestDelegatedRouter"
139
+ },
140
+ "put-ipns": {
141
+ "RouterName": "TestDelegatedRouter"
142
+ }
143
+ }' || exit 1
144
+
145
+test_expect_success "adding http delegated routing endpoint to Routing.Routers config works" '
146
+ echo "http://127.0.0.1:5098/routing/v1" > expected &&
147
+ ipfs config Routing.Routers.TestDelegatedRouter.Parameters.Endpoint > actual &&
148
+ test_cmp expected actual
149
+'
150
+
151
+test_launch_ipfs_daemon
152
+
153
+test_expect_success "start_http_routing_mock_endpoint" '
154
+ start_http_routing_mock_endpoint
155
+'
156
+
157
+test_expect_success "'ipfs routing findprovs' returns result from delegated http router" '
158
+ serve_http_routing_response "$(<../t0702-delegated-routing-http/FindProvidersResponse)" &&
159
+ echo "$EXPECTED_PROV" > expected &&
160
+ ipfs routing findprovs "$FINDPROV_CID" > actual &&
161
+ test_cmp expected actual
162
+'
163
+
164
+test_expect_success "stop_http_routing_mock_endpoint" '
165
+ stop_http_routing_mock_endpoint
166
+'
167
+
168
+
169
+test_kill_ipfs_daemon
170
+test_done
171
+# vim: ts=2 sw=2 sts=2 et:
test/sharness/t0702-delegated-routing-http/FindProvidersResponse
new
+1
@@ -0,0 +1 @@
1
+{"Providers":[{"Protocol":"bitswap","ID":"12D3KooWARYacCc6eoCqvsS9RW9MA2vo51CV75deoiqssx3YgyYJ","Addrs":["/ip4/0.0.0.0/tcp/4001","/ip4/0.0.0.0/tcp/4002"]}]}
\ No newline at end of file