Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

feat: Browser to Browser #90

Merged
merged 56 commits into from
Apr 7, 2023
Merged

feat: Browser to Browser #90

merged 56 commits into from
Apr 7, 2023

Conversation

ckousik
Copy link
Collaborator

@ckousik ckousik commented Feb 8, 2023

Adds the browser to browser transport. Supersedes #88

  • Add SDP protobufs.
  • Connection receiver initiates the RTCPeerConnection (when connecting from A to B, B will create the SDP offer after A establishes the relayed connection).
  • Add tests for protocol handler.
  • Add examples to CI.

@ckousik ckousik mentioned this pull request Feb 8, 2023
8 tasks
@ckousik ckousik requested a review from ddimaria February 8, 2023 12:59
@ckousik
Copy link
Collaborator Author

ckousik commented Feb 8, 2023

@ddimaria Still waiting on resolution for protocol name and code libp2p/specs#497 (comment)

@mxinden
Copy link
Member

mxinden commented Feb 9, 2023

@ddimaria Still waiting on resolution for protocol name and code libp2p/specs#497 (comment)

@ckousik do I understand correctly that these discussions are not blocking this pull request? Or is all other work done?

@ddimaria
Copy link
Collaborator

ddimaria commented Feb 9, 2023

@ddimaria Still waiting on resolution for protocol name and code libp2p/specs#497 (comment)

@ckousik do I understand correctly that these discussions are not blocking this pull request? Or is all other work done?

@mxinden Chinmay is out for the rest of the week. I can confirm that the spec-related decisions are not blocking this PR. I plan on adding a browser-to-browser example to the /examples directory and adding that to CI, as well as internally reviewing the code today/tomorrow. The goal is to have it ready for review sometime tomorrow.


rawStream.close()
void connection.close()
// TODO(ckousik): Remove this delay. This is required because
Copy link
Collaborator Author

@ckousik ckousik Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@achingbrain For further clarification, consider a case where A is connecting to B using webrtc-direct. A and B both complete SDP exchange and their PeerConnections transition to the connected state. For the ICE connection, A is the controlled peer and B is the controlling peer. With reference to the description here, A moves to the connected state before B. This allows A to create a stream on the new connection before B has a chance to set up the datachannel callbacks.

@MarcoPolo MarcoPolo self-requested a review February 20, 2023 23:07
@MarcoPolo
Copy link
Contributor

MarcoPolo commented Feb 21, 2023

  • todo We need to add CI testing for this example

Copy link
Contributor

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits, but overall looks good to me. I'll leave the final approval to @achingbrain

Great work @ckousik :)

appendOutput(`Dialing '${ma}'`)
const connection = await node.dial(ma)

if (!ma.protoCodes().includes(276)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

276? Let's not forget to change this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

276 is the protoCode for circuit-relay. This is just used to differentiate between dialing a relay peer to start listening vs dialing a peer over relay to create an echo stream.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a library where we can ensure the protocode is more self documenting? (similar to codes in dag-json, dag-cbor, etc.. from ipld) we shouldn't be throwing magic numbers around

)

func main() {
makeRelayV1()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not relayV2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't landed support for circuit v2 in js yet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, tracking issue libp2p/js-libp2p#1029 and pull request libp2p/js-libp2p#1533.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are in now, can we update this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump: please update to relay v2 (and the latest go-libp2p release)

src/muxer.ts Outdated Show resolved Hide resolved
src/muxer.ts Outdated Show resolved Hide resolved
src/muxer.ts Outdated Show resolved Hide resolved
src/muxer.ts Outdated Show resolved Hide resolved
src/stream.ts Outdated Show resolved Hide resolved
}

private listeningAddrs: Multiaddr[] = []
async listen (ma: Multiaddr): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? Aren't we listening already via some relay?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, but the rationale to add this is as follows:

  1. Since webrtc-direct is a protocol, we can advertise support over any transport.
  2. For running on node, we can use node-webrtc to replace all instances of RTCPeerConnection (webrtc-star and webrtc-direct currently do this).

Although, an argument can be made that any listener can support webrtc-direct since it is only implemented as a protocol.

src/peer_transport/transport.ts Outdated Show resolved Hide resolved
src/peer_transport/transport.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@MarcoPolo MarcoPolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small nits. I'll fix up anything left and merge this soon. 🎉

examples/browser-to-server/tests/test.js Outdated Show resolved Hide resolved
examples/browser-to-server/index.js Show resolved Hide resolved
src/peer_transport/handler.ts Outdated Show resolved Hide resolved
import { noise } from "@chainsafe/libp2p-noise"

// singletons
let outgoing_stream
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I should have been more clear. This shouldn't be a singleton because
there's no benefit of it being so. I'm not sure you could use this in a correct
way as a singleton anyways, since once you pass it into pipe you don't own
this stream. Since this is an example, the risk that people copy this verbatim
is pretty high. so we should remove this. I'll push a change.

src/peer_transport/transport.ts Show resolved Hide resolved
return
}

node.getMultiaddrs().forEach((ma) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to remove an address?

@MarcoPolo
Copy link
Contributor

Merging this since I've given it a review. I'm sure there's more things to fix, but I'd rather do those incrementally from now on. @achingbrain feel to review this at a later time

@MarcoPolo MarcoPolo merged commit add5c46 into main Apr 7, 2023
@MarcoPolo MarcoPolo deleted the feat/browser-to-browser branch April 7, 2023 20:58
github-actions bot pushed a commit that referenced this pull request Apr 7, 2023
## [1.1.0](v1.0.5...v1.1.0) (2023-04-07)

### Features

* Browser to Browser ([#90](#90)) ([add5c46](add5c46))
@github-actions
Copy link

github-actions bot commented Apr 7, 2023

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants