Browse Source

Minor changes in constants and printing

main
Unbewohnte 3 years ago
parent
commit
43d8373a72
  1. 2
      protocol/constants.go
  2. 11
      protocol/packet.go
  3. 2
      sender/sender.go

2
protocol/constants.go

@ -4,7 +4,7 @@ package protocol
// MAXPACKETSIZE. // MAXPACKETSIZE.
// How many bytes can contain one packet (header + body) at maximum // How many bytes can contain one packet (header + body) at maximum
// (packets with size bigger than MAXPACKETSIZE are invalid and will not be sent) // (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. // PACKETSIZEDELIMETER.
// Character that delimits one and the other sides of the next incoming packet. // Character that delimits one and the other sides of the next incoming packet.

11
protocol/packet.go

@ -118,8 +118,9 @@ func ReadFromConn(connection net.Conn) (Packet, error) {
} }
// have a packetsize, now reading the whole packet // 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 left := packetSize
for { for {
if left == 0 { if left == 0 {
@ -130,13 +131,13 @@ func ReadFromConn(connection net.Conn) (Packet, error) {
buff = make([]byte, left) buff = make([]byte, left)
} }
r, _ := connection.Read(buff) read, _ := connection.Read(buff)
left -= r left -= read
packetBytes.Write(buff[:r]) packetBuffer.Write(buff[:read])
} }
packet := BytesToPacket(packetBytes.Bytes()) packet := BytesToPacket(packetBuffer.Bytes())
return packet, nil return packet, nil
} }

2
sender/sender.go

@ -234,12 +234,14 @@ func (s *Sender) MainLoop() {
case protocol.HeaderAccept: case protocol.HeaderAccept:
// allowed to send file packets // allowed to send file packets
fmt.Println("The transfer has been accepted !")
s.TransferAllowed = true s.TransferAllowed = true
case protocol.HeaderReady: case protocol.HeaderReady:
s.ReceiverIsReady = true s.ReceiverIsReady = true
case protocol.HeaderReject: case protocol.HeaderReject:
fmt.Println("The transfer has been rejected")
s.Stop() s.Stop()
case protocol.HeaderDisconnecting: case protocol.HeaderDisconnecting:

Loading…
Cancel
Save