From 387cc83b0cfe1f3a17a4aa77ff7f5698bfcce9f7 Mon Sep 17 00:00:00 2001
From: josh <josh@elixxir.io>
Date: Wed, 23 Sep 2020 14:30:26 -0700
Subject: [PATCH] Merge branch roy/noContext into branch
 XX-2645/KeyExchangeTest

---
 Makefile                              |   8 +-
 context/utility/trackResults.go       |   2 +
 globals/log.go                        |  54 +++++++
 globals/statusEvents.go               |  18 +++
 globals/storage.go                    | 202 ++++++++++++++++++++++++++
 globals/storage_test.go               | 144 ++++++++++++++++++
 globals/terminator.go                 |  47 ++++++
 globals/terminator_test.go            |  69 +++++++++
 globals/version_vars.go               |  37 +++++
 go.mod                                |   4 +-
 go.sum                                |  10 +-
 network/health/healthTracker.go       |   2 +-
 network/manager.go                    |   4 +-
 network/message/reception.go          |   4 +-
 network/message/sendCmix.go           |   1 -
 network/rounds/historical.go          |   4 +-
 network/rounds/manager.go             |   4 +-
 network/track.go                      |   1 -
 storage/cmix/roundKeys_test.go        |   1 -
 storage/conversation/store.go         |   2 +-
 storage/e2e/key.go                    |   2 +-
 storage/e2e/manager.go                |   4 +-
 storage/e2e/session.go                |   2 +-
 storage/e2e/sessionBuff.go            |   9 +-
 storage/e2e/sessionID.go              |   6 +-
 storage/e2e/stateVector.go            |   3 +-
 storage/e2e/store.go                  |   2 -
 storage/partition/multiPartMessage.go |   2 +-
 storage/session.go                    |  19 ++-
 storage/versioned/kv.go               |   2 +-
 30 files changed, 623 insertions(+), 46 deletions(-)
 create mode 100644 globals/log.go
 create mode 100644 globals/statusEvents.go
 create mode 100644 globals/storage.go
 create mode 100644 globals/storage_test.go
 create mode 100644 globals/terminator.go
 create mode 100644 globals/terminator_test.go
 create mode 100644 globals/version_vars.go

diff --git a/Makefile b/Makefile
index d5550fc19..2facd84d8 100644
--- a/Makefile
+++ b/Makefile
@@ -20,11 +20,11 @@ build:
 	go mod tidy
 
 update_release:
-	GOFLAGS="" go get -u gitlab.com/elixxir/primitives@peppa/newClient
-	GOFLAGS="" go get -u gitlab.com/elixxir/crypto@peppa/newClient
+	GOFLAGS="" go get -u gitlab.com/elixxir/primitives@16ed0124890becb3c12182681ec3169319de2dc6
+	GOFLAGS="" go get -u gitlab.com/elixxir/crypto@bb2ad1c493cec8d2ccf6ae273430411f9997bb21
 	GOFLAGS="" go get -u gitlab.com/xx_network/crypto@release
-	GOFLAGS="" go get -u gitlab.com/elixxir/comms@release
-	GOFLAGS="" go get -u gitlab.com/xx_network/comms@release
+	GOFLAGS="" go get -u gitlab.com/elixxir/comms@peppa/newClient
+	GOFLAGS="" go get -u gitlab.com/xx_network/comms@peppa/newClient
 	GOFLAGS="" go get -u gitlab.com/xx_network/primitives@release
 
 update_master:
diff --git a/context/utility/trackResults.go b/context/utility/trackResults.go
index 200615a6e..12de24d77 100644
--- a/context/utility/trackResults.go
+++ b/context/utility/trackResults.go
@@ -1,6 +1,7 @@
 package utility
 
 import (
+	"fmt"
 	ds "gitlab.com/elixxir/comms/network/dataStructures"
 	"gitlab.com/elixxir/primitives/states"
 )
@@ -11,6 +12,7 @@ import (
 func TrackResults(resultsCh chan ds.EventReturn, numResults int) (bool, int, int) {
 	numTimeOut, numRoundFail := 0, 0
 	for numResponses := 0; numResponses < numResults; numResponses++ {
+		fmt.Printf("iterated: %v\n", numResponses)
 		er := <-resultsCh
 		if er.TimedOut {
 			numTimeOut++
diff --git a/globals/log.go b/globals/log.go
new file mode 100644
index 000000000..e9bfc4a45
--- /dev/null
+++ b/globals/log.go
@@ -0,0 +1,54 @@
+////////////////////////////////////////////////////////////////////////////////
+// Copyright © 2019 Privategrity Corporation                                   /
+//                                                                             /
+// All rights reserved.                                                        /
+////////////////////////////////////////////////////////////////////////////////
+
+package globals
+
+import (
+	jww "github.com/spf13/jwalterweatherman"
+	"io"
+	"io/ioutil"
+	"log"
+	"os"
+)
+
+// Log is logging everything to this notepad so that the CUI can replace it
+// with its own notepad and get logging statements from the client
+var Log = jww.NewNotepad(jww.LevelInfo, jww.LevelInfo, os.Stdout,
+	ioutil.Discard, "CLIENT", log.Ldate|log.Ltime)
+
+// InitLog initializes logging thresholds and the log path.
+// verbose turns on debug logging, setting the log path to nil
+// uses std out.
+func InitLog(verbose bool, logPath string) *jww.Notepad {
+	logLevel := jww.LevelInfo
+	logFlags := (log.Ldate | log.Ltime)
+	stdOut := io.Writer(os.Stdout)
+	logFile := ioutil.Discard
+
+	// If the verbose flag is set, print all logs and
+	// print microseconds as well
+	if verbose {
+		logLevel = jww.LevelDebug
+		logFlags = (log.Ldate | log.Ltime | log.Lmicroseconds)
+	}
+	// If the logpath is empty or not set to - (stdout),
+	// set up the log file and do not log to stdout
+	if logPath != "" && logPath != "-" {
+		// Create log file, overwrites if existing
+		lF, err := os.OpenFile(logPath,
+			os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+		if err != nil {
+			Log.WARN.Println("Invalid or missing log path," +
+				" stdout used.")
+		} else {
+			logFile = io.Writer(lF)
+			stdOut = ioutil.Discard
+		}
+	}
+
+	return jww.NewNotepad(logLevel, logLevel, stdOut, logFile,
+		"CLIENT", logFlags)
+}
diff --git a/globals/statusEvents.go b/globals/statusEvents.go
new file mode 100644
index 000000000..834db9f61
--- /dev/null
+++ b/globals/statusEvents.go
@@ -0,0 +1,18 @@
+package globals
+
+//Registration
+const REG_KEYGEN = 1       //Generating Cryptographic Keys
+const REG_PRECAN = 2       //Doing a Precanned Registration (Not Secure)
+const REG_UID_GEN = 3      //Generating User ID
+const REG_PERM = 4         //Validating User Identity With Permissioning Server
+const REG_NODE = 5         //Registering with Nodes
+const REG_FAIL = 6         //Failed to Register with Nodes
+const REG_SECURE_STORE = 7 //Creating Local Secure Session
+const REG_SAVE = 8         //Storing Session
+//UDB registration
+const UDB_REG_PUSHKEY = 9   //Pushing Cryptographic Material to the User Discovery Bot
+const UDB_REG_PUSHUSER = 10 //Registering User with the User Discovery Bot
+//UDB Search
+const UDB_SEARCH_LOOK = 11        //Searching for User in User Discovery
+const UDB_SEARCH_GETKEY = 12      //Getting Keying Material From User Discovery
+const UDB_SEARCH_BUILD_CREDS = 13 //Building secure end to end relationship
diff --git a/globals/storage.go b/globals/storage.go
new file mode 100644
index 000000000..aecd54789
--- /dev/null
+++ b/globals/storage.go
@@ -0,0 +1,202 @@
+////////////////////////////////////////////////////////////////////////////////
+// Copyright © 2019 Privategrity Corporation                                   /
+//                                                                             /
+// All rights reserved.                                                        /
+////////////////////////////////////////////////////////////////////////////////
+
+package globals
+
+import (
+	"os"
+	"sync"
+)
+
+const (
+	NoSave uint8 = iota
+	LocationA
+	LocationB
+)
+
+type Storage interface {
+	SetLocation(string, string) error
+	GetLocation() (string, string)
+	SaveA([]byte) error
+	SaveB([]byte) error
+	LoadA() []byte
+	LoadB() []byte
+	IsEmpty() bool
+}
+
+type DefaultStorage struct {
+	locationA string
+	locationB string
+	sync.Mutex
+}
+
+func (ds *DefaultStorage) SetLocation(locationA, locationB string) error {
+	ds.Lock()
+	ds.locationA = locationA
+	ds.locationB = locationB
+	ds.Unlock()
+	return nil
+}
+
+func (ds *DefaultStorage) GetLocation() (string, string) {
+	ds.Lock()
+	defer ds.Unlock()
+	return ds.locationA, ds.locationB
+}
+
+func (ds *DefaultStorage) IsEmpty() bool {
+	_, err := os.Stat(ds.locationA)
+	firstEmpty := err != nil && os.IsNotExist(err)
+	_, err = os.Stat(ds.locationB)
+	secondEmpty := err != nil && os.IsNotExist(err)
+	return firstEmpty && secondEmpty
+}
+
+func (ds *DefaultStorage) SaveA(data []byte) error {
+	return dsSaveHelper(ds.locationA, data)
+}
+
+func (ds *DefaultStorage) LoadA() []byte {
+	return dsLoadHelper(ds.locationA)
+}
+
+func (ds *DefaultStorage) SaveB(data []byte) error {
+	return dsSaveHelper(ds.locationB, data)
+}
+
+func (ds *DefaultStorage) LoadB() []byte {
+	return dsLoadHelper(ds.locationB)
+}
+
+type RamStorage struct {
+	DataA []byte
+	DataB []byte
+}
+
+func (rs *RamStorage) SetLocation(string, string) error {
+	return nil
+}
+
+func (rs *RamStorage) GetLocation() (string, string) {
+	return "", ""
+}
+
+func (rs *RamStorage) SaveA(data []byte) error {
+	rs.DataA = make([]byte, len(data))
+	copy(rs.DataA, data)
+	return nil
+}
+
+func (rs *RamStorage) SaveB(data []byte) error {
+	rs.DataB = make([]byte, len(data))
+	copy(rs.DataB, data)
+	return nil
+}
+
+func (rs *RamStorage) LoadA() []byte {
+	b := make([]byte, len(rs.DataA))
+	copy(b, rs.DataA)
+
+	return b
+}
+
+func (rs *RamStorage) LoadB() []byte {
+	b := make([]byte, len(rs.DataB))
+	copy(b, rs.DataB)
+
+	return b
+}
+
+func (rs *RamStorage) IsEmpty() bool {
+	return (rs.DataA == nil || len(rs.DataA) == 0) && (rs.DataB == nil || len(rs.DataB) == 0)
+}
+
+func dsLoadHelper(loc string) []byte {
+	// Check if the file exists, return nil if it does not
+	finfo, err1 := os.Stat(loc)
+
+	if err1 != nil {
+		Log.ERROR.Printf("Default Storage Load: Unknown Error Occurred on"+
+			" file check: \n  %v", err1.Error())
+		return nil
+	}
+
+	b := make([]byte, finfo.Size())
+
+	// Open the file, return nil if it cannot be opened
+	f, err2 := os.Open(loc)
+
+	defer func() {
+		if f != nil {
+			f.Close()
+		} else {
+			Log.WARN.Println("Could not close file, file is nil")
+		}
+	}()
+
+	if err2 != nil {
+		Log.ERROR.Printf("Default Storage Load: Unknown Error Occurred on"+
+			" file open: \n  %v", err2.Error())
+		return nil
+	}
+
+	// Read the data from the file, return nil if read fails
+	_, err3 := f.Read(b)
+
+	if err3 != nil {
+		Log.ERROR.Printf("Default Storage Load: Unknown Error Occurred on"+
+			" file read: \n  %v", err3.Error())
+		return nil
+	}
+
+	return b
+
+}
+
+func dsSaveHelper(loc string, data []byte) error {
+	//check if the file exists, delete if it does
+	_, err1 := os.Stat(loc)
+
+	if err1 == nil {
+		errRmv := os.Remove(loc)
+		if errRmv != nil {
+			Log.WARN.Printf("Could not remove Storage File B: %s", errRmv)
+		}
+	} else if !os.IsNotExist(err1) {
+		Log.ERROR.Printf("Default Storage Save: Unknown Error Occurred on"+
+			" file check: \n  %v",
+			err1.Error())
+		return err1
+	}
+
+	//create new file
+	f, err2 := os.Create(loc)
+
+	defer func() {
+		if f != nil {
+			f.Close()
+		} else {
+			Log.WARN.Println("Could not close file, file is nil")
+		}
+	}()
+
+	if err2 != nil {
+		Log.ERROR.Printf("Default Storage Save: Unknown Error Occurred on"+
+			" file creation: \n %v", err2.Error())
+		return err2
+	}
+
+	//Save to file
+	_, err3 := f.Write(data)
+
+	if err3 != nil {
+		Log.ERROR.Printf("Default Storage Save: Unknown Error Occurred on"+
+			" file write: \n %v", err3.Error())
+		return err3
+	}
+
+	return nil
+}
diff --git a/globals/storage_test.go b/globals/storage_test.go
new file mode 100644
index 000000000..96abc9532
--- /dev/null
+++ b/globals/storage_test.go
@@ -0,0 +1,144 @@
+////////////////////////////////////////////////////////////////////////////////
+// Copyright © 2019 Privategrity Corporation                                   /
+//                                                                             /
+// All rights reserved.                                                        /
+////////////////////////////////////////////////////////////////////////////////
+
+package globals
+
+import (
+	"os"
+	"reflect"
+	"testing"
+)
+
+func TestInitStorage(t *testing.T) {
+	TestDataA := []byte{12, 14, 54}
+	TestDataB := []byte{69, 42, 32}
+	TestSaveLocA := "testStorageA.data"
+	TestSaveLocB := "testStorageB.data"
+
+	// Test DefaultStorage initialization without existing storage
+	storage := &DefaultStorage{}
+	//Check that storage is empty prior to any Save calls
+	if !storage.IsEmpty() {
+		t.Errorf("ds.IsEmpty failed to detect an empty storage")
+	}
+
+	storage.SetLocation(TestSaveLocA, TestSaveLocB)
+
+	// Test DS saveA
+	err := storage.SaveA(TestDataA)
+	if err != nil {
+		t.Errorf("ds.Save failed to create a save file A at: %v",
+			TestSaveLocA)
+	}
+	// Check that save file was made
+	if !exists(TestSaveLocA) {
+		t.Errorf("ds.Save failed to create a save file A at: %v",
+			TestSaveLocA)
+	}
+	//Check that the storage is not empty after a saveA call
+	if storage.IsEmpty() {
+		t.Errorf("ds.IsEmpty failed to detect a non-empty storage")
+	}
+
+	// Test DS loadA
+	actualData := storage.LoadA()
+	if reflect.DeepEqual(actualData, TestDataA) != true {
+		t.Errorf("ds.Load failed to load expected data on A. Expected:%v Actual:%v",
+			TestDataA, actualData)
+	}
+
+	// Test DS saveB
+	err = storage.SaveB(TestDataB)
+	if err != nil {
+		t.Errorf("ds.Save failed to create a save file B at: %v",
+			TestSaveLocB)
+	}
+	// Check that save file was made
+	if !exists(TestSaveLocB) {
+		t.Errorf("ds.Save failed to create a save file B at: %v",
+			TestSaveLocB)
+	}
+
+	// Test DS loadA
+	actualData = storage.LoadB()
+	if reflect.DeepEqual(actualData, TestDataB) != true {
+		t.Errorf("ds.Load failed to load expected data on B. Expected:%v Actual:%v",
+			TestDataB, actualData)
+	}
+
+	// Test RamStorage
+	store := RamStorage{}
+	actualData = nil
+	// Test A
+	store.SaveA(TestDataA)
+	actualData = store.LoadA()
+	if reflect.DeepEqual(actualData, TestDataA) != true {
+		t.Errorf("rs.Load failed to load expected data A. Expected:%v Actual:%v",
+			TestDataA, actualData)
+	}
+	//Test B
+	store.SaveB(TestDataB)
+	actualData = store.LoadB()
+	if reflect.DeepEqual(actualData, TestDataB) != true {
+		t.Errorf("rs.Load failed to load expected data B. Expected:%v Actual:%v",
+			TestDataB, actualData)
+	}
+	os.Remove(TestSaveLocA)
+	os.Remove(TestSaveLocB)
+}
+
+// exists returns whether the given file or directory exists or not
+func exists(path string) bool {
+	_, err := os.Stat(path)
+	if err == nil {
+		return true
+	}
+	if os.IsNotExist(err) {
+		return false
+	}
+	return true
+}
+
+func TestDefaultStorage_GetLocation(t *testing.T) {
+	locationA := "hi"
+	locationB := "hi2"
+
+	ds := DefaultStorage{locationA: locationA, locationB: locationB}
+
+	recievedLocA, recievedLocB := ds.GetLocation()
+
+	if recievedLocA != locationA {
+		t.Errorf("defaultStorage.GetLocation returned incorrect location A. Expected:%v Actual:%v",
+			locationA, recievedLocA)
+	}
+
+	if recievedLocB != locationB {
+		t.Errorf("defaultStorage.GetLocation returned incorrect location B. Expected:%v Actual:%v",
+			locationB, recievedLocB)
+	}
+}
+
+func TestRamStorage_GetLocation(t *testing.T) {
+
+	ds := RamStorage{}
+
+	a, b := ds.GetLocation()
+
+	if a != "" && b != "" {
+		t.Errorf("RamStorage.GetLocation returned incorrect location. Actual: '', ''; Expected:'%v','%v'",
+			a, b)
+	}
+}
+
+func Test_dsLoadHelper_LocError(t *testing.T) {
+	testLoc := "~a/test"
+
+	result := dsLoadHelper(testLoc)
+
+	if result != nil {
+		t.Errorf("dsLoadHelper() did not error on invalid path.")
+	}
+}
diff --git a/globals/terminator.go b/globals/terminator.go
new file mode 100644
index 000000000..5b17199f2
--- /dev/null
+++ b/globals/terminator.go
@@ -0,0 +1,47 @@
+////////////////////////////////////////////////////////////////////////////////
+// Copyright © 2019 Privategrity Corporation                                   /
+//                                                                             /
+// All rights reserved.                                                        /
+////////////////////////////////////////////////////////////////////////////////
+
+package globals
+
+import (
+	"time"
+)
+
+type ThreadTerminator chan chan bool
+
+func NewThreadTerminator() ThreadTerminator {
+	t := make(chan chan bool, 1)
+	return t
+}
+
+func (t ThreadTerminator) Terminate() {
+	t <- nil
+}
+
+// Try's to kill a thread controlled by a termination channel for the length of
+// the timeout, returns its success. pass 0 for no timeout
+func (t ThreadTerminator) BlockingTerminate(timeout uint64) bool {
+
+	killNotify := make(chan bool)
+	defer close(killNotify)
+
+	if timeout != 0 {
+		timer := time.NewTimer(time.Duration(timeout) * time.Millisecond)
+		defer timer.Stop()
+
+		t <- killNotify
+
+		select {
+		case _ = <-killNotify:
+			return true
+		case <-timer.C:
+			return false
+		}
+	} else {
+		_ = <-killNotify
+		return true
+	}
+}
diff --git a/globals/terminator_test.go b/globals/terminator_test.go
new file mode 100644
index 000000000..b43c8cc03
--- /dev/null
+++ b/globals/terminator_test.go
@@ -0,0 +1,69 @@
+////////////////////////////////////////////////////////////////////////////////
+// Copyright © 2019 Privategrity Corporation                                   /
+//                                                                             /
+// All rights reserved.                                                        /
+////////////////////////////////////////////////////////////////////////////////
+
+package globals
+
+import (
+	"testing"
+	"time"
+)
+
+func TestNewThreadTerminator(t *testing.T) {
+
+	term := NewThreadTerminator()
+
+	var success bool
+
+	go func(term ThreadTerminator) {
+		term <- nil
+	}(term)
+
+	timer := time.NewTimer(time.Duration(1000) * time.Millisecond)
+	defer timer.Stop()
+
+	select {
+	case _ = <-term:
+		success = true
+	case <-timer.C:
+		success = false
+	}
+
+	if !success {
+		t.Errorf("NewThreadTerminator: Could not use the ThreadTerminator to" +
+			" stop a thread")
+	}
+
+}
+
+func TestBlockingTerminate(t *testing.T) {
+
+	term := NewThreadTerminator()
+
+	go func(term ThreadTerminator) {
+		var killNotify chan<- bool
+
+		q := false
+
+		for !q {
+			select {
+			case killNotify = <-term:
+				q = true
+			}
+
+			close(term)
+
+			killNotify <- true
+
+		}
+	}(term)
+
+	success := term.BlockingTerminate(1000)
+
+	if !success {
+		t.Errorf("BlockingTerminate: Thread did not terminate in time")
+	}
+
+}
diff --git a/globals/version_vars.go b/globals/version_vars.go
new file mode 100644
index 000000000..4f7517bec
--- /dev/null
+++ b/globals/version_vars.go
@@ -0,0 +1,37 @@
+// Code generated by go generate; DO NOT EDIT.
+// This file was generated by robots at
+// 2020-08-10 10:05:18.2662998 -0700 PDT m=+0.116012701
+package globals
+
+const GITVERSION = `127a946 Merge branch 'XX-2415/NodeKeys' into 'Optimus/ClientStorage'`
+const SEMVER = "1.4.0"
+const DEPENDENCIES = `module gitlab.com/elixxir/client
+
+go 1.13
+
+require (
+	github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
+	github.com/golang/protobuf v1.4.2
+	github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 // indirect
+	github.com/pelletier/go-toml v1.6.0 // indirect
+	github.com/pkg/errors v0.9.1
+	github.com/smartystreets/assertions v1.0.1 // indirect
+	github.com/spf13/afero v1.2.2 // indirect
+	github.com/spf13/cast v1.3.1 // indirect
+	github.com/spf13/cobra v1.0.0
+	github.com/spf13/jwalterweatherman v1.1.0
+	github.com/spf13/pflag v1.0.5 // indirect
+	github.com/spf13/viper v1.6.2
+	gitlab.com/elixxir/comms v0.0.0-20200805174832-240bba97beaa
+	gitlab.com/elixxir/crypto v0.0.0-20200805174804-bdf909f2a16d
+	gitlab.com/elixxir/ekv v0.1.1
+	gitlab.com/elixxir/primitives v0.0.0-20200805174810-86b366d1dd2d
+	gitlab.com/xx_network/comms v0.0.0-20200805174823-841427dd5023
+	gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da
+	golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de
+	golang.org/x/sys v0.0.0-20200806125547-5acd03effb82 // indirect
+	gopkg.in/ini.v1 v1.52.0 // indirect
+)
+
+replace google.golang.org/grpc => github.com/grpc/grpc-go v1.27.1
+`
diff --git a/go.mod b/go.mod
index 1ae4b813b..8899a0423 100644
--- a/go.mod
+++ b/go.mod
@@ -15,11 +15,11 @@ require (
 	github.com/spf13/jwalterweatherman v1.1.0
 	github.com/spf13/pflag v1.0.5 // indirect
 	github.com/spf13/viper v1.6.2
-	gitlab.com/elixxir/comms v0.0.0-20200921200427-5955a0a798b9
+	gitlab.com/elixxir/comms v0.0.0-20200922182918-25d056c28b3a
 	gitlab.com/elixxir/crypto v0.0.0-20200921195205-bca0178268ec
 	gitlab.com/elixxir/ekv v0.1.1
 	gitlab.com/elixxir/primitives v0.0.0-20200915190719-f4586ec93f50
-	gitlab.com/xx_network/comms v0.0.0-20200915154643-d533291041b7
+	gitlab.com/xx_network/comms v0.0.0-20200922173551-45ad1fa27175
 	gitlab.com/xx_network/crypto v0.0.0-20200812183430-c77a5281c686
 	gitlab.com/xx_network/primitives v0.0.0-20200915204206-eb0287ed0031
 	golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
diff --git a/go.sum b/go.sum
index 608d540ab..0a16b4d95 100644
--- a/go.sum
+++ b/go.sum
@@ -188,8 +188,8 @@ gitlab.com/elixxir/comms v0.0.0-20200916212207-60e7bd5b0913 h1:p4TLPPaMysV//lOJU
 gitlab.com/elixxir/comms v0.0.0-20200916212207-60e7bd5b0913/go.mod h1:yBEsOZSPyJQJvDbtlQ5L8ydy1JRgVlRoNgMDy9koQcE=
 gitlab.com/elixxir/comms v0.0.0-20200917172539-929fc227eb0c h1:go7/RknV7646Ie+nmQXZAa/aJ5wZBn5bpAYRB+tPens=
 gitlab.com/elixxir/comms v0.0.0-20200917172539-929fc227eb0c/go.mod h1:yBEsOZSPyJQJvDbtlQ5L8ydy1JRgVlRoNgMDy9koQcE=
-gitlab.com/elixxir/comms v0.0.0-20200921200427-5955a0a798b9 h1:skzHNWCMh+T7Cn58/88Mikg2R8KnSWfzLV0w7SnerOs=
-gitlab.com/elixxir/comms v0.0.0-20200921200427-5955a0a798b9/go.mod h1:uRr8j6yTjCslxZxbRe6k4ixACu9gAeF61JZH36OFFa0=
+gitlab.com/elixxir/comms v0.0.0-20200922182918-25d056c28b3a h1:aBBz0LOfUulcQojWFg2sawdI0EkdRNTKU5qlPsmn+Ow=
+gitlab.com/elixxir/comms v0.0.0-20200922182918-25d056c28b3a/go.mod h1:uRr8j6yTjCslxZxbRe6k4ixACu9gAeF61JZH36OFFa0=
 gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4 h1:28ftZDeYEko7xptCZzeFWS1Iam95dj46TWFVVlKmw6A=
 gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
 gitlab.com/elixxir/crypto v0.0.0-20200805174804-bdf909f2a16d/go.mod h1:cu6uNoANVLV0J6HyTL6KqVtVyh9SHU1RjJhytYlsbVQ=
@@ -221,8 +221,6 @@ gitlab.com/elixxir/crypto v0.0.0-20200915211245-8a519dfcc38d h1:6D2r42dFuUm96Kje
 gitlab.com/elixxir/crypto v0.0.0-20200915211245-8a519dfcc38d/go.mod h1:zUczcFuZGqLchDX1sjgBo189soeDK2p5Mx+GNNrkTLI=
 gitlab.com/elixxir/crypto v0.0.0-20200917184612-bb2ad1c493ce h1:g8/MABMbpVUJOn2BMhZJo8Pkee4YVSriFoV5po0TDkY=
 gitlab.com/elixxir/crypto v0.0.0-20200917184612-bb2ad1c493ce/go.mod h1:zUczcFuZGqLchDX1sjgBo189soeDK2p5Mx+GNNrkTLI=
-gitlab.com/elixxir/crypto v0.0.0-20200921191117-583f263ab715 h1:1eMAfJ1uyOVU8O3JXQSBrVYt1CLMRUBSjYYzVPI+uO0=
-gitlab.com/elixxir/crypto v0.0.0-20200921191117-583f263ab715/go.mod h1:1P3IMJ6i3L+5si0PiMvoo/qQXMsEhNVjn0yMUrm3eiA=
 gitlab.com/elixxir/crypto v0.0.0-20200921195205-bca0178268ec h1:8dnRUCSNz7knf+K5OvmEwY181aPp5ErseJogEwgS6dY=
 gitlab.com/elixxir/crypto v0.0.0-20200921195205-bca0178268ec/go.mod h1:1P3IMJ6i3L+5si0PiMvoo/qQXMsEhNVjn0yMUrm3eiA=
 gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842 h1:m1zDQ6UadpuMnV7nvnyR+DUXE3AisRnVjajTb1xZE4c=
@@ -235,6 +233,7 @@ gitlab.com/elixxir/primitives v0.0.0-20200804182913-788f47bded40/go.mod h1:tzdFF
 gitlab.com/elixxir/primitives v0.0.0-20200804231232-ad79a9e8f113/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc=
 gitlab.com/elixxir/primitives v0.0.0-20200805174810-86b366d1dd2d/go.mod h1:tzdFFvb1ESmuTCOl1z6+yf6oAICDxH2NPUemVgoNLxc=
 gitlab.com/elixxir/primitives v0.0.0-20200812191102-31c01f08b4dc/go.mod h1:pJx2DZk9s8vVMnLN7x0hIPngDjbNSdOP6kk3RLlRxHg=
+gitlab.com/elixxir/primitives v0.0.0-20200907165319-16ed0124890b h1:d1ttSIOWxWytnTpjO9hyr4KFtv/dmDBYuK59EP0sjAQ=
 gitlab.com/elixxir/primitives v0.0.0-20200907165319-16ed0124890b/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE=
 gitlab.com/elixxir/primitives v0.0.0-20200915190719-f4586ec93f50 h1:J0A2JsYlb0He1lTGDy+6KX3s/87uklk/pLv9FKv9yp8=
 gitlab.com/elixxir/primitives v0.0.0-20200915190719-f4586ec93f50/go.mod h1:kNp47yPqja2lHSiS4DddTvFpB/4D9dB2YKnw5c+LJCE=
@@ -254,7 +253,8 @@ gitlab.com/xx_network/comms v0.0.0-20200910173932-bd179f5fee4f h1:ExTCqEoro7VuS1
 gitlab.com/xx_network/comms v0.0.0-20200910173932-bd179f5fee4f/go.mod h1:+jEkDQKoK51WLl2ZZuxfAZkz6YFbUQ+oZfH0dt2wIF0=
 gitlab.com/xx_network/comms v0.0.0-20200915154643-d533291041b7 h1:lPx1wpkjNpwLaZ0pyd7/iCcdITjT+eCMmb0HXCVoIkk=
 gitlab.com/xx_network/comms v0.0.0-20200915154643-d533291041b7/go.mod h1:+jEkDQKoK51WLl2ZZuxfAZkz6YFbUQ+oZfH0dt2wIF0=
-gitlab.com/xx_network/crypto v0.0.0-20200805231039-4aa0e350ed0a h1:BlfWGPokU6yU69O+PGGsgc5iA/P9gERbHzYUvjoYbgM=
+gitlab.com/xx_network/comms v0.0.0-20200922173551-45ad1fa27175 h1:HDmgh2Skbgv/fW1selsLDRr+hvQaK24nsthxv9nAHRM=
+gitlab.com/xx_network/comms v0.0.0-20200922173551-45ad1fa27175/go.mod h1:wDPZABTOhqz+uFM75CzpGplQBRIsCQcS1EYXwker6nw=
 gitlab.com/xx_network/crypto v0.0.0-20200806202113-978fa1984bbf/go.mod h1:i0df/q6dDCBiscgD51fMoS2U2TBrm6LcyN822JmB5Tw=
 gitlab.com/xx_network/crypto v0.0.0-20200806235322-ede3c15881ce h1:gypNBUl2guESEv4MDgH+miwYqR4jPoWM8dLt2Zs5gIs=
 gitlab.com/xx_network/crypto v0.0.0-20200806235322-ede3c15881ce/go.mod h1:i0df/q6dDCBiscgD51fMoS2U2TBrm6LcyN822JmB5Tw=
diff --git a/network/health/healthTracker.go b/network/health/healthTracker.go
index 81008b098..5addcd387 100644
--- a/network/health/healthTracker.go
+++ b/network/health/healthTracker.go
@@ -81,7 +81,7 @@ func (t *Tracker) Start() {
 			"is already running")
 	}
 
-	go t.start(t.Quit())
+	//go t.start(t.Quit())
 }
 
 // Long-running thread used to monitor and report on network health
diff --git a/network/manager.go b/network/manager.go
index 7013d7f6f..efb5b9295 100644
--- a/network/manager.go
+++ b/network/manager.go
@@ -65,8 +65,8 @@ func NewManager(session *storage.Session, switchboard *switchboard.Switchboard,
 
 	//create manager object
 	m := manager{
-		param:    params,
-		runners:  stoppable.NewMulti("network.Manager"),
+		param:   params,
+		runners: stoppable.NewMulti("network.Manager"),
 	}
 
 	m.Internal = internal.Internal{
diff --git a/network/message/reception.go b/network/message/reception.go
index 656a893ea..2c1501185 100644
--- a/network/message/reception.go
+++ b/network/message/reception.go
@@ -1,11 +1,11 @@
 package message
 
 import (
+	jww "github.com/spf13/jwalterweatherman"
 	"gitlab.com/elixxir/client/context/message"
 	"gitlab.com/elixxir/crypto/e2e"
 	"gitlab.com/elixxir/primitives/format"
 	"gitlab.com/xx_network/primitives/id"
-	jww "github.com/spf13/jwalterweatherman"
 	"time"
 )
 
@@ -81,4 +81,4 @@ func (m *Manager) receiveMessage(ecrMsg format.Message) {
 	if ok {
 		m.Switchboard.Speak(xxMsg)
 	}
-}
\ No newline at end of file
+}
diff --git a/network/message/sendCmix.go b/network/message/sendCmix.go
index 669fff559..41911a73e 100644
--- a/network/message/sendCmix.go
+++ b/network/message/sendCmix.go
@@ -13,7 +13,6 @@ import (
 	"time"
 )
 
-
 // Internal send e2e which bypasses the network check, for use in SendE2E and
 // SendUnsafe which do their own network checks
 func (m *Manager) SendCMIX(msg format.Message, param params.CMIX) (id.Round, error) {
diff --git a/network/rounds/historical.go b/network/rounds/historical.go
index eb0be2815..c1a488555 100644
--- a/network/rounds/historical.go
+++ b/network/rounds/historical.go
@@ -7,12 +7,12 @@
 package rounds
 
 import (
+	jww "github.com/spf13/jwalterweatherman"
 	"gitlab.com/elixxir/client/network/gateway"
 	pb "gitlab.com/elixxir/comms/mixmessages"
 	"gitlab.com/xx_network/comms/connect"
 	"gitlab.com/xx_network/primitives/id"
 	"time"
-	jww "github.com/spf13/jwalterweatherman"
 )
 
 type historicalRoundsComms interface {
@@ -79,4 +79,4 @@ func (m *Manager) processHistoricalRounds(comm historicalRoundsComms, quitCh <-c
 			m.lookupRoundMessages <- roundInfo
 		}
 	}
-}
\ No newline at end of file
+}
diff --git a/network/rounds/manager.go b/network/rounds/manager.go
index 8ebedad10..3aeaec294 100644
--- a/network/rounds/manager.go
+++ b/network/rounds/manager.go
@@ -25,8 +25,8 @@ type Manager struct {
 func NewManager(internal internal.Internal, params params.Rounds,
 	bundles chan<- message.Bundle) *Manager {
 	m := &Manager{
-		params:   params,
-		p:        newProcessingRounds(),
+		params: params,
+		p:      newProcessingRounds(),
 
 		historicalRounds:    make(chan id.Round, params.HistoricalRoundsBufferLen),
 		lookupRoundMessages: make(chan *mixmessages.RoundInfo, params.LookupRoundsBufferLen),
diff --git a/network/track.go b/network/track.go
index 6da65c4df..12e8330ee 100644
--- a/network/track.go
+++ b/network/track.go
@@ -109,4 +109,3 @@ func (m *manager) track(rng csprng.Source, comms trackNetworkComms) {
 	checkedRounds.RangeUncheckedMasked(gwRoundsState, roundChecker,
 		int(m.param.MaxCheckedRounds))
 }
-
diff --git a/storage/cmix/roundKeys_test.go b/storage/cmix/roundKeys_test.go
index 2b38e61d1..92c14809f 100644
--- a/storage/cmix/roundKeys_test.go
+++ b/storage/cmix/roundKeys_test.go
@@ -50,7 +50,6 @@ func TestRoundKeys_Encrypt_Consistency(t *testing.T) {
 		28, 227, 140, 81, 202, 212, 140, 63, 12, 82, 214, 222, 76, 13, 194,
 		141, 75, 17, 37, 145, 27, 155, 162, 165, 234}
 
-
 	expectedKmacs := [][]byte{
 		{241, 132, 2, 131, 104, 92, 89, 120, 177, 8, 201,
 			194, 41, 63, 99, 30, 82, 44, 125, 204, 55, 145, 29, 62, 228, 57,
diff --git a/storage/conversation/store.go b/storage/conversation/store.go
index ffae85164..9a8201c69 100644
--- a/storage/conversation/store.go
+++ b/storage/conversation/store.go
@@ -39,4 +39,4 @@ func (s *Store) Get(partner *id.ID) *Conversation {
 		s.mux.Unlock()
 	}
 	return c
-}
\ No newline at end of file
+}
diff --git a/storage/e2e/key.go b/storage/e2e/key.go
index e4851f314..be2f6bcba 100644
--- a/storage/e2e/key.go
+++ b/storage/e2e/key.go
@@ -91,4 +91,4 @@ func (k *Key) denoteUse() {
 // Generates the key and returns it
 func (k *Key) generateKey() e2eCrypto.Key {
 	return e2eCrypto.DeriveKey(k.session.baseKey, k.keyNum)
-}
\ No newline at end of file
+}
diff --git a/storage/e2e/manager.go b/storage/e2e/manager.go
index e8b4f6f36..9ced3b3da 100644
--- a/storage/e2e/manager.go
+++ b/storage/e2e/manager.go
@@ -40,8 +40,8 @@ func newManager(ctx *context, kv *versioned.KV, partnerID *id.ID, myPrivKey *cyc
 		partner: partnerID,
 	}
 
-	m.send = NewSessionBuff(m, "send")
-	m.receive = NewSessionBuff(m, "receive")
+	m.send = NewSessionBuff(m, "send", kv)
+	m.receive = NewSessionBuff(m, "receive", kv)
 
 	sendSession := newSession(m, myPrivKey, partnerPubKey, nil,
 		sendParams, Send, SessionID{})
diff --git a/storage/e2e/session.go b/storage/e2e/session.go
index 4ccf315eb..2c9fb39d4 100644
--- a/storage/e2e/session.go
+++ b/storage/e2e/session.go
@@ -545,4 +545,4 @@ func (s *Session) getUnusedKeys() []*Key {
 //builds the
 func makeSessionPrefix(sid SessionID) string {
 	return fmt.Sprintf(sessionPrefix, sid)
-}
\ No newline at end of file
+}
diff --git a/storage/e2e/sessionBuff.go b/storage/e2e/sessionBuff.go
index 71cd30de4..2f5a84638 100644
--- a/storage/e2e/sessionBuff.go
+++ b/storage/e2e/sessionBuff.go
@@ -8,6 +8,7 @@ package e2e
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/pkg/errors"
 	jww "github.com/spf13/jwalterweatherman"
 	"gitlab.com/elixxir/client/storage/versioned"
@@ -33,13 +34,14 @@ type sessionBuff struct {
 	sendMux sync.Mutex
 }
 
-func NewSessionBuff(manager *Manager, key string) *sessionBuff {
+func NewSessionBuff(manager *Manager, key string, kv *versioned.KV) *sessionBuff {
 	return &sessionBuff{
 		manager:     manager,
 		sessions:    make([]*Session, 0),
 		sessionByID: make(map[SessionID]*Session),
 		mux:         sync.RWMutex{},
 		key:         key,
+		kv:          kv,
 	}
 }
 
@@ -258,9 +260,12 @@ func (sb *sessionBuff) GetByID(id SessionID) *Session {
 func (sb *sessionBuff) Confirm(id SessionID) error {
 	sb.mux.Lock()
 	defer sb.mux.Unlock()
+	fmt.Printf("sb: %v\n", sb)
+	fmt.Printf("sb.sessionById: %v\n", sb.sessionByID)
+
 	s, ok := sb.sessionByID[id]
 	if !ok {
-		return errors.Errorf("Could not confirm session %s, does not exist", s.GetID())
+		return errors.Errorf("Could not confirm session %s, does not exist", id)
 	}
 
 	s.SetNegotiationStatus(Confirmed)
diff --git a/storage/e2e/sessionID.go b/storage/e2e/sessionID.go
index 266a9b076..85c52a0d2 100644
--- a/storage/e2e/sessionID.go
+++ b/storage/e2e/sessionID.go
@@ -17,14 +17,10 @@ func (sid SessionID) String() string {
 	return base64.StdEncoding.EncodeToString(sid[:])
 }
 
-func (sid SessionID) Unmarshal(b []byte) error {
+func (sid *SessionID) Unmarshal(b []byte) error {
 	if len(b) != sessionIDLen {
 		return errors.New("SessionID of invalid length received")
 	}
-
 	copy(sid[:], b)
 	return nil
 }
-
-
-
diff --git a/storage/e2e/stateVector.go b/storage/e2e/stateVector.go
index ce9b5263e..8329ce6e6 100644
--- a/storage/e2e/stateVector.go
+++ b/storage/e2e/stateVector.go
@@ -207,7 +207,6 @@ func (sv *stateVector) Delete() error {
 	return sv.kv.Delete(sv.key)
 }
 
-
 // finds the next used state and sets that as firstAvailable. This does not
 // execute a store and a store must be executed after.
 func (sv *stateVector) nextAvailable() {
@@ -253,4 +252,4 @@ func (sv *stateVector) unmarshal(b []byte) error {
 	sv.vect = svd.Vect
 
 	return nil
-}
\ No newline at end of file
+}
diff --git a/storage/e2e/store.go b/storage/e2e/store.go
index f26aadb15..1386ccccc 100644
--- a/storage/e2e/store.go
+++ b/storage/e2e/store.go
@@ -145,7 +145,6 @@ func (s *Store) AddPartner(partnerID *id.ID, partnerPubKey *cyclic.Int,
 	m := newManager(&s.context, s.kv, partnerID, s.dhPrivateKey, partnerPubKey, sendParams, receiveParams)
 
 	s.managers[*partnerID] = m
-
 	if err := s.save(); err != nil {
 		jww.FATAL.Printf("Failed to add Parter %s: Save of store "+
 			"failed: %s", partnerID, err)
@@ -285,7 +284,6 @@ func (f *fingerprints) Check(fingerprint format.Fingerprint) bool {
 	return ok
 }
 
-
 func (f *fingerprints) Pop(fingerprint format.Fingerprint) (*Key, bool) {
 	f.mux.Lock()
 	defer f.mux.Unlock()
diff --git a/storage/partition/multiPartMessage.go b/storage/partition/multiPartMessage.go
index 9ffa13cac..ba90aec41 100644
--- a/storage/partition/multiPartMessage.go
+++ b/storage/partition/multiPartMessage.go
@@ -204,4 +204,4 @@ func (mpm *multiPartMessage) delete() {
 func makeMultiPartMessageKey(partner *id.ID, messageID uint64) string {
 	return keyMultiPartMessagePrefix + ":" + partner.String() + ":" +
 		string(messageID)
-}
\ No newline at end of file
+}
diff --git a/storage/session.go b/storage/session.go
index 02b3c5a8c..06d1c3da8 100644
--- a/storage/session.go
+++ b/storage/session.go
@@ -18,6 +18,7 @@ import (
 	"gitlab.com/elixxir/client/storage/user"
 	"gitlab.com/elixxir/client/storage/utility"
 	"gitlab.com/elixxir/client/storage/versioned"
+	"gitlab.com/elixxir/crypto/csprng"
 	"gitlab.com/elixxir/crypto/cyclic"
 	"gitlab.com/elixxir/crypto/fastRNG"
 	"gitlab.com/elixxir/crypto/large"
@@ -100,11 +101,6 @@ func New(baseDir, password string, uid *id.ID, salt []byte, rsaKey *rsa.PrivateK
 		return nil, errors.WithMessage(err, "Failed to create session")
 	}
 
-	s.criticalMessages, err = utility.NewE2eMessageBuffer(s.kv, criticalMessagesKey)
-	if err != nil {
-		return nil, errors.WithMessage(err, "Failed to create session")
-	}
-
 	s.garbledMessages, err = utility.NewMeteredCmixMessageBuffer(s.kv, garbledMessagesKey)
 	if err != nil {
 		return nil, errors.WithMessage(err, "Failed to create session")
@@ -297,5 +293,18 @@ func InitTestingSession(i interface{}) *Session {
 		globals.Log.FATAL.Panicf("InitTestingSession failed to create dummy cmix session: %+v", err)
 	}
 	s.cmix = cmix
+
+	e2eStore, err := e2e.NewStore(cmixGrp, kv, cmixGrp.NewInt(2),
+		fastRNG.NewStreamGenerator(7, 3, csprng.NewSystemRNG))
+	if err != nil {
+		globals.Log.FATAL.Panicf("InitTestingSession failed to create dummy cmix session: %+v", err)
+	}
+	s.e2e = e2eStore
+
+	s.criticalMessages, err = utility.NewE2eMessageBuffer(s.kv, criticalMessagesKey)
+	if err != nil {
+		globals.Log.FATAL.Panicf("InitTestingSession failed to create dummy critical messages: %+v", err)
+	}
+
 	return s
 }
diff --git a/storage/versioned/kv.go b/storage/versioned/kv.go
index 400f641a4..26fb8dc31 100644
--- a/storage/versioned/kv.go
+++ b/storage/versioned/kv.go
@@ -114,4 +114,4 @@ func (v *KV) Prefix(prefix string) *KV {
 		prefix: v.prefix + prefix + PrefixSeparator,
 	}
 	return &kvPrefix
-}
\ No newline at end of file
+}
-- 
GitLab