A WebSocket Transport module for libp2p
This repo adds support for WebSockets over HTTP1 for swift-libp2p applications. WebSockets are realtime full-duplex streams over tcp. This module doesn't support WebSocket Secure (WSS) connections. Instead it encrypts traffic using a libp2p security module such as Noise.
Include the following dependency in your Package.swift file
let package = Package(
...
dependencies: [
...
.package(url: "https://github.com/swift-libp2p/swift-libp2p-websocket.git", .upToNextMajor(from: "0.1.0"))
],
...
.target(
...
dependencies: [
...
.product(name: "LibP2PWebSocket", package: "swift-libp2p-websocket"),
]),
...
)
import LibP2PWebSocket
/// Tell libp2p that it should listen for WS connections on the following ip:port...
app.servers.use( .ws(host: "127.0.0.1", port: 10000) )
/// Tell libp2p that it can dial peers using WebSockets `ws`
app.transports.use( .ws )
Not Applicable
Contributions are welcomed! This code is very much a proof of concept. I can guarantee you there's a better / safer way to accomplish the same results. Any suggestions, improvements, or even just critques, are welcome!
Let's make this code better together! 🤝
MIT © 2022 Breth Inc.