mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
kinda works
This commit is contained in:
parent
024f140cb7
commit
27afdd2800
2 changed files with 17 additions and 19 deletions
|
@ -87,7 +87,6 @@ func (s *Session) SetSDP(sdp string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Session) TransferFile() {
|
func (s *Session) TransferFile() {
|
||||||
go s.readFile()
|
s.readFile()
|
||||||
<-s.sess.Done
|
|
||||||
s.sess.OnCompletion()
|
s.sess.OnCompletion()
|
||||||
}
|
}
|
||||||
|
|
|
@ -361,8 +361,6 @@ func (c *Client) processMessage(m Message) (err error) {
|
||||||
c.FilesToTransferCurrentNum = remoteFile.FilesToTransferCurrentNum
|
c.FilesToTransferCurrentNum = remoteFile.FilesToTransferCurrentNum
|
||||||
c.CurrentFileChunks = remoteFile.CurrentFileChunks
|
c.CurrentFileChunks = remoteFile.CurrentFileChunks
|
||||||
c.Step3RecipientRequestFile = true
|
c.Step3RecipientRequestFile = true
|
||||||
err = c.dataChannelSend()
|
|
||||||
|
|
||||||
case "chunk":
|
case "chunk":
|
||||||
var chunk Chunk
|
var chunk Chunk
|
||||||
err = json.Unmarshal(m.Bytes, &chunk)
|
err = json.Unmarshal(m.Bytes, &chunk)
|
||||||
|
@ -398,6 +396,7 @@ func (c *Client) processMessage(m Message) (err error) {
|
||||||
c.log.Debug("got answer:", m.Message)
|
c.log.Debug("got answer:", m.Message)
|
||||||
// Apply the answer as the remote description
|
// Apply the answer as the remote description
|
||||||
err = c.sendSess.SetSDP(m.Message)
|
err = c.sendSess.SetSDP(m.Message)
|
||||||
|
c.sendSess.TransferFile()
|
||||||
case "close-sender":
|
case "close-sender":
|
||||||
c.peerConnection[m.Num].Close()
|
c.peerConnection[m.Num].Close()
|
||||||
c.peerConnection[m.Num] = nil
|
c.peerConnection[m.Num] = nil
|
||||||
|
@ -474,21 +473,20 @@ func (c *Client) updateState() (err error) {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
// pathToFile := path.Join(c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderRemote, c.FilesToTransfer[c.FilesToTransferCurrentNum].Name)
|
||||||
|
|
||||||
// check if file should be overwritten, or simply fixed with missing chunks
|
// check if file should be overwritten, or simply fixed with missing chunks
|
||||||
overwrite := true
|
// overwrite := true
|
||||||
fstats, errStats := os.Stat(pathToFile)
|
// fstats, errStats := os.Stat(pathToFile)
|
||||||
if errStats == nil {
|
// if errStats == nil {
|
||||||
if fstats.Size() == c.FilesToTransfer[c.FilesToTransferCurrentNum].Size {
|
// if fstats.Size() == c.FilesToTransfer[c.FilesToTransferCurrentNum].Size {
|
||||||
// just request missing chunks
|
// // just request missing chunks
|
||||||
c.CurrentFileChunks = MissingChunks(pathToFile, fstats.Size(), BufferSize)
|
// c.CurrentFileChunks = MissingChunks(pathToFile, fstats.Size(), BufferSize)
|
||||||
log.Debugf("found %d missing chunks", len(c.CurrentFileChunks))
|
// log.Debugf("found %d missing chunks", len(c.CurrentFileChunks))
|
||||||
overwrite = false
|
// overwrite = false
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
c.CurrentFileChunks = []int64{}
|
// c.CurrentFileChunks = []int64{}
|
||||||
}
|
// }
|
||||||
// if overwrite {
|
// if overwrite {
|
||||||
// os.Remove(pathToFile)
|
// os.Remove(pathToFile)
|
||||||
// c.CurrentFile, err = os.Create(pathToFile)
|
// c.CurrentFile, err = os.Create(pathToFile)
|
||||||
|
@ -516,11 +514,12 @@ func (c *Client) updateState() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Step3RecipientRequestFile = true
|
c.Step3RecipientRequestFile = true
|
||||||
|
err = c.dataChannelReceive()
|
||||||
}
|
}
|
||||||
if c.IsSender && c.Step3RecipientRequestFile && !c.Step4FileTransfer {
|
if c.IsSender && c.Step3RecipientRequestFile && !c.Step4FileTransfer {
|
||||||
c.log.Debug("start sending data!")
|
c.log.Debug("start sending data!")
|
||||||
|
err = c.dataChannelSend()
|
||||||
c.Step4FileTransfer = true
|
c.Step4FileTransfer = true
|
||||||
c.sendSess.TransferFile()
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue