mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Drop 1 packet instead of a whole queue when overflowing
This commit is contained in:
		
							parent
							
								
									e6a47f705d
								
							
						
					
					
						commit
						ad5dc9ea87
					
				
					 1 changed files with 12 additions and 11 deletions
				
			
		| 
						 | 
					@ -605,21 +605,16 @@ type switch_buffers struct {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (b *switch_buffers) cleanup(t *switchTable) {
 | 
					func (b *switch_buffers) cleanup(t *switchTable) {
 | 
				
			||||||
	remove := func(streamID string) {
 | 
					 | 
				
			||||||
		// Helper function to drop a queue
 | 
					 | 
				
			||||||
		buf := b.bufs[streamID]
 | 
					 | 
				
			||||||
		for _, packet := range buf.packets {
 | 
					 | 
				
			||||||
			util_putBytes(packet.bytes)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		b.size -= buf.size
 | 
					 | 
				
			||||||
		delete(b.bufs, streamID)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for streamID, buf := range b.bufs {
 | 
						for streamID, buf := range b.bufs {
 | 
				
			||||||
		// Remove queues for which we have no next hop
 | 
							// Remove queues for which we have no next hop
 | 
				
			||||||
		packet := buf.packets[0]
 | 
							packet := buf.packets[0]
 | 
				
			||||||
		coords := switch_getPacketCoords(packet.bytes)
 | 
							coords := switch_getPacketCoords(packet.bytes)
 | 
				
			||||||
		if t.selfIsClosest(coords) {
 | 
							if t.selfIsClosest(coords) {
 | 
				
			||||||
			remove(streamID)
 | 
								for _, packet := range buf.packets {
 | 
				
			||||||
 | 
									util_putBytes(packet.bytes)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								b.size -= buf.size
 | 
				
			||||||
 | 
								delete(b.bufs, streamID)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	const maxSize = 4 * 1048576 // Maximum 4 MB
 | 
						const maxSize = 4 * 1048576 // Maximum 4 MB
 | 
				
			||||||
| 
						 | 
					@ -632,7 +627,13 @@ func (b *switch_buffers) cleanup(t *switchTable) {
 | 
				
			||||||
			if size < target {
 | 
								if size < target {
 | 
				
			||||||
				continue
 | 
									continue
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			remove(streamID)
 | 
								var packet switch_packetInfo
 | 
				
			||||||
 | 
								packet, buf.packets = buf.packets[0], buf.packets[1:]
 | 
				
			||||||
 | 
								buf.size -= uint64(len(packet.bytes))
 | 
				
			||||||
 | 
								b.size -= uint64(len(packet.bytes))
 | 
				
			||||||
 | 
								if len(buf.packets) == 0 {
 | 
				
			||||||
 | 
									delete(b.bufs, streamID)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue