-
Notifications
You must be signed in to change notification settings - Fork 16
Feature/refactor and add tests and coverage #60
Feature/refactor and add tests and coverage #60
Conversation
@@ -1,13 +1,6 @@ | |||
import errCode from 'err-code' |
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.
I just alpha sorted the errors
constructor (streamLabel: string, errorMessage: string) { | ||
super(`[stream: ${streamLabel}] data channel error: ${errorMessage}`) | ||
this.name = 'WebRTC/DataChannelError' | ||
export class OverStreamLimitError extends WebRTCTransportError { |
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.
Renamed this for consistency
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #60 +/- ##
===========================================
Coverage ? 100.00%
===========================================
Files ? 9
Lines ? 9
Branches ? 0
===========================================
Hits ? 9
Misses ? 0
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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 looks good from a preliminary read. I will review it again shortly.
|
||
go 1.18 | ||
|
||
replace github.com/libp2p/go-libp2p => github.com/ckousik/go-libp2p v0.23.3-0.20221029141116-67b7c6290b11 |
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.
We will need to update this once the Go PR is merged. I'll add an issue for it.
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.
Link to the issue in a comment perhaps with a big fat TODO?
|
||
## Hacking | ||
![https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-connection](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/packages/interface-connection/img/badge.png) |
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.
![https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-connection](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/packages/interface-connection/img/badge.png) | |
[![Connection interface for libp2p](https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces/master/packages/interface-connection/img/badge.png)](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/interface-connection) |
Not more accessible?
```js | ||
interface MultiaddrConnection extends Duplex<Uint8Array> { | ||
close: (err?: Error) => Promise<void> | ||
remoteAddr: Multiaddr |
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.
Does it has to be writable or can it be readonly
? Same question for the next property.
|
||
There is also `npm run autogen` which uses ProtoBuf's protoc to populate the generated code directory `proto_ts` based on `*.proto` files in src. Don't forget to run this step before `build` any time you make a change to any of the `*.proto` files. | ||
class WebRTCMultiaddrConnection implements MultiaddrConnection { } |
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.
Is there any value to this example as it:
- neither implements the connection
- nor does it get past a decent linter for several reasons
Just asking as people do tend to copy examples as is.
npm run go-libp2p-server | ||
``` | ||
|
||
Copy the multiaddress in the output. |
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.
might be useful to show an example of such output and multiaddress
|
||
The browser window will automatically open. | ||
Using the copied multiaddress from the Go server, pasted that value into the `Server MultiAddress` input and click the `Connect` button. | ||
Once the peer is connected, click the message section will appear. Enter a message and click the `Send` button. |
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.
Once the peer is connected, click the message section will appear. Enter a message and click the `Send` button. | |
Once the peer is connected, click the message section once it appeared. Then enter a message and click the `Send` button. |
?
import { fromString, toString } from "uint8arrays"; | ||
import { webRTC } from 'js-libp2p-webrtc' | ||
|
||
let stream; |
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.
Is this indention on purpose? o.O
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.
Or did you forget to define (async () => {
on top?
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.
Even better, probably only want to do it once you know the DOM is initialised/ready?
connectionEncryption: [() => new Noise()], | ||
}); | ||
|
||
await node.start() |
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.
Does this even run? Since when can you have await
in a non-async body, which the global body is AFAIK?
"type": "module", | ||
"scripts": { | ||
"start": "vite", | ||
"go-libp2p-server": "cd ../go-libp2p-server && go build && ./go-libp2p-server" |
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.
does npm
run your scripts in a new shell? As otherwise this command would change your CWD
implicitly, which might be confusing and not expected when the cmd exits?
libp2p.Ping(true), | ||
) | ||
if err != nil { | ||
panic(err) |
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.
given you already use log
pkg anyway, you might perhaps want to use log.Fatal(err)
instead?
|
||
/** | ||
* The multiaddr address used to communicate with the remote peer | ||
*/ | ||
remoteAddr: Multiaddr; |
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.
does this property and the ones below have to be public? If so, do they have to writable? If so, can they be public only as a get
(ter)?
log.error('error closing connection', err) | ||
if (err !== undefined) { | ||
log.error('error closing connection', err) | ||
} |
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.
might be nice to have a non-err
log.debug
equivalent for sanity checking while debugging?
readonly protocol: string = '/webrtc' | ||
|
||
/** | ||
* Array of streams in the data channel |
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.
Any streams? Just the ones alive? Or once in the array always in the array?
// channelOptions?: WebRTCReceiverInit | ||
} | ||
|
||
export interface WebRTCListenerOptions extends CreateListenerOptions {} |
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.
my linters do not accept such empty extends, I believe better practice is something like:
export { CreateListenerOptions as WebRTCListenerOptions } from '@libp2p/interface-transport'
@@ -76,7 +86,9 @@ export function toSupportedHashFunction (name: multihashes.HashName): string { | |||
} | |||
} | |||
|
|||
// Convert a multiaddr into a SDP | |||
/** | |||
* Convert a multiaddr into a SDP |
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.
Might be nice to write fully what SDP
means as <full name> (SDP)
, small effort but a cognitive ease of mind
export function fromMultiAddr (ma: Multiaddr, ufrag: string): RTCSessionDescriptionInit { | ||
return { | ||
type: 'answer', | ||
sdp: ma2sdp(ma, ufrag) | ||
} | ||
} | ||
|
||
// Replace the ufrag and password values in a SDP | ||
/** | ||
* Replace (munge) the ufrag and password values in a SDP |
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.
Might just be me reading functions that I require pre-knowledge for, but I stil feels there is a lot of guess work required on my end to get what this function does without reading the actual implementation.
@@ -12,6 +12,9 @@ import * as pb from '../proto_ts/message.js' | |||
|
|||
const log = logger('libp2p:webrtc:stream') | |||
|
|||
/** | |||
* Constructs a default StreamStat |
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.
might be nice to expand a bit on what these defaults
entail?
async dial (ma: Multiaddr, options: WebRTCDialOptions): Promise<Connection> { | ||
const rawConn = await this._connect(ma, options) | ||
log(`dialing address - ${ma.toString()}`) | ||
return rawConn | ||
} | ||
|
||
/** | ||
* Create transport listeners no supported by browsers |
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 sentence reads a big ambiguous and unclear, can you expand it please? E.g. Creating transports listeners is not supported when used from within a browser
, or something like that
import { WebRTCMultiaddrConnection } from './../src/maconn' | ||
|
||
describe('Multiaddr Connection', () => { | ||
it('can open and close', async () => { |
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.
imho it doesn't really test that right? I mean it proves the close
property changes when you call close()
but it might as well be done using a dummy property which toggles.
Not better to next to what you already do, also write to it, and have it succeed proving you receive the value, with then the the write or so afterwards doesn't work and you instead get some specific error that indicates the conn is closed and that you also confirm the content is indeed not written.
And same for or instead of the reading part?
const maConn = new WebRTCMultiaddrConnection({ | ||
peerConnection: peerConnection, | ||
remoteAddr, | ||
timeline: { |
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.
why not make this the default value, seems like a sane default if you ask me? Would allow you to omit it here as well
@@ -1,74 +1,68 @@ | |||
import * as underTest from '../src/stream' | |||
import { expect, assert } from 'chai' | |||
|
|||
function setup (): { peerConnection: RTCPeerConnection, datachannel: RTCDataChannel, webrtcStream: underTest.WebRTCStream } { | |||
const peerConnection = new RTCPeerConnection() | |||
const datachannel = peerConnection.createDataChannel('whatever', { negotiated: true, id: 91 }) |
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.
why not make the data channel id optional and generate a random ID by default? Seems better to me than having to invent strings like this?
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.
Functionality it looks ok, even though that's harder for me to tell given I Am not yet familiar with libp2p and its specs. So my review is more generic, in that context I Requested some changes but feel free to ignore them all, as none of my comments indicate a functional flaw AFAIC
Co-authored-by: Glen De Cauwsemaecker <glen.decauwsemaecker@otainsight.com>
Co-authored-by: Glen De Cauwsemaecker <glen.decauwsemaecker@otainsight.com>
🎉 This PR is included in version 1.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Also, fixes #53