diff --git a/protocol/connections/engine.go b/protocol/connections/engine.go index 959e719..5ad7e0a 100644 --- a/protocol/connections/engine.go +++ b/protocol/connections/engine.go @@ -265,12 +265,21 @@ func (e *engine) eventHandler() { serializedManifest := ev.Data[event.SerializedManifest] tempFile := ev.Data[event.TempFile] title := ev.Data[event.NameSuggestion] - // NOTE: for now there will probably only ever be a single chunk request. When we enable group - // sharing and rehosting then this loop will serve as a a way of splitting the request among multiple - // contacts - for _, message := range e.filesharingSubSystem.CompileChunkRequests(key, serializedManifest, tempFile, title) { - if err := e.sendPeerMessage(handle, message); err != nil { - e.eventManager.Publish(event.NewEvent(event.SendMessageToPeerError, map[event.Field]string{event.RemotePeer: ev.Data[event.RemotePeer], event.EventID: ev.EventID, event.Error: err.Error()})) + + // Another optimistic check here. Technically Cwtch profile should not request manifest on a download files + // but if they do then we should check if it exists up front. If it does then announce that the download + // is complete. + if _, filePath, success := e.filesharingSubSystem.VerifyFile(key); success { + log.Debugf("file verified and downloaded!") + e.eventManager.Publish(event.NewEvent(event.FileDownloaded, map[event.Field]string{event.FileKey: key, event.FilePath: filePath, event.TempFile: tempFile})) + } else { + // NOTE: for now there will probably only ever be a single chunk request. When we enable group + // sharing and rehosting then this loop will serve as a a way of splitting the request among multiple + // contacts + for _, message := range e.filesharingSubSystem.CompileChunkRequests(key, serializedManifest, tempFile, title) { + if err := e.sendPeerMessage(handle, message); err != nil { + e.eventManager.Publish(event.NewEvent(event.SendMessageToPeerError, map[event.Field]string{event.RemotePeer: ev.Data[event.RemotePeer], event.EventID: ev.EventID, event.Error: err.Error()})) + } } } case event.ProtocolEngineShutdown: