Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: architecture diagrams #2083

Closed
Tracked by #2081
wemeetagain opened this issue Sep 27, 2023 · 5 comments · Fixed by #2121
Closed
Tracked by #2081

docs: architecture diagrams #2083

wemeetagain opened this issue Sep 27, 2023 · 5 comments · Fixed by #2121
Assignees
Labels
P0 Critical: Tackled by core team ASAP topic/docs Documentation

Comments

@wemeetagain
Copy link
Member

flowchart TB
    direction TB
    subgraph Components
        direction TB
        PeerId ~~~
        Events ~~~
        ConnectionGater ~~~
        Upgrader
        AddressManager ~~~
        ConnectionManager ~~~
        TransportManager ~~~
        Registrar 
        PeerStore ~~~
        Datastore ~~~
        PeerRouting ~~~
        _xx[ ]
        ContentRouting ~~~
        Metrics ~~~
        ConnectionProtector ~~~
        _x[ ]
        
        style _x opacity:0;
        style _xx opacity:0;

    end

    subgraph Connections[Connection Configuration]
        direction TB

        subgraph Transports
            direction TB
            TCP
            WebRTC
            Websocket
            Webtransport
        end

        subgraph Encryption[Connection Encryptions]
            direction TB
            Noise
            Plaintext
        end

        subgraph Multiplexer[Stream Multiplexers]
            direction TB
            Yamux
            Mplex
        end
        
        Multiplexer ~~~ Encryption ~~~ Transports

    end
Loading
---
title: Components Dependency Graph
---
flowchart TD
    PeerId
    Events
    ConnectionGater
    Upgrader
    AddressManager
    ConnectionManager
    TransportManager
    Registrar
    PeerStore
    Datastore
    PeerRouting
    ContentRouting
    Metrics
    ConnectionProtector

    %% AddressManager
    PeerId --> AddressManager
    TransportManager --> AddressManager
    PeerStore --> AddressManager
    Events --> AddressManager

    %% ConnectionManager
    PeerId --> ConnectionManager
    Metrics --> ConnectionManager
    PeerStore --> ConnectionManager
    TransportManager --> ConnectionManager
    ConnectionGater --> ConnectionManager
    Events --> ConnectionManager

    %% TransportManager
    Metrics --> TransportManager
    AddressManager --> TransportManager
    Upgrader --> TransportManager
    Events --> TransportManager

    %% Upgrader
    PeerId --> Upgrader
    Metrics --> Upgrader
    ConnectionManager --> Upgrader
    ConnectionGater --> Upgrader
    ConnectionProtector --> Upgrader
    Registrar --> Upgrader
    PeerStore --> Upgrader
    Events --> Upgrader

    %% Registrar
    PeerId --> Registrar
    ConnectionManager --> Registrar
    PeerStore --> Registrar
    Events --> Registrar

    %% PeerStore
    PeerId --> PeerStore
    Datastore --> PeerStore
    Events --> PeerStore

    %% PeerRouting
    PeerId --> PeerRouting
    PeerStore --> PeerRouting

    %% ContentRouting
    PeerStore --> ContentRouting
Loading
@wemeetagain wemeetagain added the need/triage Needs initial labeling and prioritization label Sep 27, 2023
@SgtPooki
Copy link
Member

2023-09-27 NOTES:

  1. fix circular deps
    • between transport manager and address manager
    • transport manager to connection manager to upgrader
  2. candidates for being removed:
    • contentRouting (nothing uses it)
  3. keychain isn't in diagram - not a component: we need to document details around this
  4. We need to verify that each component has a top level package documentation string (in src/index.ts)
    • And we should be using that @packageDocumentation as our canonical, central location for documentation, in src code, that we add to the readme files.

Let's try creating some live sequence diagrams:

outbound connection

how an outbound connection is opened when a user calls .dial(), assuming user is not connected to the PeerId for the Multiaddr that was dialed.

%% how an outbound connection is opened when a user calls .dial(), 
%% assuming user is not connected to the PeerId for the 
%% Multiaddr that was dialed.
%%
%% This is 
%% 
sequenceDiagram
    User->>+libp2p: dial a multiaddr `.dial()`
    libp2p->>+Connection Manager: open a connection for me to MA `.openConnection()`
    %% obfuscating the dial queue.
    %% Connection Manager->>+Transport Manager: Choose transport to use for Multiaddr
    Connection Manager->>+Transport Manager: Network level reach out `.dial()`
    Transport Manager->>+Transport: Get MultiaddrConn `socket + multiaddr`
    %% Transport->>+Transport Manager: Return MultiaddrConn `socket + multiaddr`
    %% how the upgrade happens is transport specific, so transports directly call upgrader
    Transport-->>+Upgrader: upgrade my connection??
    Upgrader-->>+Upgrader: Perform upgrade (see other diagram)
    Upgrader->>+Connection Manager: Connection (link to interface)
    %% Connection Manager->>+Connection Manager: Connection (link to interface)
    Connection Manager->>+User: Connection (link to interface)

Loading

@SgtPooki
Copy link
Member

SgtPooki commented Sep 27, 2023

sequence diagram:

open echo protocol stream and send data

Assumptions:

  • connection established
  • stable connection
%% pushing data over stream
%% register stream handler, local opens a stream for proto, send data, 
%% remote receives data and sends data back
%% local receives data
%% stream may or may not then be closed.
%% Local is the node sending data, Remote is other peer the conn is with
%% Echo protocol
sequenceDiagram
    box Local side
    participant Local
    participant Connection
    participant LocalMuxer
    end
    participant Stream
    box pink Connection
    end
    box Remote side
    participant Remote
    participant RemoteMuxer
    participant RemoteUpgrader
    participant RemoteRegistrar
    participant RemoteStreamHandler
    end

    Remote->>RemoteRegistrar: Register Stream Handler `libp2p.handle`
    %% only register stream handlers when you want to listen for protocols. SENDERs do not need to listen
    Local->>Connection: Open outbound stream
    Connection->>LocalMuxer: Open stream
    LocalMuxer->>RemoteMuxer: Open stream
    RemoteMuxer->>RemoteUpgrader: notify Stream created
    Note over Connection,RemoteUpgrader: multi stream select handles protocol negotiation
    Connection->>Local: return Stream
    RemoteUpgrader->>RemoteRegistrar: select stream handler
    RemoteRegistrar->>RemoteStreamHandler: handle stream
    Note over RemoteStreamHandler,Local: Stream data flow & control is dictated by protocol, below is example of "echo"
    activate Stream
    Local->>Stream: send bytes "hello world"
    Stream->>RemoteStreamHandler: receive bytes "hello world"
    %% RemoteStreamHandler->>+RemoteStreamHandler: [echo] pipe back received bytes
    RemoteStreamHandler->>Stream: echo bytes back to sender
    Stream->>Local: receive echoed bytes
    deactivate Stream

Loading

@SgtPooki
Copy link
Member

SgtPooki commented Oct 2, 2023

@maschad we should confirm where these will live and move them there. Is there anything else we want to cover in this issue, or do we want to create issues for each of the diagrams we want to create?

@maschad
Copy link
Member

maschad commented Oct 2, 2023

We can discuss tomorrow in the Open Maintainers Call but my first inclination is that there should be a section in the README until we move to a hosted docs portal.

@maschad maschad added topic/docs Documentation P0 Critical: Tackled by core team ASAP and removed need/triage Needs initial labeling and prioritization labels Oct 2, 2023
@maschad
Copy link
Member

maschad commented Oct 3, 2023

Next steps:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 Critical: Tackled by core team ASAP topic/docs Documentation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants