|
|
@@ -184,6 +184,7 @@ type rawConnection struct {
|
|
|
|
|
|
inbox chan message
|
|
|
outbox chan asyncMessage
|
|
|
+ clusterConfigBox chan *ClusterConfig
|
|
|
dispatcherLoopStopped chan struct{}
|
|
|
closed chan struct{}
|
|
|
closeOnce sync.Once
|
|
|
@@ -230,6 +231,7 @@ func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiv
|
|
|
awaiting: make(map[int32]chan asyncResult),
|
|
|
inbox: make(chan message),
|
|
|
outbox: make(chan asyncMessage),
|
|
|
+ clusterConfigBox: make(chan *ClusterConfig),
|
|
|
dispatcherLoopStopped: make(chan struct{}),
|
|
|
closed: make(chan struct{}),
|
|
|
compression: compress,
|
|
|
@@ -327,9 +329,11 @@ func (c *rawConnection) Request(folder string, name string, offset int64, size i
|
|
|
return res.val, res.err
|
|
|
}
|
|
|
|
|
|
-// ClusterConfig send the cluster configuration message to the peer and returns any error
|
|
|
+// 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) {
|
|
|
- c.send(&config, nil)
|
|
|
+ c.clusterConfigBox <- &config
|
|
|
+ close(c.clusterConfigBox)
|
|
|
}
|
|
|
|
|
|
func (c *rawConnection) Closed() bool {
|
|
|
@@ -657,6 +661,16 @@ func (c *rawConnection) send(msg message, done chan struct{}) bool {
|
|
|
}
|
|
|
|
|
|
func (c *rawConnection) writerLoop() {
|
|
|
+ select {
|
|
|
+ case cc := <-c.clusterConfigBox:
|
|
|
+ err := c.writeMessage(cc)
|
|
|
+ if err != nil {
|
|
|
+ c.internalClose(err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ case <-c.closed:
|
|
|
+ return
|
|
|
+ }
|
|
|
for {
|
|
|
select {
|
|
|
case hm := <-c.outbox:
|