@@ -118,146 +118,7 @@ $ node
118
118
119
119
## API
120
120
121
- ``` js
122
- const multiaddr = require (' multiaddr' )
123
- ```
124
-
125
- ### Create
126
-
127
- #### const addr = multiaddr(str)
128
-
129
- Creates a multiaddress from a string (e.g. ` /ip4/127.0.0.1/udp/1234 ` ).
130
-
131
- #### const addr = multiaddr(buf)
132
-
133
- Creates a multiaddress from another multiaddress' raw bytes.
134
-
135
- #### addr.buffer
136
-
137
- The raw bytes representing this multiaddress.
138
-
139
- #### addr.toString()
140
-
141
- The multiaddress in string format (e.g. ` /ip4/127.0.0.1/udp/1234 ` ).
142
-
143
- ### Protocols
144
-
145
- #### addr.protoCodes()
146
-
147
- Returns the codes of the protocols in the multiaddress, in left-to-right order.
148
-
149
- ``` js
150
- addr .protoCodes ()
151
- // [4, 6]
152
- ```
153
-
154
- #### addr.protoNames()
155
-
156
- Returns the names of the protocols in the multiaddress, in left-to-right order.
157
-
158
- ``` js
159
- addr .protoNames ()
160
- // ['ip4', 'tcp']
161
- ```
162
-
163
- #### addr.protos()
164
-
165
- Returns description objects of the protocols in the multiaddress, in left-to-right order.
166
-
167
- ``` js
168
- addr .protos ()
169
- // [
170
- // { code: 4, name: 'ip4', size: 32},
171
- // { code: 17, name: 'udp', size: 16}
172
- // ]
173
- ```
174
-
175
- Each object contains the protocol code, protocol name, and the size of its
176
- address space in bits.
177
-
178
- ### Node-Friendly Addresses
179
-
180
- Utility functions for getting NodeJS-friendly address information from a
181
- multiaddress.
182
-
183
- #### addr.nodeAddress()
184
-
185
- Returns a NodeJS-friendly object describing the left-most address in the
186
- multiaddress.
187
-
188
- ``` js
189
- addr .nodeAddress ()
190
- // { family: "IPv4", port:1234, address: "127.0.0.1" }
191
- ```
192
-
193
- Note that protocol information is left out: in Node (and most network systems)
194
- the protocol is unknowable given only the address.
195
-
196
- #### addr.fromNodeAddress(addr)
197
-
198
- Constructs a multiaddress, given a NodeJS-friendly address object and a protocol.
199
-
200
- ``` js
201
- addr .fromNodeAddress ({family: " IPv4" , port: 1234 , address: " 127.0.0.1" }, ' udp' )
202
- // <Multiaddr /ip4/127.0.0.1/udp/1234>
203
- ```
204
-
205
- #### addr.fromStupidString(str)
206
-
207
- Returns a multiaddress, given a URI in the format `<proto ><IPv >://<IP
208
- Addr>[ :<proto port >] `
209
-
210
- ``` js
211
- addr = multiaddr .fromStupidString (" udp4://127.0.0.1:1234" )
212
- // <Multiaddr /ip4/127.0.0.1/udp/1234>
213
- ```
214
-
215
- * NOT IMPLEMENTED*
216
-
217
- #### addr.toStupidString()
218
-
219
- * NOT IMPLEMENTED*
220
-
221
- ### En/decapsulate
222
-
223
- #### addr.encapsulate(str)
224
-
225
- Returns a new multiaddress that encapsulates ` addr ` in a new protocol string,
226
- ` str ` .
227
-
228
- ``` js
229
- addr .encapsulate (' /sctp/5678' )
230
- // <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
231
- ```
232
-
233
- #### addr.decapsulate(str)
234
-
235
- Returns a new multiaddress with the right-most protocol string ` str ` removed.
236
-
237
- ``` js
238
- multiaddress (' /ip4/127.0.0.1/udp/1234' ).decapsulate (' /udp' )
239
- // <Multiaddr /ip4/127.0.0.1>
240
- ```
241
-
242
- ### Tunneling
243
-
244
- Given these encapsulation/decapsulate tools, multiaddresses lend
245
- themselves to expressing tunnels very nicely:
246
-
247
- ``` js
248
- const printer = multiaddr (' /ip4/192.168.0.13/tcp/80' )
249
-
250
- const proxy = multiaddr (' /ip4/10.20.30.40/tcp/443' )
251
-
252
- const printerOverProxy = proxy .encapsulate (printer)
253
- // <Multiaddr /ip4/10.20.30.40/tcp/443/ip4/192.168.0.13/tcp/80>
254
- ```
255
-
256
- ### Misc
257
-
258
- #### ` multiaddr.isMultiaddr(addr) `
259
-
260
- Returns ` true ` if the passed in ` addr ` is a valid ` multiaddr ` .
121
+ TODO: Moved to API-docs, insert link here
261
122
262
123
## Maintainers
263
124
0 commit comments