Skip to content

Commit 8a84f0e

Browse files
authored
Merge pull request #7 from bitxenia/revert-6-revert-5-autoTLS-support-checkpoint
Revert "Revert "Fix: Removed autonat causing connection issues, autoTLS no longer needed""
2 parents b169b9d + b958b23 commit 8a84f0e

File tree

7 files changed

+9
-133
lines changed

7 files changed

+9
-133
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitxenia/astradb",
3-
"version": "0.0.29",
3+
"version": "0.1.0",
44
"description": "Database for astrawiki & astrachat ipfs using orbitdb & libp2p",
55
"author": "Bitxenia",
66
"license": "MIT",

src/astradb.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ export class AstraDbNode implements AstraDb {
3030
initOptions.blockstore,
3131
initOptions.publicIp,
3232
initOptions.tcpPort,
33-
initOptions.wsPort,
34-
initOptions.wssPort,
3533
initOptions.webRTCDirectPort,
3634
dataDir
3735
);

src/connectionManager.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ export class ConnectionManager {
5959
});
6060
}
6161

62-
// TODO: searchForProviders & provideDB cause provider connection drops for some reason.
63-
// It seems that it is trying to connect again to the same provider, causing to drop the connection.
64-
// And it seems to happen with dht interactions. So that's why these two functions could be causing the issue.
65-
// That's why we are reconnecting to previously connected providers. See if we can improve this.
6662
this.startService(async () => {
6763
await this.reconnectToProviders();
6864
}, 5000);
@@ -150,9 +146,7 @@ export class ConnectionManager {
150146
private async searchForProviders(): Promise<void> {
151147
// TODO: Check if we need to add a timeout.
152148
try {
153-
let providers = this.ipfs.libp2p.contentRouting.findProviders(
154-
this.providerCID
155-
);
149+
let providers = this.ipfs.routing.findProviders(this.providerCID);
156150
for await (const provider of providers) {
157151
const providerInfo: Provider = {
158152
id: provider.id,

src/index.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,6 @@ export interface AstraDbInit {
7474
*/
7575
tcpPort?: number;
7676

77-
/**
78-
* The websocket port of the node. If astradb is running in a browser, this will be ignored.
79-
*
80-
* It is a TCP port.
81-
*
82-
* @default 40002
83-
*/
84-
wsPort?: number;
85-
86-
/**
87-
* The websocket secure port of the node. If astradb is running in a browser, this will be ignored.
88-
*
89-
* It is a TCP port.
90-
*
91-
* @default 40003
92-
*/
93-
wssPort?: number;
94-
9577
/**
9678
* The WebRTC direct port of the node. If astradb is running in a browser, this will be ignored.
9779
*
@@ -172,8 +154,6 @@ export async function createAstraDb(
172154
initOptions.blockstore = initOptions.blockstore ?? new MemoryBlockstore();
173155
initOptions.publicIp = initOptions.publicIp ?? "0.0.0.0";
174156
initOptions.tcpPort = initOptions.tcpPort ?? 40001;
175-
initOptions.wsPort = initOptions.wsPort ?? 40002;
176-
initOptions.wssPort = initOptions.wssPort ?? 40003;
177157
initOptions.webRTCDirectPort = initOptions.webRTCDirectPort ?? 40001;
178158
initOptions.dataDir = initOptions.dataDir ?? `./data`;
179159
initOptions.bootstrapProviderPeers = initOptions.bootstrapProviderPeers ?? [];

src/utils/libp2pOptions.ts

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,27 @@
11
import { noise } from "@chainsafe/libp2p-noise";
2-
import { tls } from "@libp2p/tls";
32
import { yamux } from "@chainsafe/libp2p-yamux";
43
import { createDelegatedRoutingV1HttpApiClient } from "@helia/delegated-routing-v1-http-api-client";
54
import { delegatedHTTPRoutingDefaults } from "@helia/routers";
6-
import { autoNAT } from "@libp2p/autonat";
75
import { bootstrap } from "@libp2p/bootstrap";
8-
import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
9-
import { dcutr } from "@libp2p/dcutr";
106
import { identify, identifyPush } from "@libp2p/identify";
117
import { kadDHT, removePrivateAddressesMapper } from "@libp2p/kad-dht";
128
import { ping } from "@libp2p/ping";
139
import { tcp } from "@libp2p/tcp";
14-
import { uPnPNAT } from "@libp2p/upnp-nat";
15-
import { webRTC, webRTCDirect } from "@libp2p/webrtc";
10+
import { webRTCDirect } from "@libp2p/webrtc";
1611
import { webSockets } from "@libp2p/websockets";
17-
import { ipnsSelector } from "ipns/selector";
18-
import { ipnsValidator } from "ipns/validator";
19-
import * as filters from "@libp2p/websockets/filters";
20-
import { pubsubPeerDiscovery } from "@libp2p/pubsub-peer-discovery";
2112
import { gossipsub } from "@chainsafe/libp2p-gossipsub";
22-
import { webTransport } from "@libp2p/webtransport";
2313
import { keychain } from "@libp2p/keychain";
24-
import { autoTLS } from "@ipshipyard/libp2p-auto-tls";
2514

2615
export function CreateLibp2pOptions(
2716
publicIP: string,
2817
TcpPort: number,
29-
WSPort: number,
30-
WSSPort: number,
3118
WebRTCDirectPort: number
3219
) {
3320
let appendAnnounce: string[] = [];
3421
// If a public ip was provided, use append announce
3522
if (publicIP != "0.0.0.0") {
3623
appendAnnounce = [
3724
`/ip4/${publicIP}/tcp/${TcpPort}`,
38-
`/ip4/${publicIP}/tcp/${WSPort}/ws`,
39-
`/ip4/${publicIP}/tcp/${WSSPort}/tls/ws`,
4025
`/ip4/${publicIP}/udp/${WebRTCDirectPort}/webrtc-direct`,
4126
];
4227
}
@@ -46,41 +31,16 @@ export function CreateLibp2pOptions(
4631
addresses: {
4732
listen: [
4833
`/ip4/0.0.0.0/tcp/${TcpPort}`,
49-
`/ip4/0.0.0.0/tcp/${WSPort}/ws`,
50-
`/ip4/0.0.0.0/tcp/${WSSPort}/ws`,
5134
`/ip4/0.0.0.0/udp/${WebRTCDirectPort}/webrtc-direct`,
52-
// "/p2p-circuit",
53-
// "/webrtc",
5435
],
5536
// Two websocket adresses are added for auto-tls to work.
5637
// Per: https://github.com/libp2p/js-libp2p/issues/2929
5738
// TODO: Append announce is only needed if upnp does not work. And ports are manually opened.
5839
appendAnnounce: appendAnnounce,
5940
},
60-
transports: [
61-
tcp(),
62-
// circuitRelayTransport(),
63-
// webRTC(),
64-
webRTCDirect(),
65-
// webTransport(),
66-
webSockets(),
67-
],
68-
connectionEncrypters: [
69-
noise(),
70-
// tls()
71-
],
41+
transports: [tcp(), webRTCDirect(), webSockets()],
42+
connectionEncrypters: [noise()],
7243
streamMuxers: [yamux()],
73-
connectionGater: {
74-
denyDialMultiaddr: () => false,
75-
},
76-
connectionManager: {
77-
// With the latest version of libp2p the timeouts for stream upgrades seems to be too aggresive
78-
// https://github.com/libp2p/js-libp2p/issues/2897#issuecomment-2674706509
79-
inboundStreamProtocolNegotiationTimeout: 1e4,
80-
inboundUpgradeTimeout: 1e4,
81-
outboundStreamProtocolNegotiationTimeout: 1e4,
82-
outboundUpgradeTimeout: 1e4,
83-
},
8444
peerDiscovery: [
8545
bootstrap({
8646
list: [
@@ -100,8 +60,6 @@ export function CreateLibp2pOptions(
10060
pubsub: gossipsub({
10161
allowPublishToZeroTopicPeers: true,
10262
}),
103-
autoNAT: autoNAT(),
104-
dcutr: dcutr(),
10563
delegatedRouting: () =>
10664
createDelegatedRoutingV1HttpApiClient(
10765
"https://delegated-ipfs.dev",
@@ -114,19 +72,11 @@ export function CreateLibp2pOptions(
11472
// Server mode makes the node unable to receive connections, I think it is becuase it is always full.
11573
// We do not need server mode anyway.
11674
clientMode: true,
117-
validators: {
118-
ipns: ipnsValidator,
119-
},
120-
selectors: {
121-
ipns: ipnsSelector,
122-
},
12375
}),
12476
identify: identify(),
12577
identifyPush: identifyPush(),
12678
ping: ping(),
127-
upnp: uPnPNAT(),
12879
keychain: keychain(),
129-
autoTLS: autoTLS(),
13080
},
13181
};
13282
}

src/utils/libp2pOptionsBrowser.ts

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,19 @@
11
import { noise } from "@chainsafe/libp2p-noise";
2-
import { tls } from "@libp2p/tls";
32
import { yamux } from "@chainsafe/libp2p-yamux";
43
import { createDelegatedRoutingV1HttpApiClient } from "@helia/delegated-routing-v1-http-api-client";
54
import { delegatedHTTPRoutingDefaults } from "@helia/routers";
65
import { bootstrap } from "@libp2p/bootstrap";
7-
import { circuitRelayTransport } from "@libp2p/circuit-relay-v2";
8-
import { dcutr } from "@libp2p/dcutr";
96
import { identify, identifyPush } from "@libp2p/identify";
107
import { kadDHT, removePrivateAddressesMapper } from "@libp2p/kad-dht";
118
import { ping } from "@libp2p/ping";
12-
import { webRTC, webRTCDirect } from "@libp2p/webrtc";
13-
import { webSockets } from "@libp2p/websockets";
14-
import { ipnsSelector } from "ipns/selector";
15-
import { ipnsValidator } from "ipns/validator";
16-
import * as filters from "@libp2p/websockets/filters";
17-
import { pubsubPeerDiscovery } from "@libp2p/pubsub-peer-discovery";
9+
import { webRTCDirect } from "@libp2p/webrtc";
1810
import { gossipsub } from "@chainsafe/libp2p-gossipsub";
19-
import { webTransport } from "@libp2p/webtransport";
2011

2112
export function CreateLibp2pOptionsBrowser() {
2213
return {
23-
// addresses: {
24-
// listen: ["/p2p-circuit", "/webrtc"],
25-
// },
26-
transports: [
27-
// circuitRelayTransport(),
28-
// webRTC(),
29-
webRTCDirect(),
30-
// webTransport(),
31-
webSockets(),
32-
],
14+
transports: [webRTCDirect()],
3315
connectionEncrypters: [noise()],
3416
streamMuxers: [yamux()],
35-
connectionGater: {
36-
denyDialMultiaddr: () => false,
37-
},
38-
connectionManager: {
39-
// With the latest version of libp2p the timeouts for stream upgrades seems to be too aggresive
40-
// https://github.com/libp2p/js-libp2p/issues/2897#issuecomment-2674706509
41-
inboundStreamProtocolNegotiationTimeout: 1e4,
42-
inboundUpgradeTimeout: 1e4,
43-
outboundStreamProtocolNegotiationTimeout: 1e4,
44-
outboundUpgradeTimeout: 1e4,
45-
},
4617
peerDiscovery: [
4718
bootstrap({
4819
list: [
@@ -62,7 +33,6 @@ export function CreateLibp2pOptionsBrowser() {
6233
pubsub: gossipsub({
6334
allowPublishToZeroTopicPeers: true,
6435
}),
65-
dcutr: dcutr(),
6636
delegatedRouting: () =>
6737
createDelegatedRoutingV1HttpApiClient(
6838
"https://delegated-ipfs.dev",
@@ -72,15 +42,8 @@ export function CreateLibp2pOptionsBrowser() {
7242
// https://github.com/libp2p/js-libp2p/tree/main/packages/kad-dht#example---connecting-to-the-ipfs-amino-dht
7343
protocol: "/ipfs/kad/1.0.0",
7444
peerInfoMapper: removePrivateAddressesMapper,
75-
// Server mode makes the node unable to receive connections, I think it is becuase it is always full.
76-
// We do not need server mode anyway.
45+
// Browser peers should only run the in client mode.
7746
clientMode: true,
78-
validators: {
79-
ipns: ipnsValidator,
80-
},
81-
selectors: {
82-
ipns: ipnsSelector,
83-
},
8447
}),
8548
identify: identify(),
8649
identifyPush: identifyPush(),

src/utils/startOrbitdb.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
toString as uint8ArrayToString,
1313
} from "uint8arrays";
1414
import { privateKeyFromRaw } from "@libp2p/crypto/keys";
15-
import { bootstrap } from "@libp2p/bootstrap";
1615

1716
const USER_ID = "user-id";
1817

@@ -22,8 +21,6 @@ export const startOrbitDb = async (
2221
blockstore: Blockstore,
2322
publicIP: string,
2423
TcpPort: number,
25-
WSPort: number,
26-
WSSPort: number,
2724
WebRTCDirectPort: number,
2825
dataDir: string
2926
) => {
@@ -39,13 +36,7 @@ export const startOrbitDb = async (
3936
if (isBrowser) {
4037
libp2pOptions = CreateLibp2pOptionsBrowser();
4138
} else {
42-
libp2pOptions = CreateLibp2pOptions(
43-
publicIP,
44-
TcpPort,
45-
WSPort,
46-
WSSPort,
47-
WebRTCDirectPort
48-
);
39+
libp2pOptions = CreateLibp2pOptions(publicIP, TcpPort, WebRTCDirectPort);
4940
}
5041

5142
const libp2p = await createLibp2p({

0 commit comments

Comments
 (0)