(conn protocol.Connection, downloads *deviceDownloadState, folder config.FolderConfiguration, sdb db.DB, runner service, startInfo *clusterConfigDeviceInfo, evLogger events.Logger)
| 53 | } |
| 54 | |
| 55 | func newIndexHandler(conn protocol.Connection, downloads *deviceDownloadState, folder config.FolderConfiguration, sdb db.DB, runner service, startInfo *clusterConfigDeviceInfo, evLogger events.Logger) (*indexHandler, error) { |
| 56 | myIndexID, err := sdb.GetIndexID(folder.ID, protocol.LocalDeviceID) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | mySequence, err := sdb.GetDeviceSequence(folder.ID, protocol.LocalDeviceID) |
| 61 | if err != nil { |
| 62 | return nil, err |
| 63 | } |
| 64 | var startSequence int64 |
| 65 | |
| 66 | // This is the other side's description of what it knows |
| 67 | // about us. Lets check to see if we can start sending index |
| 68 | // updates directly or need to send the index from start... |
| 69 | |
| 70 | switch startInfo.local.IndexID { |
| 71 | case myIndexID: |
| 72 | // They say they've seen our index ID before, so we can |
| 73 | // send a delta update only. |
| 74 | |
| 75 | if startInfo.local.MaxSequence > mySequence { |
| 76 | // Safety check. They claim to have more or newer |
| 77 | // index data than we have - either we have lost |
| 78 | // index data, or reset the index without resetting |
| 79 | // the IndexID, or something else weird has |
| 80 | // happened. We send a full index to reset the |
| 81 | // situation. |
| 82 | slog.Warn("Peer is delta index compatible, but seems out of sync with reality", conn.DeviceID().LogAttr(), folder.LogAttr()) |
| 83 | startSequence = 0 |
| 84 | } else { |
| 85 | l.Debugf("Device %v folder %s is delta index compatible (mlv=%d)", conn.DeviceID().Short(), folder.Description(), startInfo.local.MaxSequence) |
| 86 | startSequence = startInfo.local.MaxSequence |
| 87 | } |
| 88 | |
| 89 | case 0: |
| 90 | l.Debugf("Device %v folder %s has no index ID for us", conn.DeviceID().Short(), folder.Description()) |
| 91 | |
| 92 | default: |
| 93 | // They say they've seen an index ID from us, but it's |
| 94 | // not the right one. Either they are confused or we |
| 95 | // must have reset our database since last talking to |
| 96 | // them. We'll start with a full index transfer. |
| 97 | slog.Warn("Peer has mismatching index ID for us", conn.DeviceID().LogAttr(), folder.LogAttr(), slog.Group("indexid", slog.Any("ours", myIndexID), slog.Any("theirs", startInfo.local.IndexID))) |
| 98 | startSequence = 0 |
| 99 | } |
| 100 | |
| 101 | // This is the other side's description of themselves. We |
| 102 | // check to see that it matches the IndexID we have on file, |
| 103 | // otherwise we drop our old index data and expect to get a |
| 104 | // completely new set. |
| 105 | |
| 106 | theirIndexID, _ := sdb.GetIndexID(folder.ID, conn.DeviceID()) |
| 107 | if startInfo.remote.IndexID == 0 { |
| 108 | // They're not announcing an index ID. This means they |
| 109 | // do not support delta indexes and we should clear any |
| 110 | // information we have from them before accepting their |
| 111 | // index, which will presumably be a full index. |
| 112 | l.Debugf("Device %v folder %s does not announce an index ID", conn.DeviceID().Short(), folder.Description()) |
no test coverage detected