@libp2p/utils
Advanced tools
Comparing version 3.0.13 to 4.0.0-72e81dc1
@@ -22,3 +22,3 @@ /** | ||
*/ | ||
import type { Address } from '@libp2p/interface-peer-store'; | ||
import type { Address } from '@libp2p/interface/peer-store'; | ||
/** | ||
@@ -25,0 +25,0 @@ * Compare function for array.sort(). |
import { Address4, Address6 } from '@achingbrain/ip-address'; | ||
import { CodeError } from '@libp2p/interfaces/errors'; | ||
import { CodeError } from '@libp2p/interface/errors'; | ||
import { logger } from '@libp2p/logger'; | ||
@@ -4,0 +4,0 @@ import { multiaddr } from '@multiformats/multiaddr'; |
@@ -1,24 +0,5 @@ | ||
import type { MultiaddrConnection } from '@libp2p/interface-connection'; | ||
import type { MultiaddrConnection, Stream } from '@libp2p/interface/connection'; | ||
import type { Multiaddr } from '@multiformats/multiaddr'; | ||
import type { Duplex, Source } from 'it-stream-types'; | ||
import type { Uint8ArrayList } from 'uint8arraylist'; | ||
export interface Timeline { | ||
/** | ||
* Connection opening timestamp | ||
*/ | ||
open: number; | ||
/** | ||
* Connection upgraded timestamp | ||
*/ | ||
upgraded?: number; | ||
/** | ||
* Connection closed timestamp | ||
*/ | ||
close?: number; | ||
} | ||
export interface StreamOptions { | ||
signal?: AbortSignal; | ||
} | ||
export interface StreamProperties { | ||
stream: Duplex<AsyncIterable<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>>; | ||
stream: Stream; | ||
remoteAddr: Multiaddr; | ||
@@ -31,3 +12,3 @@ localAddr: Multiaddr; | ||
*/ | ||
export declare function streamToMaConnection(props: StreamProperties, options?: StreamOptions): MultiaddrConnection; | ||
export declare function streamToMaConnection(props: StreamProperties): MultiaddrConnection; | ||
//# sourceMappingURL=stream-to-ma-conn.d.ts.map |
import { logger } from '@libp2p/logger'; | ||
import { abortableSource } from 'abortable-iterator'; | ||
const log = logger('libp2p:stream:converter'); | ||
@@ -8,3 +7,3 @@ /** | ||
*/ | ||
export function streamToMaConnection(props, options = {}) { | ||
export function streamToMaConnection(props) { | ||
const { stream, remoteAddr } = props; | ||
@@ -24,8 +23,5 @@ const { sink, source } = stream; | ||
async sink(source) { | ||
if (options.signal != null) { | ||
source = abortableSource(source, options.signal); | ||
} | ||
try { | ||
await sink(source); | ||
await close(); | ||
close(); | ||
} | ||
@@ -42,17 +38,18 @@ catch (err) { | ||
}, | ||
source: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource, | ||
source: mapSource, | ||
remoteAddr, | ||
timeline: { open: Date.now(), close: undefined }, | ||
async close() { | ||
await sink(async function* () { | ||
yield new Uint8Array(0); | ||
}()); | ||
await close(); | ||
async close(options) { | ||
close(); | ||
await stream.close(options); | ||
}, | ||
abort(err) { | ||
close(); | ||
stream.abort(err); | ||
} | ||
}; | ||
async function close() { | ||
function close() { | ||
if (maConn.timeline.close == null) { | ||
maConn.timeline.close = Date.now(); | ||
} | ||
await Promise.resolve(); | ||
} | ||
@@ -59,0 +56,0 @@ return maConn; |
118
package.json
{ | ||
"name": "@libp2p/utils", | ||
"version": "3.0.13", | ||
"version": "4.0.0-72e81dc1", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
"license": "Apache-2.0 OR MIT", | ||
"homepage": "https://github.com/libp2p/js-libp2p-utils#readme", | ||
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/utils#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/libp2p/js-libp2p-utils.git" | ||
"url": "git+https://github.com/libp2p/js-libp2p.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/libp2p/js-libp2p-utils/issues" | ||
"url": "https://github.com/libp2p/js-libp2p/issues" | ||
}, | ||
"engines": { | ||
"node": ">=16.0.0", | ||
"npm": ">=7.0.0" | ||
}, | ||
"type": "module", | ||
@@ -78,87 +74,2 @@ "types": "./dist/src/index.d.ts", | ||
}, | ||
"release": { | ||
"branches": [ | ||
"master" | ||
], | ||
"plugins": [ | ||
[ | ||
"@semantic-release/commit-analyzer", | ||
{ | ||
"preset": "conventionalcommits", | ||
"releaseRules": [ | ||
{ | ||
"breaking": true, | ||
"release": "major" | ||
}, | ||
{ | ||
"revert": true, | ||
"release": "patch" | ||
}, | ||
{ | ||
"type": "feat", | ||
"release": "minor" | ||
}, | ||
{ | ||
"type": "fix", | ||
"release": "patch" | ||
}, | ||
{ | ||
"type": "docs", | ||
"release": "patch" | ||
}, | ||
{ | ||
"type": "test", | ||
"release": "patch" | ||
}, | ||
{ | ||
"type": "deps", | ||
"release": "patch" | ||
}, | ||
{ | ||
"scope": "no-release", | ||
"release": false | ||
} | ||
] | ||
} | ||
], | ||
[ | ||
"@semantic-release/release-notes-generator", | ||
{ | ||
"preset": "conventionalcommits", | ||
"presetConfig": { | ||
"types": [ | ||
{ | ||
"type": "feat", | ||
"section": "Features" | ||
}, | ||
{ | ||
"type": "fix", | ||
"section": "Bug Fixes" | ||
}, | ||
{ | ||
"type": "chore", | ||
"section": "Trivial Changes" | ||
}, | ||
{ | ||
"type": "docs", | ||
"section": "Documentation" | ||
}, | ||
{ | ||
"type": "deps", | ||
"section": "Dependencies" | ||
}, | ||
{ | ||
"type": "test", | ||
"section": "Tests" | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"@semantic-release/changelog", | ||
"@semantic-release/npm", | ||
"@semantic-release/github", | ||
"@semantic-release/git" | ||
] | ||
}, | ||
"scripts": { | ||
@@ -169,3 +80,2 @@ "clean": "aegir clean", | ||
"build": "aegir build", | ||
"docs": "aegir docs", | ||
"test": "aegir test", | ||
@@ -177,25 +87,21 @@ "test:chrome": "aegir test -t browser --cov", | ||
"test:node": "aegir test -t node --cov", | ||
"test:electron-main": "aegir test -t electron-main", | ||
"release": "aegir release" | ||
"test:electron-main": "aegir test -t electron-main" | ||
}, | ||
"dependencies": { | ||
"@achingbrain/ip-address": "^8.1.0", | ||
"@libp2p/interface-connection": "^5.0.1", | ||
"@libp2p/interface-peer-store": "^2.0.0", | ||
"@libp2p/interfaces": "^3.2.0", | ||
"@libp2p/logger": "^2.0.0", | ||
"@multiformats/multiaddr": "^12.0.0", | ||
"abortable-iterator": "^5.0.0", | ||
"@libp2p/interface": "0.1.0-72e81dc1", | ||
"@libp2p/logger": "3.0.0-72e81dc1", | ||
"@multiformats/multiaddr": "^12.1.3", | ||
"is-loopback-addr": "^2.0.1", | ||
"it-stream-types": "^2.0.1", | ||
"private-ip": "^3.0.0", | ||
"uint8arraylist": "^2.3.2" | ||
"uint8arraylist": "^2.4.3" | ||
}, | ||
"devDependencies": { | ||
"aegir": "^40.0.0", | ||
"aegir": "^40.0.1", | ||
"it-all": "^3.0.1", | ||
"it-pair": "^2.0.6", | ||
"it-pipe": "^3.0.0", | ||
"uint8arrays": "^4.0.2" | ||
"it-pipe": "^3.0.1", | ||
"uint8arrays": "^4.0.4" | ||
} | ||
} |
@@ -5,4 +5,4 @@ # @libp2p/utils <!-- omit in toc --> | ||
[](https://discuss.libp2p.io) | ||
[](https://codecov.io/gh/libp2p/js-libp2p-utils) | ||
[](https://github.com/libp2p/js-libp2p-utils/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) | ||
[](https://codecov.io/gh/libp2p/js-libp2p) | ||
[](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster) | ||
@@ -55,3 +55,3 @@ > Package to aggregate shared logic and dependencies for the libp2p ecosystem | ||
- <https://libp2p.github.io/js-libp2p-utils> | ||
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_utils.html> | ||
@@ -58,0 +58,0 @@ ## License |
@@ -24,3 +24,3 @@ /** | ||
import { isPrivate } from './multiaddr/is-private.js' | ||
import type { Address } from '@libp2p/interface-peer-store' | ||
import type { Address } from '@libp2p/interface/peer-store' | ||
@@ -27,0 +27,0 @@ /** |
import { Address4, Address6 } from '@achingbrain/ip-address' | ||
import { CodeError } from '@libp2p/interfaces/errors' | ||
import { CodeError } from '@libp2p/interface/errors' | ||
import { logger } from '@libp2p/logger' | ||
@@ -4,0 +4,0 @@ import { type Multiaddr, multiaddr } from '@multiformats/multiaddr' |
import { logger } from '@libp2p/logger' | ||
import { abortableSource } from 'abortable-iterator' | ||
import type { MultiaddrConnection } from '@libp2p/interface-connection' | ||
import type { AbortOptions } from '@libp2p/interface' | ||
import type { MultiaddrConnection, Stream } from '@libp2p/interface/connection' | ||
import type { Multiaddr } from '@multiformats/multiaddr' | ||
import type { Duplex, Source } from 'it-stream-types' | ||
import type { Uint8ArrayList } from 'uint8arraylist' | ||
const log = logger('libp2p:stream:converter') | ||
export interface Timeline { | ||
/** | ||
* Connection opening timestamp | ||
*/ | ||
open: number | ||
/** | ||
* Connection upgraded timestamp | ||
*/ | ||
upgraded?: number | ||
/** | ||
* Connection closed timestamp | ||
*/ | ||
close?: number | ||
} | ||
export interface StreamOptions { | ||
signal?: AbortSignal | ||
} | ||
export interface StreamProperties { | ||
stream: Duplex<AsyncIterable<Uint8ArrayList>, Source<Uint8ArrayList | Uint8Array>> | ||
stream: Stream | ||
remoteAddr: Multiaddr | ||
@@ -42,3 +18,3 @@ localAddr: Multiaddr | ||
*/ | ||
export function streamToMaConnection (props: StreamProperties, options: StreamOptions = {}): MultiaddrConnection { | ||
export function streamToMaConnection (props: StreamProperties): MultiaddrConnection { | ||
const { stream, remoteAddr } = props | ||
@@ -59,9 +35,5 @@ const { sink, source } = stream | ||
async sink (source) { | ||
if (options.signal != null) { | ||
source = abortableSource(source, options.signal) | ||
} | ||
try { | ||
await sink(source) | ||
await close() | ||
close() | ||
} catch (err: any) { | ||
@@ -77,18 +49,19 @@ // If aborted we can safely ignore | ||
}, | ||
source: (options.signal != null) ? abortableSource(mapSource, options.signal) : mapSource, | ||
source: mapSource, | ||
remoteAddr, | ||
timeline: { open: Date.now(), close: undefined }, | ||
async close () { | ||
await sink(async function * () { | ||
yield new Uint8Array(0) | ||
}()) | ||
await close() | ||
async close (options?: AbortOptions) { | ||
close() | ||
await stream.close(options) | ||
}, | ||
abort (err: Error): void { | ||
close() | ||
stream.abort(err) | ||
} | ||
} | ||
async function close (): Promise<void> { | ||
function close (): void { | ||
if (maConn.timeline.close == null) { | ||
maConn.timeline.close = Date.now() | ||
} | ||
await Promise.resolve() | ||
} | ||
@@ -95,0 +68,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8
28925
39
494
1
+ Added@libp2p/interface@0.1.0-72e81dc1(transitive)
+ Added@libp2p/logger@3.0.0-72e81dc1(transitive)
+ Addedit-pushable@3.2.3(transitive)
+ Addedmultiformats@12.1.3(transitive)
+ Addedp-defer@4.0.1(transitive)
- Removed@libp2p/interface-connection@^5.0.1
- Removed@libp2p/interface-peer-store@^2.0.0
- Removed@libp2p/interfaces@^3.2.0
- Removedabortable-iterator@^5.0.0
- Removed@libp2p/interface-connection@5.1.1(transitive)
- Removed@libp2p/interface-peer-id@2.0.2(transitive)
- Removed@libp2p/interface-peer-store@2.0.4(transitive)
- Removed@libp2p/interfaces@3.3.2(transitive)
- Removed@libp2p/logger@2.1.1(transitive)
- Removedmultiformats@11.0.2(transitive)
Updateduint8arraylist@^2.4.3