Skip to content

Commit c6e8f34

Browse files
wemeetagainmaschad
authored andcommitted
refactor!: move autonat into separate package (#2107)
Co-authored-by: chad <[email protected]>
1 parent ae9843a commit c6e8f34

File tree

28 files changed

+226
-135
lines changed

28 files changed

+226
-135
lines changed

doc/CONFIGURATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ For more information see https://docs.libp2p.io/concepts/nat/autonat/#what-is-au
930930

931931
```ts
932932
import { createLibp2p } from 'libp2p'
933-
import { autoNATService } from 'libp2p/autonat'
933+
import { autoNATService } from '@libp2p/autonat'
934934

935935
const node = await createLibp2p({
936936
services: {

doc/migrations/v0.46-v1.0.0.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
<!--Specify versions for migration below-->
12
# Migrating to [email protected] <!-- omit in toc -->
23

34
A migration guide for refactoring your application code from libp2p `v0.46` to `v1.0.0`.
45

56
## Table of Contents <!-- omit in toc -->
67

7-
- [New features](#new-features)
8-
- [Breaking changes](#breaking-changes)
8+
- [AutoNAT](#autonat)
99
- [KeyChain](#keychain)
1010
- [Metrics](#metrics)
1111

12-
## New features
12+
## AutoNAT
1313

14-
...
14+
The AutoNAT service is now published in its own package.
1515

16-
## Breaking changes
16+
**Before**
1717

1818
```ts
1919
import { autoNATService } from 'libp2p/autonat'

doc/migrations/v0.46-v1.0.md

Lines changed: 0 additions & 85 deletions
This file was deleted.

packages/interface/src/errors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,7 @@ export class InvalidCryptoTransmissionError extends Error {
6565

6666
static readonly code = 'ERR_INVALID_CRYPTO_TRANSMISSION'
6767
}
68+
69+
// Error codes
70+
71+
export const ERR_TIMEOUT = 'ERR_TIMEOUT'

packages/libp2p/package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@
4848
"types": "./dist/src/index.d.ts",
4949
"import": "./dist/src/index.js"
5050
},
51-
"./autonat": {
52-
"types": "./dist/src/autonat/index.d.ts",
53-
"import": "./dist/src/autonat/index.js"
54-
},
5551
"./circuit-relay": {
5652
"types": "./dist/src/circuit-relay/index.d.ts",
5753
"import": "./dist/src/circuit-relay/index.js"
@@ -104,7 +100,6 @@
104100
"prepublishOnly": "node scripts/update-version.js && npm run build",
105101
"build": "aegir build",
106102
"generate": "run-s generate:proto:*",
107-
"generate:proto:autonat": "protons ./src/autonat/pb/index.proto",
108103
"generate:proto:circuit-relay": "protons ./src/circuit-relay/pb/index.proto",
109104
"generate:proto:dcutr": "protons ./src/dcutr/pb/message.proto",
110105
"generate:proto:fetch": "protons ./src/fetch/pb/proto.proto",
@@ -149,7 +144,6 @@
149144
"it-map": "^3.0.3",
150145
"it-merge": "^3.0.0",
151146
"it-pair": "^2.0.6",
152-
"it-parallel": "^3.0.0",
153147
"it-pipe": "^3.0.1",
154148
"it-protobuf-stream": "^1.0.0",
155149
"it-stream-types": "^2.0.1",

packages/libp2p/src/connection-manager/dial-queue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setMaxListeners } from 'events'
2-
import { AbortError, CodeError } from '@libp2p/interface/errors'
2+
import { AbortError, CodeError, ERR_TIMEOUT } from '@libp2p/interface/errors'
33
import { logger } from '@libp2p/logger'
44
import { defaultAddressSort } from '@libp2p/utils/address-sort'
55
import { type Multiaddr, type Resolver, resolvers } from '@multiformats/multiaddr'
@@ -250,7 +250,7 @@ export class DialQueue {
250250

251251
// Error is a timeout
252252
if (signal.aborted) {
253-
const error = new CodeError(err.message, codes.ERR_TIMEOUT)
253+
const error = new CodeError(err.message, ERR_TIMEOUT)
254254
throw error
255255
}
256256

packages/libp2p/src/content-routing/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CodeError } from '@libp2p/interface/errors'
22
import merge from 'it-merge'
33
import { pipe } from 'it-pipe'
4-
import { messages, codes } from '../errors.js'
4+
import { codes, messages } from '../errors.js'
55
import {
66
storeAddresses,
77
uniquePeers,

packages/libp2p/src/errors.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export enum codes {
3737
ERR_INVALID_PEER = 'ERR_INVALID_PEER',
3838
ERR_MUXER_UNAVAILABLE = 'ERR_MUXER_UNAVAILABLE',
3939
ERR_NOT_FOUND = 'ERR_NOT_FOUND',
40-
ERR_TIMEOUT = 'ERR_TIMEOUT',
4140
ERR_TRANSPORT_UNAVAILABLE = 'ERR_TRANSPORT_UNAVAILABLE',
4241
ERR_TRANSPORT_DIAL_FAILED = 'ERR_TRANSPORT_DIAL_FAILED',
4342
ERR_UNSUPPORTED_PROTOCOL = 'ERR_UNSUPPORTED_PROTOCOL',

packages/libp2p/src/fetch/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setMaxListeners } from 'events'
2-
import { CodeError } from '@libp2p/interface/errors'
2+
import { CodeError, ERR_TIMEOUT } from '@libp2p/interface/errors'
33
import { logger } from '@libp2p/logger'
44
import first from 'it-first'
55
import * as lp from 'it-length-prefixed'
@@ -158,7 +158,7 @@ class DefaultFetchService implements Startable, FetchService {
158158
})
159159

160160
onAbort = () => {
161-
stream?.abort(new CodeError('fetch timeout', codes.ERR_TIMEOUT))
161+
stream?.abort(new CodeError('fetch timeout', ERR_TIMEOUT))
162162
}
163163

164164
// make stream abortable

packages/libp2p/src/ping/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { randomBytes } from '@libp2p/crypto'
2-
import { CodeError } from '@libp2p/interface/errors'
2+
import { CodeError, ERR_TIMEOUT } from '@libp2p/interface/errors'
33
import { logger } from '@libp2p/logger'
44
import first from 'it-first'
55
import { pipe } from 'it-pipe'
@@ -118,7 +118,7 @@ class DefaultPingService implements Startable, PingService {
118118
})
119119

120120
onAbort = () => {
121-
stream?.abort(new CodeError('ping timeout', codes.ERR_TIMEOUT))
121+
stream?.abort(new CodeError('ping timeout', ERR_TIMEOUT))
122122
}
123123

124124
// make stream abortable

0 commit comments

Comments
 (0)