| 218 | var CloseTimeout = 10 * time.Second |
| 219 | |
| 220 | func 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 | |
| 242 | func newRawConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, closer io.Closer, receiver rawModel, connInfo ConnectionInfo, compress Compression) *rawConnection { |
| 243 | idString := deviceID.String() |