mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-10 07:20:39 +03:00
I'll try sorting, that's a good trick
This commit is contained in:
parent
cceecf4b1a
commit
2ae213c255
@ -19,6 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -249,6 +250,10 @@ func (iface *tcpInterface) handler(sock net.Conn, incoming bool) {
|
|||||||
var stack [][]byte
|
var stack [][]byte
|
||||||
put := func(msg []byte) {
|
put := func(msg []byte) {
|
||||||
stack = append(stack, msg)
|
stack = append(stack, msg)
|
||||||
|
sort.SliceStable(stack, func(i, j int) bool {
|
||||||
|
// Sort in reverse order, with smallest messages at the end
|
||||||
|
return len(stack[i]) >= len(stack[j])
|
||||||
|
})
|
||||||
for len(stack) > 32 {
|
for len(stack) > 32 {
|
||||||
util_putBytes(stack[0])
|
util_putBytes(stack[0])
|
||||||
stack = stack[1:]
|
stack = stack[1:]
|
||||||
|
Loading…
Reference in New Issue
Block a user