universal-connectivity icon indicating copy to clipboard operation
universal-connectivity copied to clipboard

Add .NET peer implementation with TCP transport and GossipSub

Open leny62 opened this issue 9 months ago • 3 comments

Overview

This PR adds a .NET peer implementation to the universal connectivity demo, which previously showcased connectivity between Go, Rust, and JavaScript. The new implementation demonstrates how libp2p can be used in the .NET ecosystem, providing a way for C# developers to participate in the same libp2p network.

Features

  • Full-featured .NET peer using the Nethermind.Libp2p library
  • TCP transport protocol support
  • GossipSub protocol for message publishing/subscription
  • Beautiful console UI with separate panels for chat, peers, and system logs
  • Cross-implementation compatibility with existing Go, and probably Rust (testing soon)

Changes

  • Added dotnet-peer directory with a complete implementation
  • Created Console UI:
    • Terminal.Gui-based UI
  • Comprehensive README documentation for .NET peer setup and usage
  • Added appropriate .gitignore rules for .NET projects

Testing

The implementation has been tested for interoperability with:

  • Go peer over TCP

Live Demo

https://drive.google.com/file/d/1crse0KP1bfbFLx-_BkaG77uPYZ-mDI1G/view?usp=drive_link

Protocol Support Matrix (Updated)

Package Description WebTransport WebRTC WebRTC-direct QUIC TCP
js-peer Browser Chat Peer in TypeScript
go-peer Chat peer implemented in Go
rust-peer Chat peer implemented in Rust
dotnet-peer Chat peer implemented in .NET 🚧

This implementation expands the universal connectivity demo to include the .NET ecosystem, further demonstrating libp2p's cross-language interoperability capabilities.

leny62 avatar Mar 21 '25 15:03 leny62

It looks like you hacked up the go client on the left for your video. Is that correct? It looks from the log output that you hard coded it to connect to your dotnet-peer. Then you must have changed the chat window code to show the full object received instead of just the chat message. That's no big deal, it's just not what users should expect.

Also, is there a way to re-direct all of the log tracing to the "Logs" tab in your UI instead of having it take over your terminal briefly? In Rust there's an easy way to do that: https://github.com/libp2p/universal-connectivity/pull/245/files#diff-4a6d015b4db92c87150fef3ceca232743a6bd871ee368ced697e338e81b2fb41

I'm not sure if there is one in DotNet. I'm pretty sure you just have to either inject code into the logging system that libraries/apps use...if not that, then you need to redirect stderr to a stream you read from and output to the Log tab.

Overally, this is excellent!! Great work. 🍻

dhuseby avatar Mar 21 '25 20:03 dhuseby

You don't have to hard code the go-peer to connect to your peer. It has a command line argument "-connect" that you can pass the multiaddr to (e.g. /ip4/127.0.0.1/tcp/9096/p2p/<peer id>).

dhuseby avatar Mar 21 '25 20:03 dhuseby

Thank you for the feedback @dhuseby. I've made several improvements to address your comments:

Updates in this revision:

  1. UI Display Fix:

    • Fixed the Terminal.GUI display issue by properly separating threading concerns
    • The chat UI now displays correctly within the console window, with all components properly organized
    • The application now correctly shows the welcome messages and connection information in the UI
  2. Log Redirection:

    • Implemented proper log redirection to the "Logs" tab in the UI
    • Added a custom logging provider that captures all logs (including library logs) and displays them in the UI
    • Console output is significantly cleaner, with most messages now appearing in the Logs tab
  3. Clean Architecture:

    • Restructured the codebase into a clean architecture with proper separation of concerns
    • Implemented Domain, Application, Infrastructure, and Presentation layers
    • All components now interact through well-defined interfaces
  4. Demo Video:

leny62 avatar Apr 02 '25 16:04 leny62