lib/model, lib/protocol: Send ClusterConfig on config change (fixes #7020) (#7018)

This commit is contained in:
Simon Frei
2020-10-02 11:49:51 +02:00
committed by GitHub
parent e027175446
commit a20c6ca868
4 changed files with 155 additions and 116 deletions
+8 -5
View File
@@ -322,11 +322,9 @@ func (c *rawConnection) Request(ctx context.Context, folder string, name string,
}
// ClusterConfig sends the cluster configuration message to the peer.
// It must be called just once (as per BEP), otherwise it will panic.
func (c *rawConnection) ClusterConfig(config ClusterConfig) {
select {
case c.clusterConfigBox <- &config:
close(c.clusterConfigBox)
case <-c.closed:
}
}
@@ -386,13 +384,12 @@ func (c *rawConnection) dispatcherLoop() (err error) {
switch msg := msg.(type) {
case *ClusterConfig:
l.Debugln("read ClusterConfig message")
if state != stateInitial {
return fmt.Errorf("protocol error: cluster config message in state %d", state)
if state == stateInitial {
state = stateReady
}
if err := c.receiver.ClusterConfig(c.id, *msg); err != nil {
return errors.Wrap(err, "receiver error")
}
state = stateReady
case *Index:
l.Debugln("read Index message")
@@ -683,6 +680,12 @@ func (c *rawConnection) writerLoop() {
}
for {
select {
case cc := <-c.clusterConfigBox:
err := c.writeMessage(cc)
if err != nil {
c.internalClose(err)
return
}
case hm := <-c.outbox:
err := c.writeMessage(hm.msg)
if hm.done != nil {