MCPcopy
hub / github.com/syncthing/syncthing / NewConnection

Function NewConnection

lib/protocol/protocol.go:220–240  ·  view source on GitHub ↗
(deviceID DeviceID, reader io.Reader, writer io.Writer, closer io.Closer, model Model, connInfo ConnectionInfo, compress Compression, keyGen *KeyGenerator)

Source from the content-addressed store, hash-verified

218var CloseTimeout = 10 * time.Second
219
220func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, closer io.Closer, model Model, connInfo ConnectionInfo, compress Compression, keyGen *KeyGenerator) Connection {
221 // We create the wrapper for the model first, as it needs to be passed
222 // in at the lowest level in the stack. At the end of construction,
223 // before returning, we add the connection to cwm so that it can be used
224 // by the model.
225 cwm := &connectionWrappingModel{model: model}
226
227 // Encryption / decryption is first (outermost) before conversion to
228 // native path formats.
229 nm := makeNative(cwm)
230 em := newEncryptedModel(nm, keyGen)
231
232 // We do the wire format conversion first (outermost) so that the
233 // metadata is in wire format when it reaches the encryption step.
234 rc := newRawConnection(deviceID, reader, writer, closer, em, connInfo, compress)
235 ec := newEncryptedConnection(rc, rc, em.folderKeys, keyGen)
236 wc := wireFormatConnection{ec}
237
238 cwm.conn = wc
239 return wc
240}
241
242func newRawConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, closer io.Closer, receiver rawModel, connInfo ConnectionInfo, compress Compression) *rawConnection {
243 idString := deviceID.String()

Callers 15

handleHellosMethod · 0.92
TestConnCloseOnRestartFunction · 0.92
TestPingFunction · 0.85
TestCloseFunction · 0.85
TestCloseOnBlockingSendFunction · 0.85
TestCloseRaceFunction · 0.85
TestClusterConfigFirstFunction · 0.85
TestCloseTimeoutFunction · 0.85
TestRequestMaxSizeFunction · 0.85

Calls 4

newEncryptedModelFunction · 0.85
newRawConnectionFunction · 0.85
newEncryptedConnectionFunction · 0.85
makeNativeFunction · 0.70

Tested by 14

TestConnCloseOnRestartFunction · 0.74
TestPingFunction · 0.68
TestCloseFunction · 0.68
TestCloseOnBlockingSendFunction · 0.68
TestCloseRaceFunction · 0.68
TestClusterConfigFirstFunction · 0.68
TestCloseTimeoutFunction · 0.68
TestRequestMaxSizeFunction · 0.68
TestRequestZeroSizeFunction · 0.68