From 1d24d125076af4b017dd124ccb2334263864cdf5 Mon Sep 17 00:00:00 2001 From: AaronH88 Date: Tue, 16 Jan 2024 19:59:20 +0000 Subject: [PATCH] Create sequence diagram for adding a backend tcp listener (#773) Co-authored-by: Matthew Sandoval --- docs/diagrams/AddListenerBackend.md | 73 +++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 docs/diagrams/AddListenerBackend.md diff --git a/docs/diagrams/AddListenerBackend.md b/docs/diagrams/AddListenerBackend.md new file mode 100644 index 000000000..9d6493ada --- /dev/null +++ b/docs/diagrams/AddListenerBackend.md @@ -0,0 +1,73 @@ +```mermaid +sequenceDiagram + participant Application + participant Netceptor + participant Netceptor closures + participant Netceptor connectInfo ReadChan + participant Netceptor connectInfo WriteChan + Application->>+Netceptor: New + Netceptor-->>-Application: netceptor instance n1 + Application->>+Backend tcp.go: NewTCPListener + Backend tcp.go-->>-Application: backendsTCPListener b1 + Application->>+Netceptor: AddBackend(b1) + Netceptor->>Netceptor: backendCancel(context) + Netceptor->>+Backend tcp.go:(Backend Interface) b1.Start(context, waitgroup) + Backend tcp.go->>+Backend utils.go:listenerSession(context, waitgroup, logger, ListenFunc, AcceptFunc, CancelFunc) + Backend utils.go->>+Backend tcp.go:ListenFunc() + Backend tcp.go-->>-Backend utils.go:error + Backend utils.go->>Backend utils.go:create chan BackendSession + Backend utils.go-)+Backend sessChan Closure:go closure + loop Every time AcceptFunc is called + Backend sessChan Closure->>Backend sessChan Closure:AcceptFunc + end + + Backend utils.go-->>-Backend tcp.go:chan (Backend Interface) BackendsSession + Backend tcp.go-->>-Netceptor: chan (Backend Interface) BackendsSession + Netceptor->>+Netceptor closures: go closure + Netceptor closures->>+Netceptor closures: go closure + Netceptor closures->>Netceptor closures: runProtocol(context, backend session, backendInfo) + Netceptor closures->>+Netceptor connectInfo ReadChan: make (chan []byte) + Netceptor closures->>+Netceptor connectInfo WriteChan: make (chan []byte) + Netceptor closures-)Netceptor closures: protoReader(backend session) + loop + Backend sessChan Closure->>Netceptor closures: sess.Recv(1 * time.Second) + Netceptor closures->>Netceptor connectInfo ReadChan: ci.ReadChan <- buf + end + loop + Netceptor connectInfo WriteChan->>Netceptor closures: message, more = <-ci.WriteChan + Netceptor closures->>Backend sessChan Closure: sess.Send(message) + end + Netceptor closures-)Netceptor closures: protoWriter(backend session) + Netceptor closures-)+Netceptor closures: s.sendInitialConnectMessage(ci, initDoneChan) + Netceptor closures-)Netceptor closures: s.translateStructToNetwork(MsgTypeRoute, s.makeRoutingUpdate(0)) + Netceptor closures-)-Netceptor closures: context.Done() + Netceptor connectInfo ReadChan->>Netceptor closures: data = <-ci.ReadChan + alt established + alt MsgTypeData + Netceptor closures->>Netceptor closures: translateDataToMessage(data []byte) + else MsgTypeRoute + Netceptor closures->>Netceptor closures: s.handleRoutingUpdate(ri, remoteNodeID) + else MsgTypeServiceAdvertisement + Netceptor closures->>Netceptor closures: s.handleServiceAdvertisement(data, remoteNodeID) + else MsgTypeReject + Netceptor closures->>Netceptor closures: return error + end + else !established + alt msgType == MsgTypeRoute + Netceptor closures->>Netceptor closures: add connection + else msgType == MsgTypeReject + Netceptor closures->>Netceptor closures: return error + end + end + + Netceptor closures->>Netceptor connectInfo WriteChan: ci.WriteChan <- ConnectMessage + Netceptor closures->>-Netceptor closures: wg Done() + Backend sessChan Closure->>Backend sessChan Closure:CancelFunc + Backend sessChan Closure-->>-Application:context.Done() + Netceptor->>Netceptor closures: wg Done() + Netceptor closures-->>-Netceptor: + Netceptor connectInfo ReadChan-->>-Netceptor closures: context.Done() + Netceptor connectInfo WriteChan-->>-Netceptor closures: context.Done() + +``` +