Browse Source

[node] improved mainloop logic

main
Unbewohnte 3 years ago
parent
commit
d0d15f2bd5
  1. 13
      src/node/node.go

13
src/node/node.go

@ -246,6 +246,12 @@ func (node *Node) Start() {
protocol.SendPacket(node.Net.Conn, endFilePacket) protocol.SendPacket(node.Net.Conn, endFilePacket)
// because there`s still no handling for directories - send
// done packet
protocol.SendPacket(node.Net.Conn, protocol.Packet{
Header: protocol.HeaderDone,
})
node.State.Stopped = true node.State.Stopped = true
} else { } else {
node.State.Stopped = true node.State.Stopped = true
@ -302,7 +308,7 @@ func (node *Node) Start() {
panic(err) panic(err)
} }
fmt.Printf("| ID: %d\n| Filename: %s\n| Size: %.2f MB\n| Checksum: %s\n", file.ID, file.Name, float32(file.Size)/1024/1024, file.Checksum) fmt.Printf("| Filename: %s\n| Size: %.2f MB\n| Checksum: %s\n", file.Name, float32(file.Size)/1024/1024, file.Checksum)
var answer string var answer string
fmt.Printf("| Download ? [Y/n]: ") fmt.Printf("| Download ? [Y/n]: ")
fmt.Scanln(&answer) fmt.Scanln(&answer)
@ -453,7 +459,7 @@ func (node *Node) Start() {
} }
} }
node.State.Stopped = true // node.State.Stopped = true
case protocol.HeaderEncryptionKey: case protocol.HeaderEncryptionKey:
// retrieve the key // retrieve the key
@ -467,6 +473,9 @@ func (node *Node) Start() {
node.Net.EncryptionKey = encrKey node.Net.EncryptionKey = encrKey
case protocol.HeaderDone:
node.State.Stopped = true
case protocol.HeaderDisconnecting: case protocol.HeaderDisconnecting:
node.State.Stopped = true node.State.Stopped = true

Loading…
Cancel
Save