Exemplo n.º 1
0
 def addEncapsulatedToQueue(self, packet, flags=priority["Normal"]):
     if Reliability.isReliable(packet.reliability):
         packet.messageIndex = self.messageIndex
         self.messageIndex += 1
         if packet.reliability == Reliability.reliableOrdered:
             packet.orderIndex = self.channelIndex[packet.orderChannel]
             self.channelIndex[packet.orderChannel] += 1
     if packet.getTotalLength() > self.mtuSize:
         buffers = {}
         i = 0
         splitIndex = 0
         while i < len(packet.buffer):
             buffers[splitIndex] = packet.buffer[i:i + self.mtuSize]
             splitIndex += 1
             i += self.mtuSize
         for index, buffer in buffers.items():
             pk = EncapsulatedPacket()
             pk.splitId = self.splitId
             pk.splitCount = len(buffers)
             pk.reliability = packet.reliability
             pk.splitIndex = index
             pk.buffer = buffer
             if index != 0:
                 pk.messageIndex = self.messageIndex
                 self.messageIndex += 1
             if pk.reliability == Reliability.reliableOrdered:
                 pk.orderChannel = packet.orderChannel
                 pk.orderIndex = packet.orderIndex
             self.addToQueue(pk, flags)
         self.splitId += 1
     else:
         self.addToQueue(packet, flags)
Exemplo n.º 2
0
 def addEncapsulatedToQueue(self, packet, flags = priority["Normal"]):
     packet.needAck = flags & 0b00001000
     if packet.needAck > 0:
         self.needAck[packet.identifierACK] = []
     if 2 <= packet.reliability <= 7:
         packet.messageIndex = self.messageIndex
         self.messageIndex += 1
         if packet.reliability == 3:
             packet.orderIndex = self.channelIndex[packet.orderChannel]
             self.channelIndex[packet.orderChannel] += 1
     if packet.getTotalLength() + 4 > self.mtuSize:
         buffers = []
         for i in range(0, len(packet.buffer), self.mtuSize - 34):
             buffers.append(packet.buffer[i:i - (self.mtuSize - 34)])
         self.splitId += 1
         splitId = self.splitId % 65536
         for count, buffer in enumerate(buffers):
             pk = EncapsulatedPacket()
             pk.splitId = splitId
             pk.split = True
             pk.splitCount = len(buffers)
             pk.reliability = packet.reliability
             pk.splitIndex = count
             pk.buffer = buffer
             if count > 0:
                 pk.messageIndex = self.messageIndex
                 self.messageIndex += 1
             else:
                 pk.messageIndex = packet.messageIndex
             if pk.reliability == 3:
                 pk.orderChannel = packet.orderChannel
                 pk.orderIndex = packet.orderIndex
             self.addToQueue(pk, flags | self.priority["Immediate"])
     else:
         self.addToQueue(packet, flags)