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

@libp2p/interface

Package Overview
Dependencies
Maintainers
6
Versions
518
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/interface - npm Package Compare versions

Comparing version 0.0.1-daeb43d8 to 0.0.1-e9cafd3d

86

dist/src/connection/index.d.ts

@@ -13,27 +13,5 @@ import type * as Status from './status.js';

/**
* Outbound conections are opened by the local node, inbound streams are opened by the remote
* Outbound connections are opened by the local node, inbound streams are opened by the remote
*/
export type Direction = 'inbound' | 'outbound';
export interface ConnectionStat {
/**
* Outbound conections are opened by the local node, inbound streams are opened by the remote
*/
direction: Direction;
/**
* Lifecycle times for the connection
*/
timeline: ConnectionTimeline;
/**
* Once a multiplexer has been negotiated for this stream, it will be set on the stat object
*/
multiplexer?: string;
/**
* Once a connection encrypter has been negotiated for this stream, it will be set on the stat object
*/
encryption?: string;
/**
* The current status of the connection
*/
status: keyof typeof Status;
}
export interface StreamTimeline {

@@ -61,16 +39,2 @@ /**

}
export interface StreamStat {
/**
* Outbound streams are opened by the local node, inbound streams are opened by the remote
*/
direction: Direction;
/**
* Lifecycle times for the stream
*/
timeline: StreamTimeline;
/**
* Once a protocol has been negotiated for this stream, it will be set on the stat object
*/
protocol?: string;
}
/**

@@ -131,6 +95,14 @@ * A Stream is a data channel between two peers that

/**
* Stats about this stream
* Outbound streams are opened by the local node, inbound streams are opened by the remote
*/
stat: StreamStat;
direction: Direction;
/**
* Lifecycle times for the stream
*/
timeline: StreamTimeline;
/**
* Once a protocol has been negotiated for this stream, it will be set on the stat object
*/
protocol?: string;
/**
* User defined stream metadata

@@ -155,8 +127,42 @@ */

export interface Connection {
/**
* The unique identifier for this connection
*/
id: string;
stat: ConnectionStat;
/**
* The address of the remote end of the connection
*/
remoteAddr: Multiaddr;
/**
* The id of the peer at the remote end of the connection
*/
remotePeer: PeerId;
/**
* A list of tags applied to this connection
*/
tags: string[];
/**
* A list of open streams on this connection
*/
streams: Stream[];
/**
* Outbound conections are opened by the local node, inbound streams are opened by the remote
*/
direction: Direction;
/**
* Lifecycle times for the connection
*/
timeline: ConnectionTimeline;
/**
* Once a multiplexer has been negotiated for this stream, it will be set on the stat object
*/
multiplexer?: string;
/**
* Once a connection encrypter has been negotiated for this stream, it will be set on the stat object
*/
encryption?: string;
/**
* The current status of the connection
*/
status: keyof typeof Status;
newStream: (multicodecs: string | string[], options?: NewStreamOptions) => Promise<Stream>;

@@ -163,0 +169,0 @@ addStream: (stream: Stream) => void;

import { Uint8ArrayList } from 'uint8arraylist';
import type { Direction, Stream, StreamStat } from '../connection/index.js';
import type { Direction, Stream, StreamTimeline } from '../connection/index.js';
import type { Source } from 'it-stream-types';

@@ -29,3 +29,5 @@ export interface AbstractStreamInit {

id: string;
stat: StreamStat;
direction: Direction;
timeline: StreamTimeline;
protocol?: string;
metadata: Record<string, unknown>;

@@ -32,0 +34,0 @@ source: AsyncGenerator<Uint8ArrayList, void, unknown>;

@@ -20,3 +20,5 @@ // import { logger } from '@libp2p/logger'

id;
stat;
direction;
timeline;
protocol;
metadata;

@@ -43,7 +45,5 @@ source;

this.metadata = init.metadata ?? {};
this.stat = {
direction: init.direction,
timeline: {
open: Date.now()
}
this.direction = init.direction;
this.timeline = {
open: Date.now()
};

@@ -55,3 +55,3 @@ this.maxDataSize = init.maxDataSize;

// already sent a reset message
if (this.stat.timeline.reset !== null) {
if (this.timeline.reset !== null) {
const res = this.sendCloseRead();

@@ -74,5 +74,5 @@ if (isPromise(res)) {

}
this.stat.timeline.closeRead = Date.now();
this.timeline.closeRead = Date.now();
this.sourceEnded = true;
log.trace('%s stream %s source end - err: %o', this.stat.direction, this.id, err);
log.trace('%s stream %s source end - err: %o', this.direction, this.id, err);
if (err != null && this.endErr == null) {

@@ -82,3 +82,3 @@ this.endErr = err;

if (this.sinkEnded) {
this.stat.timeline.close = Date.now();
this.timeline.close = Date.now();
if (this.onEnd != null) {

@@ -93,5 +93,5 @@ this.onEnd(this.endErr);

}
this.stat.timeline.closeWrite = Date.now();
this.timeline.closeWrite = Date.now();
this.sinkEnded = true;
log.trace('%s stream %s sink end - err: %o', this.stat.direction, this.id, err);
log.trace('%s stream %s sink end - err: %o', this.direction, this.id, err);
if (err != null && this.endErr == null) {

@@ -101,3 +101,3 @@ this.endErr = err;

if (this.sourceEnded) {
this.stat.timeline.close = Date.now();
this.timeline.close = Date.now();
if (this.onEnd != null) {

@@ -110,3 +110,3 @@ this.onEnd(this.endErr);

close() {
log.trace('%s stream %s close', this.stat.direction, this.id);
log.trace('%s stream %s close', this.direction, this.id);
this.closeRead();

@@ -117,3 +117,3 @@ this.closeWrite();

closeRead() {
log.trace('%s stream %s closeRead', this.stat.direction, this.id);
log.trace('%s stream %s closeRead', this.direction, this.id);
if (this.sourceEnded) {

@@ -126,3 +126,3 @@ return;

closeWrite() {
log.trace('%s stream %s closeWrite', this.stat.direction, this.id);
log.trace('%s stream %s closeWrite', this.direction, this.id);
if (this.sinkEnded) {

@@ -143,3 +143,3 @@ return;

catch (err) {
log.trace('%s stream %s error sending close', this.stat.direction, this.id, err);
log.trace('%s stream %s error sending close', this.direction, this.id, err);
}

@@ -150,3 +150,3 @@ this.onSinkEnd();

abort(err) {
log.trace('%s stream %s abort', this.stat.direction, this.id, err);
log.trace('%s stream %s abort', this.direction, this.id, err);
// End the source with the passed error

@@ -179,3 +179,3 @@ this.streamSource.end(err);

source = abortableSource(source, signal);
if (this.stat.direction === 'outbound') { // If initiator, open a new stream
if (this.direction === 'outbound') { // If initiator, open a new stream
const res = this.sendNewStream();

@@ -220,6 +220,6 @@ if (isPromise(res)) {

if (err.code === ERR_STREAM_RESET) {
log.trace('%s stream %s reset', this.stat.direction, this.id);
log.trace('%s stream %s reset', this.direction, this.id);
}
else {
log.trace('%s stream %s error', this.stat.direction, this.id, err);
log.trace('%s stream %s error', this.direction, this.id, err);
try {

@@ -230,6 +230,6 @@ const res = this.sendReset();

}
this.stat.timeline.reset = Date.now();
this.timeline.reset = Date.now();
}
catch (err) {
log.trace('%s stream %s error sending reset', this.stat.direction, this.id, err);
log.trace('%s stream %s error sending reset', this.direction, this.id, err);
}

@@ -251,3 +251,3 @@ }

catch (err) {
log.trace('%s stream %s error sending close', this.stat.direction, this.id, err);
log.trace('%s stream %s error sending close', this.direction, this.id, err);
}

@@ -254,0 +254,0 @@ this.onSinkEnd();

{
"name": "@libp2p/interface",
"version": "0.0.1-daeb43d8",
"version": "0.0.1-e9cafd3d",
"description": "The interface implemented by a libp2p node",

@@ -174,3 +174,3 @@ "license": "Apache-2.0 OR MIT",

"@types/sinon": "^10.0.15",
"aegir": "^39.0.10",
"aegir": "^39.0.13",
"sinon": "^15.1.2",

@@ -177,0 +177,0 @@ "sinon-ts": "^1.0.0"

@@ -15,33 +15,6 @@ import type * as Status from './status.js'

/**
* Outbound conections are opened by the local node, inbound streams are opened by the remote
* Outbound connections are opened by the local node, inbound streams are opened by the remote
*/
export type Direction = 'inbound' | 'outbound'
export interface ConnectionStat {
/**
* Outbound conections are opened by the local node, inbound streams are opened by the remote
*/
direction: Direction
/**
* Lifecycle times for the connection
*/
timeline: ConnectionTimeline
/**
* Once a multiplexer has been negotiated for this stream, it will be set on the stat object
*/
multiplexer?: string
/**
* Once a connection encrypter has been negotiated for this stream, it will be set on the stat object
*/
encryption?: string
/**
* The current status of the connection
*/
status: keyof typeof Status
}
export interface StreamTimeline {

@@ -74,19 +47,2 @@ /**

export interface StreamStat {
/**
* Outbound streams are opened by the local node, inbound streams are opened by the remote
*/
direction: Direction
/**
* Lifecycle times for the stream
*/
timeline: StreamTimeline
/**
* Once a protocol has been negotiated for this stream, it will be set on the stat object
*/
protocol?: string
}
/**

@@ -153,7 +109,17 @@ * A Stream is a data channel between two peers that

/**
* Stats about this stream
* Outbound streams are opened by the local node, inbound streams are opened by the remote
*/
stat: StreamStat
direction: Direction
/**
* Lifecycle times for the stream
*/
timeline: StreamTimeline
/**
* Once a protocol has been negotiated for this stream, it will be set on the stat object
*/
protocol?: string
/**
* User defined stream metadata

@@ -180,9 +146,52 @@ */

export interface Connection {
/**
* The unique identifier for this connection
*/
id: string
stat: ConnectionStat
/**
* The address of the remote end of the connection
*/
remoteAddr: Multiaddr
/**
* The id of the peer at the remote end of the connection
*/
remotePeer: PeerId
/**
* A list of tags applied to this connection
*/
tags: string[]
/**
* A list of open streams on this connection
*/
streams: Stream[]
/**
* Outbound conections are opened by the local node, inbound streams are opened by the remote
*/
direction: Direction
/**
* Lifecycle times for the connection
*/
timeline: ConnectionTimeline
/**
* Once a multiplexer has been negotiated for this stream, it will be set on the stat object
*/
multiplexer?: string
/**
* Once a connection encrypter has been negotiated for this stream, it will be set on the stat object
*/
encryption?: string
/**
* The current status of the connection
*/
status: keyof typeof Status
newStream: (multicodecs: string | string[], options?: NewStreamOptions) => Promise<Stream>

@@ -189,0 +198,0 @@ addStream: (stream: Stream) => void

@@ -7,3 +7,3 @@ // import { logger } from '@libp2p/logger'

import { CodeError } from '../errors.js'
import type { Direction, Stream, StreamStat } from '../connection/index.js'
import type { Direction, Stream, StreamTimeline } from '../connection/index.js'
import type { Source } from 'it-stream-types'

@@ -56,3 +56,5 @@

public id: string
public stat: StreamStat
public direction: Direction
public timeline: StreamTimeline
public protocol?: string
public metadata: Record<string, unknown>

@@ -82,7 +84,5 @@ public source: AsyncGenerator<Uint8ArrayList, void, unknown>

this.metadata = init.metadata ?? {}
this.stat = {
direction: init.direction,
timeline: {
open: Date.now()
}
this.direction = init.direction
this.timeline = {
open: Date.now()
}

@@ -95,3 +95,3 @@ this.maxDataSize = init.maxDataSize

// already sent a reset message
if (this.stat.timeline.reset !== null) {
if (this.timeline.reset !== null) {
const res = this.sendCloseRead()

@@ -119,5 +119,5 @@

this.stat.timeline.closeRead = Date.now()
this.timeline.closeRead = Date.now()
this.sourceEnded = true
log.trace('%s stream %s source end - err: %o', this.stat.direction, this.id, err)
log.trace('%s stream %s source end - err: %o', this.direction, this.id, err)

@@ -129,3 +129,3 @@ if (err != null && this.endErr == null) {

if (this.sinkEnded) {
this.stat.timeline.close = Date.now()
this.timeline.close = Date.now()

@@ -143,5 +143,5 @@ if (this.onEnd != null) {

this.stat.timeline.closeWrite = Date.now()
this.timeline.closeWrite = Date.now()
this.sinkEnded = true
log.trace('%s stream %s sink end - err: %o', this.stat.direction, this.id, err)
log.trace('%s stream %s sink end - err: %o', this.direction, this.id, err)

@@ -153,3 +153,3 @@ if (err != null && this.endErr == null) {

if (this.sourceEnded) {
this.stat.timeline.close = Date.now()
this.timeline.close = Date.now()

@@ -164,3 +164,3 @@ if (this.onEnd != null) {

close (): void {
log.trace('%s stream %s close', this.stat.direction, this.id)
log.trace('%s stream %s close', this.direction, this.id)

@@ -173,3 +173,3 @@ this.closeRead()

closeRead (): void {
log.trace('%s stream %s closeRead', this.stat.direction, this.id)
log.trace('%s stream %s closeRead', this.direction, this.id)

@@ -185,3 +185,3 @@ if (this.sourceEnded) {

closeWrite (): void {
log.trace('%s stream %s closeWrite', this.stat.direction, this.id)
log.trace('%s stream %s closeWrite', this.direction, this.id)

@@ -205,3 +205,3 @@ if (this.sinkEnded) {

} catch (err) {
log.trace('%s stream %s error sending close', this.stat.direction, this.id, err)
log.trace('%s stream %s error sending close', this.direction, this.id, err)
}

@@ -214,3 +214,3 @@

abort (err: Error): void {
log.trace('%s stream %s abort', this.stat.direction, this.id, err)
log.trace('%s stream %s abort', this.direction, this.id, err)
// End the source with the passed error

@@ -250,3 +250,3 @@ this.streamSource.end(err)

if (this.stat.direction === 'outbound') { // If initiator, open a new stream
if (this.direction === 'outbound') { // If initiator, open a new stream
const res = this.sendNewStream()

@@ -299,5 +299,5 @@

if (err.code === ERR_STREAM_RESET) {
log.trace('%s stream %s reset', this.stat.direction, this.id)
log.trace('%s stream %s reset', this.direction, this.id)
} else {
log.trace('%s stream %s error', this.stat.direction, this.id, err)
log.trace('%s stream %s error', this.direction, this.id, err)
try {

@@ -310,5 +310,5 @@ const res = this.sendReset()

this.stat.timeline.reset = Date.now()
this.timeline.reset = Date.now()
} catch (err) {
log.trace('%s stream %s error sending reset', this.stat.direction, this.id, err)
log.trace('%s stream %s error sending reset', this.direction, this.id, err)
}

@@ -332,3 +332,3 @@ }

} catch (err) {
log.trace('%s stream %s error sending close', this.stat.direction, this.id, err)
log.trace('%s stream %s error sending close', this.direction, this.id, err)
}

@@ -335,0 +335,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

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