Browse Source

Minor changes in constants and printing

main
Unbewohnte 4 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.
// 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.

11
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
}

2
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:

Loading…
Cancel
Save