Browse Source

added struct to model

0xdcarns 3 years ago
parent
commit
3483e45beb
3 changed files with 7 additions and 10 deletions
  1. 1 3
      database/database.go
  2. 3 4
      logic/traffic.go
  3. 3 3
      models/structs.go

+ 1 - 3
database/database.go

@@ -211,9 +211,7 @@ func initializeUUID() error {
 		return keyErr
 	}
 
-	data, _ := json.Marshal(rsaPrivKey)
-
-	telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKey: string(data)}
+	telemetry := models.Telemetry{UUID: uuid.NewString(), TrafficKey: *rsaPrivKey}
 	telJSON, err := json.Marshal(&telemetry)
 	if err != nil {
 		return err

+ 3 - 4
logic/traffic.go

@@ -2,7 +2,7 @@ package logic
 
 import (
 	"crypto/rsa"
-	"encoding/json"
+	"fmt"
 )
 
 // RetrieveTrafficKey - retrieves public key based on node
@@ -11,8 +11,7 @@ func RetrieveTrafficKey() (rsa.PrivateKey, error) {
 	if err != nil {
 		return rsa.PrivateKey{}, err
 	}
-	var key rsa.PrivateKey
-	json.Unmarshal([]byte(telRecord.TrafficKey), &key)
+	fmt.Printf("fetched key %v \n", telRecord.TrafficKey)
 
-	return key, nil
+	return telRecord.TrafficKey, nil
 }

+ 3 - 3
models/structs.go

@@ -170,9 +170,9 @@ type ServerUpdateData struct {
 
 // Telemetry - contains UUID of the server and timestamp of last send to posthog
 type Telemetry struct {
-	UUID       string `json:"uuid" bson:"uuid"`
-	LastSend   int64  `json:"lastsend" bson:"lastsend"`
-	TrafficKey string `json:"traffickey" bson:"traffickey"`
+	UUID       string         `json:"uuid" bson:"uuid"`
+	LastSend   int64          `json:"lastsend" bson:"lastsend"`
+	TrafficKey rsa.PrivateKey `json:"traffickey" bson:"traffickey"`
 }
 
 // ServerAddr - to pass to clients to tell server addresses and if it's the leader or not