@@ -8,38 +8,40 @@ weight: 33
8
8
9
9
A libp2p connection allows two peers to read and write data to each other.
10
10
Peers connect over [ transport protocols] ( ../transports/overview.md ) , which are
11
- core abstractions of libp2p and offer extensibility. As a modular networking stack,
12
- libp2p is transport-agnostic and does not enforce the implementation of a specific
13
- transport protocol. Though the support of modern transport protocols is a primary
14
- focus for libp2p, implementers may support multiple types of transport. This document
15
- does not cover establishing "transport level" connections, for example, opening "raw"
16
- TCP sockets, as those semantics are specific to each transport. Rather, this document
17
- explains the process that occurs after making the initial transport-level connection,
18
- up to the point where "application level" streams are opened. Learn about transport
19
- protocols in libp2p in the [ transport section] ( ../transports/overview/ ) .
11
+ core abstractions of libp2p and offer extensibility.
12
+ This document does not cover establishing "transport level" connections, for example,
13
+ opening "raw" TCP sockets, as those semantics are specific to each transport. Rather,
14
+ this document explains the process that occurs after making the initial transport-level
15
+ connection, up to the point where "application level" streams are opened.
16
+ Learn about transport protocols in libp2p in the [ transport section] ( ../transports/overview/ ) .
20
17
21
18
## Life of a libp2p connection
22
19
23
- The following points present an overview for a standard libp2p connection:
20
+ The following points present an overview for a standard libp2p connection; we'll then dive
21
+ more into the various components later in the document.
24
22
25
23
- A libp2p node (peer) initiates a connection with another node by sending
26
24
a request over the underlying transport protocol (e.g., TCP). This request
27
- is referred to as "dialing."
25
+ is referred to as "dialing", and the peer is referred to as the "dialer ."
28
26
- The receiving node, known as the "listener", accepts the incoming connection
29
27
request and responds with a handshake message to initiate the protocol negotiation
30
28
process.
31
29
- Both nodes exchange protocol information and select the protocols to use for the
32
- connection, including protocols for security and stream multiplexing if necessary.
33
- The multistream-select protocol is used for this negotiation process.
30
+ connection, including protocols for [ security] ( ../secure-comm/overview.md ) and
31
+ [ stream multiplexing] ( ../multiplex/overview.md ) if necessary.
32
+ The [ multistream-select] ( https://github.com/multiformats/multistream-select ) is used
33
+ for this negotiation process.
34
34
- If the underlying transport protocol does not natively support security and multiplexing,
35
35
a connection upgrade is performed to add these capabilities to the raw transport connection.
36
- The peers may use NAT traversal techniques such as UPnP or hole punching to allow nodes
37
- behind NAT devices to establish connections.
36
+ The peers may use NAT traversal techniques such as
37
+ [ UPnP] ( https://en.wikipedia.org/wiki/Universal_Plug_and_Play ) or
38
+ [ hole punching] ( ../nat/hole-punching.md ) to allow nodes behind NAT devices to establish
39
+ connections.
38
40
- Once the connection is established, and protocols are selected, the nodes can open multiple
39
41
streams over the connection for various interactions, each using its own protocol.
40
42
- Data is exchanged over the streams using the negotiated protocols.
41
- - When a node wants to close the connection or a stream, it sends a close message to the other
42
- node, which responds with an acknowledgment message.
43
+ - When a node wants to close the connection or a stream, it sends a " close" message to the other
44
+ node, which responds with an " acknowledgment" message.
43
45
- Once both nodes have sent and received the close message and acknowledgment, the connection
44
46
or stream is closed.
45
47
@@ -98,8 +100,8 @@ important to consider compatibility with existing protocols, performance, and se
98
100
99
101
libp2p is designed to support a variety of transport protocols, including those that do
100
102
not natively support the core libp2p capabilities of security and stream multiplexing.
101
- The process of layering capabilities onto "raw" transport connections is called "upgrading"
102
- the connection.
103
+ The process of layering capabilities onto "raw" transport connections is known as
104
+ "upgrading" the connection.
103
105
104
106
The listener's multiaddr determines the security protocol to be used on a connection
105
107
(see [ addressing specification] ). The multiplexing protocol is determined using protocol
@@ -153,17 +155,16 @@ version, but they may also choose to support older versions for compatibility. M
153
155
protocols is available on the [ protocols document] ( protocols.md ) .
154
156
155
157
Protocol negotiation works by one peer sending a message containing the protocol ID of the
156
- protocol it wishes to use, and the other either echoing back the same id if it supports
157
- the protocol or sending a different id if it does not. This process continues until both
158
+ protocol it wishes to use, and the other either echoing back the same ID if it supports
159
+ the protocol or sending a different ID if it does not. This process continues until both
158
160
peers agree on a common protocol to use or determine that no common protocol is available.
159
161
160
162
For example, consider a case where two libp2p nodes are attempting to upgrade a
161
163
raw transport connection to a secure libp2p connection using the Noise protocol:
162
164
163
165
- The dialing peer sends a message containing the protocol ID ` /noise/1.0.0 ` to
164
- - indicate its desire to use the Noise protocol.
165
- - The listening peer supports the Noise protocol,
166
- which echoes the same protocol ID.
166
+ indicate its desire to use the Noise protocol.
167
+ - The listening peer supports the Noise protocol, which echoes the same protocol ID.
167
168
- Both peers perform the Noise handshake to establish a secure connection.
168
169
169
170
> If the listening peer did not support the Noise protocol, it would have responded
0 commit comments