Closed wemeetagain closed 1 year ago
2023-09-27 NOTES:
@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:
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)
sequence diagram:
Assumptions:
%% 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
@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?
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.
Next steps:
docs/architecture.md