Move chunk respones into goroutine to not block the listen() thread
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Sarah Jamie Lewis 2021-09-30 12:32:11 -07:00
parent 907a7ca638
commit 31666b8df8
1 changed files with 7 additions and 4 deletions

View File

@ -561,11 +561,14 @@ func (e *engine) handlePeerMessage(hostname string, eventID string, context stri
e.eventManager.Publish(event.NewEvent(event.ManifestReceived, map[event.Field]string{event.Handle: hostname, event.FileKey: fileKey, event.SerializedManifest: manifest}))
}
} else if context == event.ContextRequestFile {
for _, message := range e.filesharingSubSystem.ProcessChunkRequest(eventID, message) {
if err := e.sendPeerMessage(hostname, message); err != nil {
e.eventManager.Publish(event.NewEvent(event.SendMessageToPeerError, map[event.Field]string{event.RemotePeer: hostname, event.EventID: eventID, event.Error: err.Error()}))
chunks := e.filesharingSubSystem.ProcessChunkRequest(eventID, message)
go func() {
for _, message := range chunks {
if err := e.sendPeerMessage(hostname, message); err != nil {
e.eventManager.Publish(event.NewEvent(event.SendMessageToPeerError, map[event.Field]string{event.RemotePeer: hostname, event.EventID: eventID, event.Error: err.Error()}))
}
}
}
}()
} else if context == event.ContextSendFile {
fileKey, progress, totalChunks, _, title := e.filesharingSubSystem.ProcessChunk(eventID, message)
if len(fileKey) != 0 {