Browse Source

addresses review comments

0xdcarns 3 years ago
parent
commit
ad79f2ea1f
5 changed files with 4 additions and 77 deletions
  1. 1 1
      database/database.go
  2. 1 1
      logic/nodes.go
  3. 1 0
      models/structs.go
  4. 0 74
      netclient/ncutils/netclientutils.go
  5. 1 1
      serverctl/iptables.go

+ 1 - 1
database/database.go

@@ -41,7 +41,7 @@ const PEERS_TABLE_NAME = "peers"
 // SERVERCONF_TABLE_NAME - stores server conf
 const SERVERCONF_TABLE_NAME = "serverconf"
 
-// SERVER_UUID_TABLE_NAME - stores
+// SERVER_UUID_TABLE_NAME - stores unique netmaker server data
 const SERVER_UUID_TABLE_NAME = "serveruuid"
 
 // SERVER_UUID_RECORD_KEY - telemetry thing

+ 1 - 1
logic/nodes.go

@@ -60,8 +60,8 @@ func GetSortedNetworkServerNodes(network string) ([]models.Node, error) {
 
 // GetServerNodes - gets the server nodes of a network
 func GetServerNodes(network string) []models.Node {
-	var nodes, err = GetNetworkNodes(network)
 	var serverNodes = make([]models.Node, 0)
+	var nodes, err = GetNetworkNodes(network)
 	if err != nil {
 		return serverNodes
 	}

+ 1 - 0
models/structs.go

@@ -167,6 +167,7 @@ type ServerUpdateData struct {
 }
 
 // Telemetry - contains UUID of the server and timestamp of last send to posthog
+// also contains assymetrical encryption pub/priv keys for any server traffic
 type Telemetry struct {
 	UUID           string `json:"uuid" bson:"uuid"`
 	LastSend       int64  `json:"lastsend" bson:"lastsend"`

+ 0 - 74
netclient/ncutils/netclientutils.go

@@ -594,77 +594,3 @@ func BoxDecrypt(encrypted []byte, senderPublicKey *[32]byte, recipientPrivateKey
 	}
 	return decrypted, nil
 }
-
-// DestructMessage - reconstruct original message through chunks
-// func DestructMessage(builtMsg string, priv *rsa.PrivateKey) []byte {
-// 	var chunks = strings.Split(builtMsg, splitKey)
-// 	var totalMessage = make([]byte, len(builtMsg))
-// 	for _, chunk := range chunks {
-// 		var bytes = decryptWithPrivateKey([]byte(chunk), priv)
-// 		if bytes == nil {
-// 			return nil
-// 		}
-// 		totalMessage = append(totalMessage, bytes...)
-// 	}
-// 	return totalMessage
-// }
-
-// // BuildMessage Build a message for publishing
-// func BuildMessage(originalMessage []byte, pub *rsa.PublicKey) string {
-// 	chunks := getSliceChunks(originalMessage, 228)
-// 	var message = ""
-// 	for i := 0; i < len(chunks); i++ {
-// 		var encryptedText, encryptErr = encryptWithPublicKey(chunks[i], pub)
-// 		if encryptErr != nil {
-// 			fmt.Printf("encrypt err: %v \n", encryptErr)
-// 			return ""
-// 		}
-
-// 		message += string(encryptedText)
-// 		if i < len(chunks)-1 {
-// 			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 {
-// 		lastByte := i + chunkSize
-
-// 		if lastByte > len(slice) {
-// 			lastByte = len(slice)
-// 		}
-
-// 		chunks = append(chunks, slice[i:lastByte])
-// 	}
-
-// 	return chunks
-// }
-
-// // encryptWithPublicKey encrypts data with public key
-// func encryptWithPublicKey(msg []byte, pub *rsa.PublicKey) ([]byte, error) {
-// 	if pub == nil {
-// 		return nil, errors.New("invalid public key when decrypting")
-// 	}
-// 	hash := sha512.New()
-// 	ciphertext, err := rsa.EncryptOAEP(hash, crand.Reader, pub, msg, []byte(""))
-// 	if err != nil {
-// 		return nil, err
-// 	}
-
-// 	return ciphertext, nil
-// }
-
-// // decryptWithPrivateKey decrypts data with private key
-// func decryptWithPrivateKey(ciphertext []byte, priv *rsa.PrivateKey) []byte {
-// 	hash := sha512.New()
-// 	plaintext, err := rsa.DecryptOAEP(hash, crand.Reader, priv, ciphertext, []byte(""))
-// 	if err != nil {
-// 		return nil
-// 	}
-// 	return plaintext
-// }

+ 1 - 1
serverctl/iptables.go

@@ -15,7 +15,7 @@ import (
 
 const netmakerProcessName = "netmaker"
 
-// InitServerNetclient - intializes the server netclient
+// InitIPTables - intializes the server iptables
 func InitIPTables() error {
 	_, err := exec.LookPath("iptables")
 	if err != nil {