@libp2p/utils
Advanced tools
Comparing version 3.0.12-ab0e3980 to 3.0.12-b36ec7f2
@@ -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; |
{ | ||
"name": "@libp2p/utils", | ||
"version": "3.0.12-ab0e3980", | ||
"version": "3.0.12-b36ec7f2", | ||
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem", | ||
@@ -89,8 +89,5 @@ "license": "Apache-2.0 OR MIT", | ||
"@achingbrain/ip-address": "^8.1.0", | ||
"@libp2p/interface-connection": "5.1.1-ab0e3980", | ||
"@libp2p/interface-peer-store": "2.0.4-ab0e3980", | ||
"@libp2p/interfaces": "3.3.2-ab0e3980", | ||
"@libp2p/logger": "2.1.1-ab0e3980", | ||
"@libp2p/interface": "0.0.1-b36ec7f2", | ||
"@libp2p/logger": "2.1.1-b36ec7f2", | ||
"@multiformats/multiaddr": "^12.1.3", | ||
"abortable-iterator": "^5.0.1", | ||
"is-loopback-addr": "^2.0.1", | ||
@@ -102,7 +99,7 @@ "it-stream-types": "^2.0.1", | ||
"devDependencies": { | ||
"aegir": "^39.0.10", | ||
"aegir": "^39.0.13", | ||
"it-all": "^3.0.1", | ||
"it-pair": "^2.0.6", | ||
"it-pipe": "^3.0.1", | ||
"uint8arrays": "^4.0.3" | ||
"uint8arrays": "^4.0.4" | ||
}, | ||
@@ -109,0 +106,0 @@ "typedoc": { |
@@ -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
8
28963
494
+ Added@libp2p/interface@0.0.1-b36ec7f2(transitive)
+ Added@libp2p/logger@2.1.1-b36ec7f2(transitive)
+ Addedit-pushable@3.2.3(transitive)
+ Addedmultiformats@12.1.3(transitive)
+ Addedp-defer@4.0.1(transitive)
+ Addedp-queue@8.1.0(transitive)
- Removed@libp2p/interfaces@3.3.2-ab0e3980
- Removedabortable-iterator@^5.0.1
- Removed@libp2p/interface-connection@5.1.1-ab0e3980(transitive)
- Removed@libp2p/interface-peer-id@2.0.2-ab0e3980(transitive)
- Removed@libp2p/interface-peer-store@2.0.4-ab0e3980(transitive)
- Removed@libp2p/interfaces@3.3.2-ab0e3980(transitive)
- Removed@libp2p/logger@2.1.1-ab0e3980(transitive)
- Removedmultiformats@11.0.2(transitive)
- Removedp-queue@8.0.1(transitive)