Browse Source

v2.2.0; Fixed freezing on big amount of files; Improved transfer data printing; Introduction to some minor bugs with it as well, but that is not a severe problem anyway

main
Unbewohnte 3 years ago
parent
commit
0ac9cd2b71
  1. 2
      src/main.go
  2. 1028
      src/node/node.go
  3. 16
      src/protocol/headers.go
  4. 23
      src/protocol/send.go

2
src/main.go

@ -30,7 +30,7 @@ import (
)
var (
VERSION string = "v2.1.4"
VERSION string = "v2.2.0"
versionInformation string = fmt.Sprintf("ftu %s\n\nCopyright (C) 2021 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)

1028
src/node/node.go

File diff suppressed because it is too large Load Diff

16
src/protocol/headers.go

@ -29,7 +29,7 @@ type Header string
//// and (size) is 8 bytes long big-endian binary encoded uint64
// ENCRKEY.
// The FIRST header to be sent. Sent immediately after the connection has been established
// The FIRST header to be sent if you`re going to encrypt the transfer. Sent immediately after the connection has been established
// by sender. Body contains a size of a key and the key itself.
// ie: ENCRKEY~(size)(encryption key)
const HeaderEncryptionKey Header = "ENCRKEY"
@ -41,7 +41,7 @@ const HeaderReject Header = "REJECT"
// ACCEPT.
// The opposite of the previous REJECT. Sent by receiver when
// he has agreed to download the file|directory.
// it has agreed to download the file|directory.
// ie: ACCEPT~
const HeaderAccept Header = "ACCEPT"
@ -55,19 +55,11 @@ const HeaderDone Header = "DONE"
// READY.
// Sent by receiver when it has read and processed the last
// FILEBYTES packet or when it has information about all the files and it`s ready to
// receive bytes (FILESINFODONE). The sender is not allowed to "spam" FILEBYTES
// packets without the permission of receiver.
// FILEBYTES or FILE packet. The sender is not allowed to "spam" FILEBYTES or FILE
// packets without the permission (packet with this header) from receiver.
// ie: READY!~
const HeaderReady Header = "READY"
// FILESINFODONE.
// Sent by sender after it`s announced about all the files that are
// going to be sent. It is not allowed to send any file bytes before
// packet with this header was sent.
// ie: FILESINFODONE~
const HeaderFilesInfoDone Header = "FILESINFODONE"
// BYE!.
// Packet with this header can be sent both by receiver and sender.
// It`s used when the sender or the receiver are going to disconnect

23
src/protocol/send.go

@ -137,13 +137,15 @@ func SendTransferOffer(connection net.Conn, file *fsys.File, dir *fsys.Directory
var ErrorSentAll error = fmt.Errorf("sent the whole file")
// sends a piece of file to the connection; The next calls will send
// Sends a piece of file to the connection; The next calls will send
// another piece util the file has been fully sent. If encrKey is not nil - encrypts each packet with
// this key
func SendPiece(file *fsys.File, connection net.Conn, encrKey []byte) error {
// this key. Returns amount of filebytes written to the connection
func SendPiece(file *fsys.File, connection net.Conn, encrKey []byte) (uint64, error) {
var sentBytes uint64 = 0
err := file.Open()
if err != nil {
return err
return sentBytes, err
}
defer file.Close()
@ -152,7 +154,7 @@ func SendPiece(file *fsys.File, connection net.Conn, encrKey []byte) error {
}
if file.Size == file.SentBytes {
return ErrorSentAll
return sentBytes, ErrorSentAll
}
fileBytesPacket := Packet{
@ -164,7 +166,7 @@ func SendPiece(file *fsys.File, connection net.Conn, encrKey []byte) error {
// write file ID first
err = binary.Write(packetBodyBuff, binary.BigEndian, file.ID)
if err != nil {
return err
return sentBytes, err
}
// fill the remaining space of packet with the contents of a file
@ -183,9 +185,10 @@ func SendPiece(file *fsys.File, connection net.Conn, encrKey []byte) error {
read, err := file.Handler.ReadAt(fileBytes, int64(file.SentBytes))
if err != nil {
return err
return sentBytes, err
}
file.SentBytes += uint64(read)
sentBytes += uint64(canSendBytes)
packetBodyBuff.Write(fileBytes)
@ -194,15 +197,15 @@ func SendPiece(file *fsys.File, connection net.Conn, encrKey []byte) error {
if encrKey != nil {
err = fileBytesPacket.EncryptBody(encrKey)
if err != nil {
return err
return sentBytes, err
}
}
// send it to the other side
err = SendPacket(connection, fileBytesPacket)
if err != nil {
return err
return 0, err
}
return nil
return sentBytes, nil
}

Loading…
Cancel
Save