You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add support for arbitrary service modules (#1563)
Updates the libp2p init args to accept an object of service
factory functions that can use internal libp2p components.
The returned libp2p object has a `.services` key that corresponds
to the service factory keys.
---------
Co-authored-by: achingbrain <[email protected]>
If none of the available content routing protocols fulfills your needs, you can create a libp2p compatible one. A libp2p content routing protocol just needs to be compliant with the [Content Routing Interface](https://github.com/libp2p/js-interfaces/tree/master/src/content-routing).**(WIP: This module is not yet implemented)**
147
+
If none of the available content routing protocols fulfil your needs, you can create a libp2p compatible one. A libp2p content routing protocol just needs to be compliant with the [Content Routing Interface](https://github.com/libp2p/js-interfaces/tree/master/src/content-routing).
147
148
148
149
If you want to know more about libp2p content routing, you should read the following content:
Network Address Translation (NAT) is a function performed by your router to enable multiple devices on your local network to share a single IPv4 address. It's done transparently for outgoing connections, ensuring the correct response traffic is routed to your computer, but if you wish to accept incoming connections some configuration is necessary.
850
860
851
-
The NAT manager can be configured as follows:
861
+
Some home routers support [UPnP NAT](https://en.wikipedia.org/wiki/Universal_Plug_and_Play) which allows network devices to request traffic to be forwarded from public facing ports that would otherwise be firewalled.
862
+
863
+
If your router supports this, libp2p can be configured to use it as follows:
852
864
853
865
```js
866
+
import { createLibp2p } from'libp2p'
867
+
import { uPnPNAT } from'libp2p/upnp-nat'
868
+
854
869
constnode=awaitcreateLibp2p({
855
-
config: {
856
-
nat: {
857
-
enabled:true, // defaults to true
870
+
services: {
871
+
nat:uPnPNAT({
858
872
description:'my-node', // set as the port mapping description on the router, defaults the current libp2p version and your peer id
859
873
gateway:'192.168.1.1', // leave unset to auto-discover
860
874
externalIp:'80.1.1.1', // leave unset to auto-discover
861
875
localAddress:'129.168.1.123', // leave unset to auto-discover
862
876
ttl:7200, // TTL for port mappings (min 20 minutes)
863
877
keepAlive:true, // Refresh port mapping after TTL expires
864
-
}
878
+
})
865
879
}
866
880
})
867
881
```
@@ -881,12 +895,18 @@ By default under nodejs libp2p will attempt to use [UPnP](https://en.wikipedia.o
881
895
Changing the protocol name prefix can isolate default public network (IPFS) for custom purposes.
Copy file name to clipboardExpand all lines: doc/LIMITS.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ We can also limit the number of connections in a "pending" state. These connecti
29
29
All fields are optional. The default values are defined in [src/connection-manager/index.ts](https://github.com/libp2p/js-libp2p/blob/master/src/connection-manager/index.ts) - please see that file for the current values.
30
30
31
31
```ts
32
-
const node =awaitcreateLibp2pNode({
32
+
const node =awaitcreateLibp2p({
33
33
connectionManager: {
34
34
/**
35
35
* The total number of connections allowed to be open at one time
@@ -69,7 +69,7 @@ To prevent individual peers from opening multiple connections to a node, an `inb
69
69
All fields are optional. The default values are defined in [src/connection-manager/index.ts](https://github.com/libp2p/js-libp2p/blob/master/src/connection-manager/index.ts) - please see that file for the current values.
70
70
71
71
```ts
72
-
const node =awaitcreateLibp2pNode({
72
+
const node =awaitcreateLibp2p({
73
73
connectionManager: {
74
74
/**
75
75
* A remote peer may attempt to open up to this many connections per second,
@@ -93,7 +93,7 @@ These settings are done on a per-muxer basis, please see the README of the relev
93
93
All fields are optional. The default values are defined in [@libp2p/mplex/src/mplex.ts](https://github.com/libp2p/js-libp2p-mplex/blob/master/src/mplex.ts) - please see that file for the current values.
All fields are optional. The default values are defined in [@chainsafe/libp2p-yamux/src/config.ts](https://github.com/ChainSafe/js-libp2p-yamux/blob/master/src/config.ts) - please see that file for the current values.
134
134
135
135
```ts
136
-
const node =awaitcreateLibp2pNode({
136
+
const node =awaitcreateLibp2p({
137
137
muxers: [
138
138
yamux({
139
139
/**
@@ -186,7 +186,7 @@ The [@libp2p/tcp](https://github.com/libp2p/js-libp2p-tcp) transport allows addi
186
186
All fields are optional. The full list of options is defined in [@libp2p/tcp/src/index.ts](https://github.com/libp2p/js-libp2p-tcp/blob/master/src/index.ts) - please see that file for more details.
Copy file name to clipboardExpand all lines: doc/migrations/v0.44-v0.45.md
+70Lines changed: 70 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ A migration guide for refactoring your application code from libp2p v0.44.x to v
4
4
5
5
## Table of Contents <!-- omit in toc -->
6
6
7
+
-[Services](#services)
7
8
-[Events](#events)
8
9
-[Emitters](#emitters)
9
10
-[Event changes](#event-changes)
@@ -13,6 +14,75 @@ A migration guide for refactoring your application code from libp2p v0.44.x to v
13
14
-[`self:peer:update`](#selfpeerupdate)
14
15
-[Atomic peer store methods](#atomic-peer-store-methods)
15
16
17
+
## Services
18
+
19
+
libp2p now accepts arbitrary service modules that can use internal components to fulfil their functions.
20
+
21
+
This reduces the attack surface area of libp2p nodes as less functionality is enabled by default, and with tree shaking less code will be included in bundles making for faster downloads when used in browsers.
22
+
23
+
Several optional modules have been removed and must now be configured as services:
0 commit comments