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
Fix noise prologue generation #18
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0a7acbe
Getting more specific with the errors being thrown.
John-LittleBearLabs 3073031
Fix noise prologue generation
ckousik 425b830
Shifting approach.
John-LittleBearLabs d5f0db9
Using error codes tied to error types by way of convenience functions.
John-LittleBearLabs fd63ecd
fix multibase
ckousik 2b845e0
fix duplicate function
ckousik ea19f45
Merge remote-tracking branch 'origin/jt/error' into ckousik/noise-pro…
ckousik 60df448
use new errors
ckousik cbb9864
remove comment
ckousik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,13 +1,99 @@ | ||
import { default as createError } from 'err-code'; | ||
import { Direction } from '@libp2p/interface-connection'; | ||
|
||
export class WebRTCTransportError extends Error { | ||
constructor(msg: string) { | ||
super(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_INVALID_MULTIADDR = 'ERR_INVALID_MULTIADDR', | ||
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', | ||
} | ||
|
||
export class InvalidArgumentError extends WebRTCTransportError { | ||
constructor(msg: string) { | ||
super(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 class UnsupportedHashAlgorithmError extends WebRTCTransportError { | ||
constructor(algo: string) { | ||
let 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 class UnimplementedError extends WebRTCTransportError { | ||
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 createError(new UnimplementedError(methodName), codes.ERR_NOT_IMPLEMENTED); | ||
} | ||
|
||
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'; | ||
} | ||
} | ||
|
||
export function inappropriateMultiaddr(msg: string) { | ||
return createError(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'; | ||
} | ||
} | ||
|
||
export function operationAborted(context: string, reason: string) { | ||
return createError(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'; | ||
} | ||
} | ||
|
||
export function dataChannelError(streamLabel: string, msg: string) { | ||
return createError(new OperationAbortedError(streamLabel, msg), codes.ERR_DATA_CHANNEL); | ||
} | ||
|
||
export class StreamingLimitationError extends WebRTCTransportError { | ||
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); | ||
} |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certhash contains a space?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This writes the fingerprint in SDP format
<hash algorithm> <fingerprint>
.