Made Tree serialize the same always by sorting before serializing

gql_cataclysm
noah metz 2023-10-15 18:34:34 -06:00
parent b9bf61cf68
commit e299e77e78
4 changed files with 28 additions and 5 deletions

@ -2,6 +2,7 @@ package graphvent
import (
"crypto/ecdh"
"sort"
"time"
"encoding/binary"
"errors"
@ -975,6 +976,11 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
map_size := 0
map_iter := value.MapRange()
type TreeMapValue struct{
Key SerializedType
Data []byte
}
value_stacks := []TreeMapValue{}
for map_iter.Next() {
map_size += 1
key_reflect := map_iter.Key()
@ -989,8 +995,19 @@ func NewContext(db * badger.DB, log Logger) (*Context, error) {
return SerializedValue{}, err
}
data = append(data, key_value.Data...)
data = append(data, elem_value.Data...)
value_stacks = append(value_stacks, TreeMapValue{
SerializedType(key_reflect.Uint()),
append(key_value.Data, elem_value.Data...),
})
}
// Sort the value_stacks, then add them to `data`
sort.Slice(value_stacks, func(i, j int) bool {
return value_stacks[i].Key > value_stacks[j].Key
})
for _, stack := range(value_stacks) {
data = append(data, stack.Data...)
}
binary.BigEndian.PutUint64(data[0:8], uint64(map_size))

@ -242,7 +242,7 @@ func GraphiQLHandler() func(http.ResponseWriter, *http.Request) {
fetcher: GraphiQL.createFetcher({
url: '/gql',
headers: {
"Authorization": ` + "`Basic ${res}`" + `,
"Authorization": ` + "`${res}`" + `,
},
}),
defaultEditorToolsVisibility: true,

@ -294,7 +294,7 @@ func nodeLoop(ctx *Context, node *Node) error {
}
validated := ed25519.Verify(msg.Source, sig_data, msg.Signature)
if validated == false {
ctx.Log.Logf("signal", "SIGNAL_VERIFY_ERR: %s - %+v", node.ID, msg)
ctx.Log.Logf("signal", "SIGNAL_VERIFY_ERR: %s - %s", node.ID, reflect.TypeOf(msg.Signal))
continue
}
@ -426,7 +426,7 @@ func nodeLoop(ctx *Context, node *Node) error {
}
err = node.DequeueSignal(req_info.TimeoutID)
if err != nil {
panic("dequeued a passed signal")
ctx.Log.Logf("node", "ACL_DEQUEUE_ERROR: timeout signal not in queue when trying to clear after counter hit 0 %s, %s - %s", err, signal.ID(), req_info.TimeoutID)
}
delete(node.PendingACLs, info.ID)
} else {

@ -66,6 +66,12 @@ func TestSerializeBasic(t *testing.T) {
"test_string",
})
testSerialize(t, ctx, Tree{
ErrorType: nil,
MapType: nil,
StringType: nil,
})
testSerialize(t, ctx, Tree{
TreeType: nil,
})