From d593a85baecc65d7f4de4aedf9fba5cd9c8ba440 Mon Sep 17 00:00:00 2001 From: Fran Bull Date: Fri, 21 Feb 2025 11:23:22 -0800 Subject: [PATCH] comments, whitespace --- tsconsensus/tsconsensus.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tsconsensus/tsconsensus.go b/tsconsensus/tsconsensus.go index 45b17f9e6..b120448a7 100644 --- a/tsconsensus/tsconsensus.go +++ b/tsconsensus/tsconsensus.go @@ -141,15 +141,20 @@ func (sl StreamLayer) Accept() (net.Conn, error) { } // Start returns a pointer to a running Consensus instance. +// Calling it with a *tsnet.Server will cause that server to join or start a consensus cluster +// with other nodes on the tailnet tagged with the clusterTag. The *tsnet.Server will run the state +// machine defined by the raft.FSM also provided, and keep it in sync with the other cluster members' +// state machines using Raft. func Start(ctx context.Context, ts *tsnet.Server, fsm raft.FSM, clusterTag string, cfg Config) (*Consensus, error) { if clusterTag == "" { return nil, errors.New("cluster tag must be provided") } - v4, _ := ts.TailscaleIPs() + cc := commandClient{ port: cfg.CommandPort, httpClient: ts.HTTPClient(), } + v4, _ := ts.TailscaleIPs() self := selfRaftNode{ id: v4.String(), host: v4.String(), @@ -172,22 +177,29 @@ func Start(ctx context.Context, ts *tsnet.Server, fsm raft.FSM, clusterTag strin return nil, errors.New("this node is not tagged with the cluster tag") } + // after startRaft it's possible some other raft node that has us in their configuration will get + // in contact, so by the time we do anything else we may already be a functioning member + // of a consensus r, err := startRaft(ts, &fsm, c.self, auth, cfg) if err != nil { return nil, err } c.raft = r + srv, err := c.serveCmdHttp(ts, auth) if err != nil { return nil, err } c.cmdHttpServer = srv + c.bootstrap(auth.allowedPeers()) + srv, err = serveMonitor(&c, ts, addr(c.self.host, cfg.MonitorPort)) if err != nil { return nil, err } c.monitorHttpServer = srv + return &c, nil } @@ -215,9 +227,6 @@ func startRaft(ts *tsnet.Server, fsm *raft.FSM, self selfRaftNode, auth *authori cfg.ConnTimeout, nil) // TODO pass in proper logging - // after NewRaft it's possible some other raft node that has us in their configuration will get - // in contact, so by the time we do anything else we may already be a functioning member - // of a consensus return raft.NewRaft(config, *fsm, logStore, stableStore, snapshots, transport) }