edited chunk size

This commit is contained in:
0xdcarns 2022-01-29 09:01:33 -05:00
parent 7c29f2454e
commit c40c905b3b
3 changed files with 6 additions and 5 deletions

View file

@ -148,7 +148,6 @@ func Insert(key string, value string, tableName string) error {
if key != "" && value != "" && IsJSONString(value) {
return getCurrentDB()[INSERT].(func(string, string, string) error)(key, value, tableName)
} else {
logger.Log(0, "invalid json detected!!")
return errors.New("invalid insert " + key + " : " + value)
}
}

View file

@ -233,7 +233,7 @@ func CreateNode(node *models.Node) error {
if err != nil {
return err
}
logger.Log(0, "INSERTING: ", node.ID, fmt.Sprintf("pubkey? %v", node.TrafficKeys.Server))
logger.Log(0, "INSERTING: ", node.ID, fmt.Sprintf("pubkey? %v", node.TrafficKeys))
err = database.Insert(node.ID, string(nodebytes), database.NODES_TABLE_NAME)
if err != nil {
return err

View file

@ -552,7 +552,7 @@ func ServerAddrSliceContains(slice []models.ServerAddr, item models.ServerAddr)
// DestructMessage - reconstruct original message through chunks
func DestructMessage(builtMsg string, priv *rsa.PrivateKey) []byte {
var chunks = strings.Split(builtMsg, ",")
var chunks = strings.Split(builtMsg, splitKey)
var totalMessage = make([]byte, len(builtMsg))
for _, chunk := range chunks {
var bytes = decryptWithPrivateKey([]byte(chunk), priv)
@ -566,7 +566,7 @@ func DestructMessage(builtMsg string, priv *rsa.PrivateKey) []byte {
// BuildMessage Build a message for publishing
func BuildMessage(originalMessage []byte, pub *rsa.PublicKey) string {
chunks := getSliceChunks(originalMessage, 2048)
chunks := getSliceChunks(originalMessage, 1024)
var message = ""
for i := 0; i < len(chunks); i++ {
var encryptedText, encryptErr = encryptWithPublicKey(chunks[i], pub)
@ -577,12 +577,14 @@ func BuildMessage(originalMessage []byte, pub *rsa.PublicKey) string {
message += string(encryptedText)
if i < len(chunks)-1 {
message += ","
message += splitKey
}
}
return message
}
var splitKey = "|o|"
func getSliceChunks(slice []byte, chunkSize int) [][]byte {
var chunks [][]byte
for i := 0; i < len(slice); i += chunkSize {