syncthing/lib/connections
Jakob Borg e52be3d83e lib/connections, lib/model: Refactor connection close handling (fixes #3466)
So there were some issues here. The main problem was that
model.Close(deviceID) was overloaded to mean "the connection was closed
by the protocol layer" and "i want to close this connection". That meant
it could get called twice - once *to* close the connection and then once
more when the connection *was* closed.

After this refactor there is instead a Closed(conn) method that is the
callback. I didn't need to change the parameter in the end, but I think
it's clearer what it means when it takes the connection that was closed
instead of a device ID. To close a connection, the new close(deviceID)
method is used instead, which only closes the underlying connection and
leaves the cleanup to the Closed() callback.

I also changed how we do connection switching. Instead of the connection
service calling close and then adding the connection, it just adds the
new connection. The model knows that it already has a connection and
makes sure to close and clean out that one before adding the new
connection.

To make sure to sequence this properly I added a new map of channels
that get created on connection add and closed by Closed(), so that
AddConnection() can do the close and wait for the cleanup to happen
before proceeding.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3490
2016-08-10 09:37:32 +00:00
..
debug.go Implement facility based logger, debugging via REST API 2015-10-03 18:09:53 +02:00
empty_test.go build, lib: Correct total test coverage calculation 2016-08-08 16:29:32 +00:00
limitedreader.go Decouple connections service from model 2015-09-25 12:19:30 -04:00
limitedwriter.go Decouple connections service from model 2015-09-25 12:19:30 -04:00
relay_dial.go lib/connections: TLS handshake must complete in a timely fashion (fixes #3375) 2016-07-02 20:33:31 +00:00
relay_listen.go lib/connections: TLS handshake must complete in a timely fashion (fixes #3375) 2016-07-02 20:33:31 +00:00
service.go lib/connections, lib/model: Refactor connection close handling (fixes #3466) 2016-08-10 09:37:32 +00:00
structs.go lib/connections, lib/model: Refactor connection close handling (fixes #3466) 2016-08-10 09:37:32 +00:00
tcp_dial.go lib/connections: TLS handshake must complete in a timely fashion (fixes #3375) 2016-07-02 20:33:31 +00:00
tcp_listen.go lib/connections: TLS handshake must complete in a timely fashion (fixes #3375) 2016-07-02 20:33:31 +00:00