Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/utils

Package Overview
Dependencies
Maintainers
6
Versions
561
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/utils - npm Package Compare versions

Comparing version 3.0.12-6fdaa7dc to 3.0.12-791f56f0

25

dist/src/stream-to-ma-conn.d.ts

@@ -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

25

dist/src/stream-to-ma-conn.js
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-6fdaa7dc",
"version": "3.0.12-791f56f0",
"description": "Package to aggregate shared logic and dependencies for the libp2p ecosystem",

@@ -89,6 +89,5 @@ "license": "Apache-2.0 OR MIT",

"@achingbrain/ip-address": "^8.1.0",
"@libp2p/interface": "0.0.1-6fdaa7dc",
"@libp2p/logger": "2.1.1-6fdaa7dc",
"@libp2p/interface": "0.0.1-791f56f0",
"@libp2p/logger": "2.1.1-791f56f0",
"@multiformats/multiaddr": "^12.1.3",
"abortable-iterator": "^5.0.1",
"is-loopback-addr": "^2.0.1",

@@ -100,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"
},

@@ -107,0 +106,0 @@ "typedoc": {

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc