This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from little-bear-labs/bugfix/fix-linting-issues
Apply auto lint fixer
- Loading branch information
Showing
20 changed files
with
851 additions
and
798 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,123 @@ | ||
import { default as createError } from 'err-code'; | ||
import { Direction } from '@libp2p/interface-connection'; | ||
import errCode from 'err-code' | ||
import { Direction } from '@libp2p/interface-connection' | ||
|
||
export class WebRTCTransportError extends Error { | ||
constructor(msg: string) { | ||
super('WebRTC transport error: ' + msg); | ||
this.name = 'WebRTCTransportError'; | ||
constructor (msg: string) { | ||
super('WebRTC transport error: ' + msg) | ||
this.name = 'WebRTCTransportError' | ||
} | ||
} | ||
|
||
export enum codes { | ||
ERR_ALREADY_ABORTED = 'ERR_ALREADY_ABORTED', | ||
ERR_DATA_CHANNEL = 'ERR_DATA_CHANNEL', | ||
ERR_CONNECTION_CLOSED = 'ERR_CONNECTION_CLOSED', | ||
ERR_HASH_NOT_SUPPORTED = 'ERR_HASH_NOT_SUPPORTED', | ||
ERR_INVALID_MULTIADDR = 'ERR_INVALID_MULTIADDR', | ||
ERR_INVALID_FINGERPRINT = 'ERR_INVALID_FINGERPRINT', | ||
ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS', | ||
ERR_HASH_NOT_SUPPORTED = 'ERR_HASH_NOT_SUPPORTED', | ||
ERR_NOT_IMPLEMENTED = 'ERR_NOT_IMPLEMENTED', | ||
ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS', | ||
ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS', | ||
ERR_CONNECTION_CLOSED = 'ERR_CONNECTION_CLOSED', | ||
} | ||
|
||
export class ConnectionClosedError extends WebRTCTransportError { | ||
constructor(state: RTCPeerConnectionState, msg: string) { | ||
super(`peerconnection moved to state: ${state}:` + msg); | ||
this.name = 'WebRTC/ConnectionClosed'; | ||
constructor (state: RTCPeerConnectionState, msg: string) { | ||
super(`peerconnection moved to state: ${state}:` + msg) | ||
this.name = 'WebRTC/ConnectionClosed' | ||
} | ||
} | ||
|
||
export function connectionClosedError(state: RTCPeerConnectionState, msg: string) { | ||
return createError(new ConnectionClosedError(state, msg), codes.ERR_CONNECTION_CLOSED) | ||
export function connectionClosedError (state: RTCPeerConnectionState, msg: string) { | ||
return errCode(new ConnectionClosedError(state, msg), codes.ERR_CONNECTION_CLOSED) | ||
} | ||
|
||
export class InvalidArgumentError extends WebRTCTransportError { | ||
constructor(msg: string) { | ||
super('There was a problem with a provided argument: ' + msg); | ||
this.name = 'WebRTC/InvalidArgumentError'; | ||
constructor (msg: string) { | ||
super('There was a problem with a provided argument: ' + msg) | ||
this.name = 'WebRTC/InvalidArgumentError' | ||
} | ||
} | ||
|
||
export function unsupportedHashAlgorithm(algorithm: string) { | ||
return createError(new UnsupportedHashAlgorithmError(algorithm), codes.ERR_HASH_NOT_SUPPORTED); | ||
export function unsupportedHashAlgorithm (algorithm: string) { | ||
return errCode(new UnsupportedHashAlgorithmError(algorithm), codes.ERR_HASH_NOT_SUPPORTED) | ||
} | ||
|
||
export class UnsupportedHashAlgorithmError extends WebRTCTransportError { | ||
constructor(algo: string) { | ||
let msg = `unsupported hash algorithm: ${algo}`; | ||
super(msg); | ||
this.name = 'WebRTC/UnsupportedHashAlgorithmError'; | ||
constructor (algo: string) { | ||
const msg = `unsupported hash algorithm: ${algo}` | ||
super(msg) | ||
this.name = 'WebRTC/UnsupportedHashAlgorithmError' | ||
} | ||
} | ||
|
||
export function invalidArgument(msg: string) { | ||
return createError(new InvalidArgumentError(msg), codes.ERR_INVALID_PARAMETERS); | ||
export function invalidArgument (msg: string) { | ||
return errCode(new InvalidArgumentError(msg), codes.ERR_INVALID_PARAMETERS) | ||
} | ||
|
||
export class UnimplementedError extends WebRTCTransportError { | ||
constructor(methodName: string) { | ||
super('A method (' + methodName + ') was called though it has been intentionally left unimplemented.'); | ||
this.name = 'WebRTC/UnimplementedError'; | ||
constructor (methodName: string) { | ||
super('A method (' + methodName + ') was called though it has been intentionally left unimplemented.') | ||
this.name = 'WebRTC/UnimplementedError' | ||
} | ||
} | ||
|
||
export function unimplemented (methodName: string) { | ||
return errCode(new UnimplementedError(methodName), codes.ERR_NOT_IMPLEMENTED) | ||
} | ||
|
||
export class InvalidFingerprintError extends WebRTCTransportError { | ||
constructor (fingerprint: string, source: string) { | ||
super(`Invalid fingerprint "${fingerprint}" within ${source}`) | ||
this.name = 'WebRTC/InvalidFingerprintError' | ||
} | ||
} | ||
|
||
export function unimplemented(methodName: string) { | ||
return createError(new UnimplementedError(methodName), codes.ERR_NOT_IMPLEMENTED); | ||
export function invalidFingerprint (fingerprint: string, source: string) { | ||
return errCode(new InvalidFingerprintError(fingerprint, source), codes.ERR_INVALID_FINGERPRINT) | ||
} | ||
|
||
export class InappropriateMultiaddrError extends WebRTCTransportError { | ||
constructor(msg: string) { | ||
super('There was a problem with the Multiaddr which was passed in: ' + msg); | ||
this.name = 'WebRTC/InappropriateMultiaddrError'; | ||
constructor (msg: string) { | ||
super('There was a problem with the Multiaddr which was passed in: ' + msg) | ||
this.name = 'WebRTC/InappropriateMultiaddrError' | ||
} | ||
} | ||
|
||
export function inappropriateMultiaddr(msg: string) { | ||
return createError(new InappropriateMultiaddrError(msg), codes.ERR_INVALID_MULTIADDR); | ||
export function inappropriateMultiaddr (msg: string) { | ||
return errCode(new InappropriateMultiaddrError(msg), codes.ERR_INVALID_MULTIADDR) | ||
} | ||
|
||
export class OperationAbortedError extends WebRTCTransportError { | ||
constructor(context: string, abortReason: string) { | ||
super(`Signalled to abort because (${abortReason}})${context}`); | ||
this.name = 'WebRTC/OperationAbortedError'; | ||
constructor (context: string, abortReason: string) { | ||
super(`Signalled to abort because (${abortReason}})${context}`) | ||
this.name = 'WebRTC/OperationAbortedError' | ||
} | ||
} | ||
|
||
export function operationAborted(context: string, reason: string) { | ||
return createError(new OperationAbortedError(context, reason), codes.ERR_ALREADY_ABORTED); | ||
export function operationAborted (context: string, reason: string) { | ||
return errCode(new OperationAbortedError(context, reason), codes.ERR_ALREADY_ABORTED) | ||
} | ||
|
||
export class DataChannelError extends WebRTCTransportError { | ||
constructor(streamLabel: string, errorMessage: string) { | ||
super(`[stream: ${streamLabel}] data channel error: ${errorMessage}`); | ||
this.name = 'WebRTC/DataChannelError'; | ||
constructor (streamLabel: string, errorMessage: string) { | ||
super(`[stream: ${streamLabel}] data channel error: ${errorMessage}`) | ||
this.name = 'WebRTC/DataChannelError' | ||
} | ||
} | ||
|
||
export function dataChannelError(streamLabel: string, msg: string) { | ||
return createError(new DataChannelError(streamLabel, msg), codes.ERR_DATA_CHANNEL); | ||
export function dataChannelError (streamLabel: string, msg: string) { | ||
return errCode(new DataChannelError(streamLabel, msg), codes.ERR_DATA_CHANNEL) | ||
} | ||
|
||
export class StreamingLimitationError extends WebRTCTransportError { | ||
constructor(msg: string) { | ||
super(msg); | ||
this.name = 'WebRTC/StreamingLimitationError'; | ||
constructor (msg: string) { | ||
super(msg) | ||
this.name = 'WebRTC/StreamingLimitationError' | ||
} | ||
} | ||
|
||
export function overStreamLimit(dir: Direction, proto: string) { | ||
let code = dir == 'inbound' ? codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS : codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS; | ||
return createError(new StreamingLimitationError(`${dir} stream limit reached for protocol - ${proto}`), code); | ||
export function overStreamLimit (dir: Direction, proto: string) { | ||
const code = dir === 'inbound' ? codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS : codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS | ||
return errCode(new StreamingLimitationError(`${dir} stream limit reached for protocol - ${proto}`), code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,34 @@ | ||
import {MultiaddrConnection, MultiaddrConnectionTimeline} from "@libp2p/interface-connection"; | ||
import { logger } from '@libp2p/logger'; | ||
import {Multiaddr} from "@multiformats/multiaddr"; | ||
import {Source, Sink} from "it-stream-types"; | ||
import {nopSink, nopSource} from "./util.js"; | ||
import { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface-connection' | ||
import { logger } from '@libp2p/logger' | ||
import { Multiaddr } from '@multiformats/multiaddr' | ||
import { Source, Sink } from 'it-stream-types' | ||
|
||
const log = logger('libp2p:webrtc:connection'); | ||
import { nopSink, nopSource } from './util.js' | ||
|
||
type WebRTCMultiaddrConnectionInit = { | ||
peerConnection: RTCPeerConnection; | ||
remoteAddr: Multiaddr; | ||
timeline: MultiaddrConnectionTimeline; | ||
}; | ||
const log = logger('libp2p:webrtc:connection') | ||
|
||
interface WebRTCMultiaddrConnectionInit { | ||
peerConnection: RTCPeerConnection | ||
remoteAddr: Multiaddr | ||
timeline: MultiaddrConnectionTimeline | ||
} | ||
|
||
export class WebRTCMultiaddrConnection implements MultiaddrConnection { | ||
private peerConnection: RTCPeerConnection; | ||
private readonly peerConnection: RTCPeerConnection; | ||
remoteAddr: Multiaddr; | ||
timeline: MultiaddrConnectionTimeline; | ||
|
||
source: Source<Uint8Array> = nopSource | ||
sink: Sink<Uint8Array, Promise<void>> = nopSink; | ||
|
||
constructor(init: WebRTCMultiaddrConnectionInit) { | ||
this.remoteAddr = init.remoteAddr; | ||
this.timeline = init.timeline; | ||
this.peerConnection = init.peerConnection; | ||
constructor (init: WebRTCMultiaddrConnectionInit) { | ||
this.remoteAddr = init.remoteAddr | ||
this.timeline = init.timeline | ||
this.peerConnection = init.peerConnection | ||
} | ||
|
||
async close(err?: Error | undefined): Promise<void> { | ||
log.error("error closing connection", err) | ||
async close (err?: Error | undefined): Promise<void> { | ||
log.error('error closing connection', err) | ||
this.peerConnection.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.