mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-17 02:48:57 -07:00
Merge pull request #14 from syncthing/clusterconfigrace
Connection now needs explicit Start()
This commit is contained in:
commit
7996ef0d45
@ -89,6 +89,7 @@ type Model interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Connection interface {
|
type Connection interface {
|
||||||
|
Start()
|
||||||
ID() DeviceID
|
ID() DeviceID
|
||||||
Name() string
|
Name() string
|
||||||
Index(folder string, files []FileInfo, flags uint32, options []Option) error
|
Index(folder string, files []FileInfo, flags uint32, options []Option) error
|
||||||
@ -161,12 +162,16 @@ func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiv
|
|||||||
compression: compress,
|
compression: compress,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return wireFormatConnection{&c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start creates the goroutines for sending and receiving of messages. It must
|
||||||
|
// be called exactly once after creating a connection.
|
||||||
|
func (c *rawConnection) Start() {
|
||||||
go c.readerLoop()
|
go c.readerLoop()
|
||||||
go c.writerLoop()
|
go c.writerLoop()
|
||||||
go c.pingerLoop()
|
go c.pingerLoop()
|
||||||
go c.idGenerator()
|
go c.idGenerator()
|
||||||
|
|
||||||
return wireFormatConnection{&c}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *rawConnection) ID() DeviceID {
|
func (c *rawConnection) ID() DeviceID {
|
||||||
|
@ -68,7 +68,9 @@ func TestPing(t *testing.T) {
|
|||||||
br, bw := io.Pipe()
|
br, bw := io.Pipe()
|
||||||
|
|
||||||
c0 := NewConnection(c0ID, ar, bw, newTestModel(), "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
c0 := NewConnection(c0ID, ar, bw, newTestModel(), "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
||||||
|
c0.Start()
|
||||||
c1 := NewConnection(c1ID, br, aw, newTestModel(), "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
c1 := NewConnection(c1ID, br, aw, newTestModel(), "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
||||||
|
c1.Start()
|
||||||
c0.ClusterConfig(ClusterConfigMessage{})
|
c0.ClusterConfig(ClusterConfigMessage{})
|
||||||
c1.ClusterConfig(ClusterConfigMessage{})
|
c1.ClusterConfig(ClusterConfigMessage{})
|
||||||
|
|
||||||
@ -94,7 +96,9 @@ func TestPingErr(t *testing.T) {
|
|||||||
ebw := &ErrPipe{PipeWriter: *bw, max: j, err: e}
|
ebw := &ErrPipe{PipeWriter: *bw, max: j, err: e}
|
||||||
|
|
||||||
c0 := NewConnection(c0ID, ar, ebw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
c0 := NewConnection(c0ID, ar, ebw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
||||||
|
c0.Start()
|
||||||
c1 := NewConnection(c1ID, br, eaw, m1, "name", CompressAlways)
|
c1 := NewConnection(c1ID, br, eaw, m1, "name", CompressAlways)
|
||||||
|
c1.Start()
|
||||||
c0.ClusterConfig(ClusterConfigMessage{})
|
c0.ClusterConfig(ClusterConfigMessage{})
|
||||||
c1.ClusterConfig(ClusterConfigMessage{})
|
c1.ClusterConfig(ClusterConfigMessage{})
|
||||||
|
|
||||||
@ -174,7 +178,9 @@ func TestVersionErr(t *testing.T) {
|
|||||||
br, bw := io.Pipe()
|
br, bw := io.Pipe()
|
||||||
|
|
||||||
c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
||||||
|
c0.Start()
|
||||||
c1 := NewConnection(c1ID, br, aw, m1, "name", CompressAlways)
|
c1 := NewConnection(c1ID, br, aw, m1, "name", CompressAlways)
|
||||||
|
c1.Start()
|
||||||
c0.ClusterConfig(ClusterConfigMessage{})
|
c0.ClusterConfig(ClusterConfigMessage{})
|
||||||
c1.ClusterConfig(ClusterConfigMessage{})
|
c1.ClusterConfig(ClusterConfigMessage{})
|
||||||
|
|
||||||
@ -199,7 +205,9 @@ func TestTypeErr(t *testing.T) {
|
|||||||
br, bw := io.Pipe()
|
br, bw := io.Pipe()
|
||||||
|
|
||||||
c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
||||||
|
c0.Start()
|
||||||
c1 := NewConnection(c1ID, br, aw, m1, "name", CompressAlways)
|
c1 := NewConnection(c1ID, br, aw, m1, "name", CompressAlways)
|
||||||
|
c1.Start()
|
||||||
c0.ClusterConfig(ClusterConfigMessage{})
|
c0.ClusterConfig(ClusterConfigMessage{})
|
||||||
c1.ClusterConfig(ClusterConfigMessage{})
|
c1.ClusterConfig(ClusterConfigMessage{})
|
||||||
|
|
||||||
@ -224,7 +232,9 @@ func TestClose(t *testing.T) {
|
|||||||
br, bw := io.Pipe()
|
br, bw := io.Pipe()
|
||||||
|
|
||||||
c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
c0 := NewConnection(c0ID, ar, bw, m0, "name", CompressAlways).(wireFormatConnection).next.(*rawConnection)
|
||||||
|
c0.Start()
|
||||||
c1 := NewConnection(c1ID, br, aw, m1, "name", CompressAlways)
|
c1 := NewConnection(c1ID, br, aw, m1, "name", CompressAlways)
|
||||||
|
c1.Start()
|
||||||
c0.ClusterConfig(ClusterConfigMessage{})
|
c0.ClusterConfig(ClusterConfigMessage{})
|
||||||
c1.ClusterConfig(ClusterConfigMessage{})
|
c1.ClusterConfig(ClusterConfigMessage{})
|
||||||
|
|
||||||
|
@ -12,6 +12,10 @@ type wireFormatConnection struct {
|
|||||||
next Connection
|
next Connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c wireFormatConnection) Start() {
|
||||||
|
c.next.Start()
|
||||||
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) ID() DeviceID {
|
func (c wireFormatConnection) ID() DeviceID {
|
||||||
return c.next.ID()
|
return c.next.ID()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user