mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Need to add concurrent reading from the file
Perhaps using this: https://play.golang.org/p/kyusY5Dc0W
This commit is contained in:
parent
9e1d7b4460
commit
7ad54dced3
1 changed files with 14 additions and 2 deletions
14
connect.go
14
connect.go
|
@ -79,16 +79,21 @@ func (c *Connection) Run() error {
|
||||||
// check code
|
// check code
|
||||||
goodCode := true
|
goodCode := true
|
||||||
m := strings.Split(c.Code, "-")
|
m := strings.Split(c.Code, "-")
|
||||||
|
log.Debug(m)
|
||||||
numThreads, errParse := strconv.Atoi(m[0])
|
numThreads, errParse := strconv.Atoi(m[0])
|
||||||
if len(m) < 2 {
|
if len(m) < 2 {
|
||||||
goodCode = false
|
goodCode = false
|
||||||
|
log.Debug("code too short")
|
||||||
} else if numThreads > MAX_NUMBER_THREADS || numThreads < 1 || (forceSingleThreaded && numThreads != 1) {
|
} else if numThreads > MAX_NUMBER_THREADS || numThreads < 1 || (forceSingleThreaded && numThreads != 1) {
|
||||||
c.NumberOfConnections = MAX_NUMBER_THREADS
|
c.NumberOfConnections = MAX_NUMBER_THREADS
|
||||||
goodCode = false
|
goodCode = false
|
||||||
|
log.Debug("incorrect number of threads")
|
||||||
} else if errParse != nil {
|
} else if errParse != nil {
|
||||||
goodCode = false
|
goodCode = false
|
||||||
|
log.Debug("problem parsing threads")
|
||||||
}
|
}
|
||||||
log.Debug(m)
|
log.Debug(m)
|
||||||
|
log.Debug(goodCode)
|
||||||
if !goodCode {
|
if !goodCode {
|
||||||
if c.IsSender {
|
if c.IsSender {
|
||||||
if forceSingleThreaded {
|
if forceSingleThreaded {
|
||||||
|
@ -236,7 +241,9 @@ func (c *Connection) runClient() error {
|
||||||
} else {
|
} else {
|
||||||
sendMessage("ok", connection)
|
sendMessage("ok", connection)
|
||||||
logger.Debug("receive file")
|
logger.Debug("receive file")
|
||||||
|
if id == 0 {
|
||||||
fmt.Printf("\n\nReceiving (<-%s)..\n", sendersAddress)
|
fmt.Printf("\n\nReceiving (<-%s)..\n", sendersAddress)
|
||||||
|
}
|
||||||
c.receiveFile(id, connection)
|
c.receiveFile(id, connection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -341,6 +348,7 @@ func (c *Connection) receiveFile(id int, connection net.Conn) error {
|
||||||
|
|
||||||
logger.Debug("waiting for file")
|
logger.Debug("waiting for file")
|
||||||
var receivedBytes int64
|
var receivedBytes int64
|
||||||
|
receivedFirstBytes := false
|
||||||
for {
|
for {
|
||||||
if !c.Debug {
|
if !c.Debug {
|
||||||
c.bars[id].Incr()
|
c.bars[id].Incr()
|
||||||
|
@ -357,6 +365,10 @@ func (c *Connection) receiveFile(id int, connection net.Conn) error {
|
||||||
}
|
}
|
||||||
io.CopyN(newFile, connection, BUFFERSIZE)
|
io.CopyN(newFile, connection, BUFFERSIZE)
|
||||||
receivedBytes += BUFFERSIZE
|
receivedBytes += BUFFERSIZE
|
||||||
|
if !receivedFirstBytes {
|
||||||
|
receivedFirstBytes = true
|
||||||
|
logger.Debug("Receieved first bytes!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
logger.Debug("received file")
|
logger.Debug("received file")
|
||||||
return nil
|
return nil
|
||||||
|
@ -390,7 +402,7 @@ func (c *Connection) sendFile(id int, connection net.Conn) {
|
||||||
sendBuffer := make([]byte, BUFFERSIZE)
|
sendBuffer := make([]byte, BUFFERSIZE)
|
||||||
|
|
||||||
// open encrypted file
|
// open encrypted file
|
||||||
file, err := os.Open(c.File.Name + ".enc")
|
file, err := os.OpenFile(c.File.Name+".enc", os.O_RDONLY, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue