From c58aaf860dfc61faed10f71474e9639484c94e3b Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 9 Apr 2019 09:54:09 -0700 Subject: [PATCH] can stop sending --- pkg/session/sender/io.go | 6 ++++-- pkg/session/sender/state.go | 6 +++++- src/croc/croc.go | 21 +++++++++------------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pkg/session/sender/io.go b/pkg/session/sender/io.go index fb2a7b7e..d30e62e8 100644 --- a/pkg/session/sender/io.go +++ b/pkg/session/sender/io.go @@ -76,10 +76,12 @@ func (s *Session) onBufferedAmountLow() func() { func (s *Session) writeToNetwork() { // Set callback, as transfer may be paused + fmt.Println("\nwriting") s.dataChannel.OnBufferedAmountLow(s.onBufferedAmountLow()) - + fmt.Println("\ndone") <-s.stopSending + fmt.Println("\nstopped sending") s.dataChannel.OnBufferedAmountLow(nil) - s.sess.NetworkStats.Pause() log.Infof("Pausing network I/O... (remaining at least %v packets)\n", len(s.output)) + s.sess.NetworkStats.Pause() } diff --git a/pkg/session/sender/state.go b/pkg/session/sender/state.go index 47075424..cac51287 100644 --- a/pkg/session/sender/state.go +++ b/pkg/session/sender/state.go @@ -7,11 +7,15 @@ import ( log "github.com/sirupsen/logrus" ) +func (s *Session) StopSending() { + s.stopSending <- struct{}{} +} + func (s *Session) onConnectionStateChange() func(connectionState webrtc.ICEConnectionState) { return func(connectionState webrtc.ICEConnectionState) { log.Infof("ICE Connection State has changed: %s\n", connectionState.String()) if connectionState == webrtc.ICEConnectionStateDisconnected { - s.stopSending <- struct{}{} + s.StopSending() } } } diff --git a/src/croc/croc.go b/src/croc/croc.go index e6768e4e..d2f99a34 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -392,7 +392,10 @@ func (c *Client) processMessage(m Message) (err error) { // start receiving data pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name) c.recvSess.ReceiveData(pathToFile) - + fmt.Println("\ndone receiving") + err = c.redisdb.Publish(c.nameOutChannel, Message{ + Type: "close-sender", + }.String()).Err() case "datachannel-answer": c.log.Debug("got answer:", m.Message) // Apply the answer as the remote description @@ -400,22 +403,16 @@ func (c *Client) processMessage(m Message) (err error) { pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderSource, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name) c.sendSess.TransferFile(pathToFile) case "close-sender": - c.peerConnection[m.Num].Close() - c.peerConnection[m.Num] = nil - c.dataChannel[m.Num].Close() - c.dataChannel[m.Num] = nil - // c.Step4FileTransfer = false - // c.Step3RecipientRequestFile = false + c.Step4FileTransfer = false + c.Step3RecipientRequestFile = false + c.sendSess.StopSending() err = c.redisdb.Publish(c.nameOutChannel, Message{ Type: "close-recipient", Num: m.Num, }.String()).Err() case "close-recipient": - c.peerConnection[m.Num].Close() - c.peerConnection[m.Num] = nil - c.dataChannel[m.Num] = nil - // c.Step4FileTransfer = false - // c.Step3RecipientRequestFile = false + c.Step4FileTransfer = false + c.Step3RecipientRequestFile = false } if err != nil { return