Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 6d00cc7

Browse files
committed
wip: circuit relay v2
Q: JS side of things does not seem to support v2 protocol(?) Q: do we need to diable mdns, bootstrappers and routing to be sure this works?
1 parent 69ded0b commit 6d00cc7

File tree

3 files changed

+134
-58
lines changed

3 files changed

+134
-58
lines changed

test/circuit/all.js

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,68 @@
11
/* eslint max-nested-callbacks: ["error", 8] */
22
/* eslint-env mocha */
33

4-
import { createJs, createGo } from '../utils/circuit.js'
4+
import { createJs, createGo, createGoRelay } from '../utils/circuit.js'
55

66
const base = '/ip4/127.0.0.1/tcp/0'
77

88
export default {
99
'go-go-go': {
10-
create: (factory) => Promise.all([
11-
createGo([`${base}/ws`], factory),
12-
createGo([`${base}/ws`], factory),
13-
createGo([`${base}/ws`], factory)
14-
])
10+
create: async (factory) => {
11+
const goRelayV2 = await createGoRelay([`${base}/ws`], factory)
12+
return Promise.all([
13+
createGo([`${base}/ws`], factory),
14+
goRelayV2,
15+
createGo([`${base}/ws`], factory, goRelayV2)
16+
])
17+
}
1518
},
1619
'js-go-go': {
17-
create: (factory) => Promise.all([
18-
createJs([`${base}/ws`], factory),
19-
createGo([`${base}/ws`], factory),
20-
createGo([`${base}/ws`], factory)
21-
])
20+
create: async (factory) => {
21+
const goRelayV2 = await createGoRelay([`${base}/ws`], factory)
22+
return Promise.all([
23+
createJs([`${base}/ws`], factory),
24+
goRelayV2,
25+
createGo([`${base}/ws`], factory, goRelayV2)
26+
])
27+
}
2228
},
2329
'go-go-js': {
24-
create: (factory) => Promise.all([
25-
createGo([`${base}/ws`], factory),
26-
createGo([`${base}/ws`], factory),
27-
createJs([`${base}/ws`], factory)
28-
])
30+
create: async (factory) => {
31+
const goRelayV2 = await createGoRelay([`${base}/ws`], factory)
32+
return Promise.all([
33+
createGo([`${base}/ws`], factory, goRelayV2),
34+
goRelayV2,
35+
createJs([`${base}/ws`], factory)
36+
])
37+
}
2938
},
3039
'js-go-js': {
31-
create: (factory) => Promise.all([
32-
createJs([`${base}/ws`], factory),
33-
createGo([`${base}/ws`], factory),
34-
createJs([`${base}/ws`], factory)
35-
])
40+
create: async (factory) => {
41+
const goRelayV2 = await createGoRelay([`${base}/ws`], factory)
42+
return Promise.all([
43+
createJs([`${base}/ws`], factory),
44+
goRelayV2,
45+
createJs([`${base}/ws`], factory)
46+
])
47+
}
3648
},
3749
'go-js-go': {
38-
create: (factory) => Promise.all([
39-
createGo([`${base}/ws`], factory),
40-
createJs([`${base}/ws`], factory),
41-
createGo([`${base}/ws`], factory)
42-
])
50+
create: async (factory) => {
51+
return Promise.all([
52+
createGo([`${base}/ws`], factory),
53+
createJs([`${base}/ws`], factory),
54+
createGo([`${base}/ws`], factory)
55+
])
56+
}
4357
},
4458
'js-js-go': {
45-
create: (factory) => Promise.all([
46-
createJs([`${base}/ws`], factory),
47-
createJs([`${base}/ws`], factory),
48-
createGo([`${base}/ws`], factory)
49-
])
59+
create: async (factory) => {
60+
return Promise.all([
61+
createJs([`${base}/ws`], factory),
62+
createJs([`${base}/ws`], factory),
63+
createGo([`${base}/ws`], factory)
64+
])
65+
}
5066
},
5167
'go-js-js': {
5268
create: (factory) => Promise.all([

test/circuit/browser.js

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { isWebWorker } from 'wherearewe'
66
import {
77
createJs,
88
createGo,
9+
createGoRelay,
910
createProc,
1011
connWithTimeout,
1112
getWsAddr,
@@ -14,21 +15,28 @@ import {
1415

1516
const base = '/ip4/127.0.0.1/tcp/0'
1617

18+
// note: the order nodeA-nodeB-relay means "node A connect to B over relay"
1719
export default {
1820
'browser-go-js': {
19-
create: (factory) => Promise.all([
20-
createProc([], factory),
21-
createGo([`${base}/ws`], factory),
22-
createJs([`${base}/ws`], factory)
23-
]),
21+
create: async (factory) => {
22+
const goRelayV2 = await createGoRelay([`${base}/ws`], factory)
23+
return Promise.all([
24+
createProc([], factory),
25+
goRelayV2,
26+
createJs([`${base}/ws`], factory, goRelayV2)
27+
])
28+
},
2429
connect: connWithTimeout(1500)
2530
},
2631
'browser-go-go': {
27-
create: (factory) => Promise.all([
28-
createProc([], factory),
29-
createGo([`${base}/ws`], factory),
30-
createGo([`${base}/ws`], factory)
31-
]),
32+
create: async (factory) => {
33+
const goRelayV2 = await createGoRelay([`${base}/ws`], factory)
34+
return Promise.all([
35+
createProc([], factory),
36+
goRelayV2,
37+
createGo([`${base}/ws`], factory, goRelayV2)
38+
])
39+
},
3240
connect: connWithTimeout(1500)
3341
},
3442
'browser-js-js': {
@@ -48,19 +56,25 @@ export default {
4856
connect: connWithTimeout(1500)
4957
},
5058
'js-go-browser': {
51-
create: (factory) => Promise.all([
52-
createJs([`${base}/ws`], factory),
53-
createGo([`${base}/ws`], factory),
54-
createProc([], factory)
55-
]),
59+
create: async (factory) => {
60+
const goRelayV2 = await createGoRelay([`${base}/ws`], factory)
61+
return Promise.all([
62+
createJs([`${base}/ws`], factory),
63+
goRelayV2,
64+
createProc([], factory, goRelayV2)
65+
])
66+
},
5667
connect: connWithTimeout(1500)
5768
},
5869
'go-go-browser': {
59-
create: (factory) => Promise.all([
60-
createGo([`${base}/ws`], factory),
61-
createGo([`${base}/ws`], factory),
62-
createProc([], factory)
63-
]),
70+
create: async (factory) => {
71+
const goRelayV2 = await createGoRelay([`${base}/ws`], factory)
72+
return Promise.all([
73+
createGo([`${base}/ws`], factory),
74+
goRelayV2,
75+
createProc([], factory, goRelayV2)
76+
])
77+
},
6478
connect: connWithTimeout(1500)
6579
},
6680
'js-js-browser': {

test/utils/circuit.js

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ import { expect } from 'aegir/utils/chai.js'
77

88
const transportKey = WS.prototype[Symbol.toStringTag]
99

10-
export function createProc (addrs, factory) {
10+
export function createProc (addrs, factory, relay) {
11+
if (relay) {
12+
// FIXME throw new Error('createProc missing circuit relay v2 support')
13+
}
1114
return factory.spawn({
1215
type: 'proc',
1316
ipfsOptions: {
1417
config: {
1518
Addresses: {
1619
Swarm: addrs
1720
},
18-
relay: {
21+
relay: { // FIXME: this is circuit v1, needs support of v2
1922
enabled: true,
2023
hop: {
2124
enabled: true
@@ -35,15 +38,18 @@ export function createProc (addrs, factory) {
3538
})
3639
}
3740

38-
export function createJs (addrs, factory) {
41+
export function createJs (addrs, factory, relay) {
42+
if (relay) {
43+
// FIXME throw new Error('createJs missing circuit relay v2 support')
44+
}
3945
return factory.spawn({
4046
type: 'js',
4147
ipfsOptions: {
4248
config: {
4349
Addresses: {
4450
Swarm: addrs
4551
},
46-
relay: {
52+
relay: { // FIXME: this is circuit v1, needs support of v2
4753
enabled: true,
4854
hop: {
4955
enabled: true
@@ -54,7 +60,12 @@ export function createJs (addrs, factory) {
5460
})
5561
}
5662

57-
export function createGo (addrs, factory) {
63+
// creates "private" go-ipfs node which is uses static relay if specified
64+
export function createGo (addrs, factory, relay) {
65+
let StaticRelays
66+
if (relay) {
67+
StaticRelays = [getWsAddr(relay.api.peerId.addresses)]
68+
}
5869
return factory.spawn({
5970
type: 'go',
6071
ipfsOptions: {
@@ -63,8 +74,43 @@ export function createGo (addrs, factory) {
6374
Swarm: addrs
6475
},
6576
Swarm: {
66-
DisableRelay: false,
67-
EnableRelayHop: true
77+
// go uses circuit v2
78+
RelayClient: {
79+
Enabled: true,
80+
StaticRelays
81+
},
82+
RelayService: {
83+
Enabled: false
84+
}
85+
},
86+
Internal: {
87+
Libp2pForceReachability: 'private'
88+
}
89+
}
90+
}
91+
})
92+
}
93+
94+
// creates "publicly diallable" go-ipfs running a relay service
95+
export function createGoRelay (addrs, factory) {
96+
return factory.spawn({
97+
type: 'go',
98+
ipfsOptions: {
99+
config: {
100+
Addresses: {
101+
Swarm: addrs
102+
},
103+
Swarm: {
104+
// go uses circuit v2
105+
RelayClient: {
106+
Enabled: false
107+
},
108+
RelayService: {
109+
Enabled: true
110+
}
111+
},
112+
Internal: {
113+
Libp2pForceReachability: 'public'
68114
}
69115
}
70116
}

0 commit comments

Comments
 (0)