Skip to content

Commit

Permalink
[Node] Invalid transfer info printing is >>|FIXED|<<
Browse files Browse the repository at this point in the history
  • Loading branch information
Unbewohnte committed Jan 9, 2022
1 parent 382908c commit 4d12a15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

var (
VERSION string = "v2.2.1"
VERSION string = "v2.2.2"

versionInformation string = fmt.Sprintf("ftu %s\n\nCopyright (C) 2021,2022 Kasyanov Nikolay Alexeevich (Unbewohnte (https://unbewohnte.xyz/))\nThis program comes with ABSOLUTELY NO WARRANTY.\nThis is free software, and you are welcome to redistribute it under certain conditions; type \"ftu -l\" for details.\n", VERSION)

Expand Down
39 changes: 23 additions & 16 deletions src/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ func (node *Node) send() {
break
}

if !node.verboseOutput {
go node.printTransferInfo(time.Second)
}

// receive incoming packets and decrypt them if necessary
incomingPacket, ok := <-node.packetPipe
if !ok {
Expand Down Expand Up @@ -395,12 +399,13 @@ func (node *Node) send() {

node.transferInfo.Sending.SentBytes += fileToSend.Size

node.transferInfo.Sending.InTransfer = false

if node.verboseOutput {
fmt.Printf("\n[File] receiver already has \"%s\"", fileToSend.Name)
}
}
}

}

// Transfer section
Expand All @@ -411,7 +416,6 @@ func (node *Node) send() {
Header: protocol.HeaderDone,
})

fmt.Printf("\nTransfer ended successfully")
node.stopped = true

continue
Expand Down Expand Up @@ -451,10 +455,6 @@ func (node *Node) send() {
continue
}

if !node.verboseOutput {
go node.printTransferInfo(time.Second)
}

// if allowed to transfer and the other node is ready to receive packets - send one piece
// and wait for it to be ready again
if node.transferInfo.Sending.AllowedToTransfer && node.transferInfo.Sending.CanSendBytes && node.transferInfo.Sending.InTransfer {
Expand Down Expand Up @@ -544,6 +544,10 @@ func (node *Node) receive() {
break
}

if !node.verboseOutput && node.transferInfo.Receiving.ReceivedBytes != 0 {
go node.printTransferInfo(time.Second)
}

// receive incoming packets and decrypt them if necessary
incomingPacket, ok := <-node.packetPipe
if !ok {
Expand Down Expand Up @@ -718,6 +722,13 @@ func (node *Node) receive() {
node.mutex.Lock()
node.transferInfo.Receiving.AcceptedFiles = append(node.transferInfo.Receiving.AcceptedFiles, file)
node.mutex.Unlock()

err = protocol.SendPacket(node.netInfo.Conn, protocol.Packet{
Header: protocol.HeaderReady,
})
if err != nil {
panic(err)
}
}

existingFileHandler.Close()
Expand All @@ -727,13 +738,13 @@ func (node *Node) receive() {
node.mutex.Lock()
node.transferInfo.Receiving.AcceptedFiles = append(node.transferInfo.Receiving.AcceptedFiles, file)
node.mutex.Unlock()
}

err = protocol.SendPacket(node.netInfo.Conn, protocol.Packet{
Header: protocol.HeaderReady,
})
if err != nil {
panic(err)
err = protocol.SendPacket(node.netInfo.Conn, protocol.Packet{
Header: protocol.HeaderReady,
})
if err != nil {
panic(err)
}
}

case protocol.HeaderFileBytes:
Expand Down Expand Up @@ -855,10 +866,6 @@ func (node *Node) receive() {

fmt.Printf("\n%s disconnected", node.netInfo.Conn.RemoteAddr())
}

if !node.verboseOutput && node.transferInfo.Receiving.ReceivedBytes != 0 {
go node.printTransferInfo(time.Second)
}
}
}

Expand Down

0 comments on commit 4d12a15

Please sign in to comment.