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) { if key != "" && value != "" && IsJSONString(value) {
return getCurrentDB()[INSERT].(func(string, string, string) error)(key, value, tableName) return getCurrentDB()[INSERT].(func(string, string, string) error)(key, value, tableName)
} else { } else {
logger.Log(0, "invalid json detected!!")
return errors.New("invalid insert " + key + " : " + value) return errors.New("invalid insert " + key + " : " + value)
} }
} }

View File

@@ -233,7 +233,7 @@ func CreateNode(node *models.Node) error {
if err != nil { if err != nil {
return err 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) err = database.Insert(node.ID, string(nodebytes), database.NODES_TABLE_NAME)
if err != nil { if err != nil {
return err return err

View File

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