From 43d8373a72860c2f8a7a59dc00118ad129399770 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Sun, 13 Jun 2021 16:12:14 +0300 Subject: [PATCH] Minor changes in constants and printing --- protocol/constants.go | 2 +- protocol/packet.go | 11 ++++++----- sender/sender.go | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/protocol/constants.go b/protocol/constants.go index 98f736d..e58f4b8 100644 --- a/protocol/constants.go +++ b/protocol/constants.go @@ -4,7 +4,7 @@ package protocol // MAXPACKETSIZE. // How many bytes can contain one packet (header + body) at maximum // (packets with size bigger than MAXPACKETSIZE are invalid and will not be sent) -const MAXPACKETSIZE uint = 10240 // 10 kilobytes +const MAXPACKETSIZE uint = 51200 // 50 kilobytes // PACKETSIZEDELIMETER. // Character that delimits one and the other sides of the next incoming packet. diff --git a/protocol/packet.go b/protocol/packet.go index a766ce2..d6a6b8d 100644 --- a/protocol/packet.go +++ b/protocol/packet.go @@ -118,8 +118,9 @@ func ReadFromConn(connection net.Conn) (Packet, error) { } // have a packetsize, now reading the whole packet - packetBytes := new(bytes.Buffer) + packetBuffer := new(bytes.Buffer) + // splitting big-sized packet into chunks and constructing it from pieces left := packetSize for { if left == 0 { @@ -130,13 +131,13 @@ func ReadFromConn(connection net.Conn) (Packet, error) { buff = make([]byte, left) } - r, _ := connection.Read(buff) - left -= r + read, _ := connection.Read(buff) + left -= read - packetBytes.Write(buff[:r]) + packetBuffer.Write(buff[:read]) } - packet := BytesToPacket(packetBytes.Bytes()) + packet := BytesToPacket(packetBuffer.Bytes()) return packet, nil } diff --git a/sender/sender.go b/sender/sender.go index 4da9c5d..bac4504 100644 --- a/sender/sender.go +++ b/sender/sender.go @@ -234,12 +234,14 @@ func (s *Sender) MainLoop() { case protocol.HeaderAccept: // allowed to send file packets + fmt.Println("The transfer has been accepted !") s.TransferAllowed = true case protocol.HeaderReady: s.ReceiverIsReady = true case protocol.HeaderReject: + fmt.Println("The transfer has been rejected") s.Stop() case protocol.HeaderDisconnecting: