@@ -52,11 +52,55 @@ The bundle integrates four Anytype sync services into a single binary:
5252
5353### Critical: Service Startup Order
5454
55- ** ORDER MATTERS!** Services must start in this exact order ( ` cmd/start.go:83-87 ` ) :
56- 1 . ** Coordinator** - provides network coordination for all other services
57- 2 . ** Consensus, File, Sync** - can start in any order (all depend on coordinator )
55+ ** ORDER MATTERS!** Services must start in this exact order:
56+ 1 . ** Coordinator** - MUST start first ( provides shared network stack for all services)
57+ 2 . ** Consensus, File, Sync** - start after coordinator (reuse its network stack )
5858
59- If coordinator doesn't start first, other services will fail to connect.
59+ The coordinator creates the network infrastructure (TCP/UDP listeners, DRPC mux, connection pool).
60+ Other services extract and reuse these components via ` SharedNetworkManager ` .
61+
62+ ### Shared Network Architecture
63+
64+ ** Key Innovation** : Instead of each service creating its own network stack, all services share ONE network infrastructure:
65+
66+ ```
67+ Coordinator App (Primary)
68+ ├── Creates network stack
69+ │ ├── yamux (TCP listener on port 33010)
70+ │ ├── quic (UDP listener on port 33020)
71+ │ ├── server (DRPC multiplexer)
72+ │ ├── pool (connection pool)
73+ │ └── peerservice (peer management)
74+ └── Registers CoordinatorService RPC handlers
75+
76+ SharedNetworkManager
77+ ├── Extracts network components from coordinator
78+ └── Provides them to secondary services
79+
80+ Secondary Apps (Consensus, FileNode, Sync)
81+ ├── Receive shared network via SharedNetworkManager
82+ ├── Register their own RPC handlers to shared DRPC mux
83+ └── Service-specific components only
84+ ```
85+
86+ ** Benefits** :
87+ - Single port pair (33010 TCP, 33020 UDP) instead of 8 ports
88+ - Shared connection pool - all services reuse peer connections
89+ - Reduced memory usage - one network stack instead of four
90+ - True service bundling
91+
92+ ** Implementation** (` lightnode/sharednetwork.go ` ):
93+ - ` ExtractSharedNetwork(app) ` - extracts network components from coordinator
94+ - ` RegisterToApp(app) ` - injects shared components into secondary services
95+
96+ ** Startup Flow** (` cmd/start.go ` ):
97+ 1 . Create coordinator app (full network stack)
98+ 2 . Start coordinator
99+ 3 . Extract shared network via ` ExtractSharedNetwork(coordinatorApp) `
100+ 4 . Create secondary apps with ` sharedNet ` parameter
101+ 5 . Start secondary apps (they reuse coordinator's network)
102+
103+ ** Backward Compatibility** : Services can still run standalone by passing ` nil ` for ` sharedNet ` parameter.
60104
61105### Key Components
62106
@@ -80,8 +124,17 @@ If coordinator doesn't start first, other services will fail to connect.
80124
81125## Service Port Mapping
82126
83- - TCP ports: 33010-33013 (various sync services)
84- - UDP ports: 33020-33023 (QUIC transport)
127+ ** New Shared Network Architecture** (default):
128+ - TCP port: 33010 (ALL services share ONE listener)
129+ - UDP port: 33020 (ALL services share ONE listener)
130+
131+ All services (coordinator, consensus, filenode, sync) register their RPC handlers to a single DRPC multiplexer:
132+ - Coordinator: ` /CoordinatorService/* `
133+ - Consensus: ` /ConsensusService/* `
134+ - FileNode: ` /FileService/* `
135+ - SyncNode: ` /SpaceSyncService/* `
136+
137+ These method namespaces don't conflict, so they coexist in one mux.
85138
86139## Configuration Patterns
87140
0 commit comments