Skip to content

swift-libp2p/swift-libp2p-websocket

Repository files navigation

LibP2PWebSocket

Swift Package Manager compatible Build & Test (macos and linux)

A WebSocket Transport module for libp2p

Table of Contents

Overview

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.

Install

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"),
            ]),
    ...
)

Usage

Example

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 )

API

Not Applicable

Contributing

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! 🤝

Credits

License

MIT © 2022 Breth Inc.

About

A WebSocket Transport Module for LibP2P Applications

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages