diff --git a/api/client.go b/api/client.go index 1d1e91815884bc925e2c329b2cf2b9b87a7d52cf..d2735cd8689b73c17e89104146545be8be5f09b4 100644 --- a/api/client.go +++ b/api/client.go @@ -7,17 +7,13 @@ package api import ( - "bufio" - "crypto" - "crypto/sha256" - "encoding/base64" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/interfaces" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/network" "gitlab.com/elixxir/client/permissioning" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/switchboard" "gitlab.com/elixxir/comms/client" @@ -27,10 +23,8 @@ import ( "gitlab.com/elixxir/crypto/fastRNG" "gitlab.com/elixxir/crypto/large" "gitlab.com/xx_network/crypto/signature/rsa" - "gitlab.com/xx_network/crypto/tls" "gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/ndf" - "strings" ) type Client struct { @@ -47,7 +41,7 @@ type Client struct { // note that the manager has a pointer to the context in many cases, but // this interface allows it to be mocked for easy testing without the // loop - network context.NetworkManager + network interfaces.NetworkManager //object used to register and communicate with permissioning permissioning *permissioning.Permissioning } @@ -57,11 +51,41 @@ type Client struct { // merely creates a new cryptographic identity for adding such information // at a later date. func NewClient(defJSON, storageDir string, password []byte) (*Client, error) { - if clientStorageExists(storageDir) { - return nil, errors.Errorf("client already exists at %s", - storageDir) + // Use fastRNG for RNG ops (AES fortuna based RNG using system RNG) + rngStreamGen := fastRNG.NewStreamGenerator(12, 3, csprng.NewSystemRNG) + rngStream := rngStreamGen.GetStream() + + // Parse the NDF + def, err := parseNDF(defJSON) + if err != nil { + return nil, err } + cmixGrp, e2eGrp := decodeGroups(def) + + protoUser := createNewUser(rngStream, cmixGrp, e2eGrp) + // Create Storage + passwordStr := string(password) + storageSess, err := storage.New(storageDir, passwordStr, + protoUser.UID, protoUser.Salt, protoUser.RSAKey, protoUser.IsPrecanned, + protoUser.CMixKey, protoUser.E2EKey, cmixGrp, e2eGrp, rngStreamGen) + if err != nil { + return nil, err + } + + // Save NDF to be used in the future + storageSess.SetBaseNDF(def) + + //execute the rest of the loading as normal + return loadClient(storageSess, rngStreamGen) +} + +// NewPrecannedClient creates an insecure user with predetermined keys with nodes +// It creates client storage, generates keys, connects, and registers +// with the network. Note that this does not register a username/identity, but +// merely creates a new cryptographic identity for adding such information +// at a later date. +func NewPrecannedClient(precannedID uint, defJSON, storageDir string, password []byte) (*Client, error) { // Use fastRNG for RNG ops (AES fortuna based RNG using system RNG) rngStreamGen := fastRNG.NewStreamGenerator(12, 3, csprng.NewSystemRNG) rngStream := rngStreamGen.GetStream() @@ -73,7 +97,7 @@ func NewClient(defJSON, storageDir string, password []byte) (*Client, error) { } cmixGrp, e2eGrp := decodeGroups(def) - protoUser := createNewUser(rngStream, cmixGrp, e2eGrp) + protoUser := createPrecannedUser(precannedID, rngStream, cmixGrp, e2eGrp) // Create Storage passwordStr := string(password) @@ -91,13 +115,9 @@ func NewClient(defJSON, storageDir string, password []byte) (*Client, error) { return loadClient(storageSess, rngStreamGen) } + // LoadClient initalizes a client object from existing storage. func LoadClient(storageDir string, password []byte) (*Client, error) { - if !clientStorageExists(storageDir) { - return nil, errors.Errorf("client does not exist at %s", - storageDir) - } - // Use fastRNG for RNG ops (AES fortuna based RNG using system RNG) rngStreamGen := fastRNG.NewStreamGenerator(12, 3, csprng.NewSystemRNG) @@ -392,69 +412,18 @@ func (c *Client) RegisterRoundEventsCb( } // ----- Utility Functions ----- - -// clientStorageExists returns true if an EKV (storage.Session) exists in the -// given location or not. -func clientStorageExists(storageDir string) bool { - // Check if diretory exists. - - // If directory exists, check if either .ekv.1 or .ekv.2 files exist in - // the directory. - - return false -} - -// parseNDF parses the initial ndf string for the client. This includes a -// network public key that is also used to verify integrity of the ndf. +// parseNDF parses the initial ndf string for the client. do not check the +// signature, it is deprecated. func parseNDF(ndfString string) (*ndf.NetworkDefinition, error) { if ndfString == "" { return nil, errors.New("ndf file empty") } - ndfReader := bufio.NewReader(strings.NewReader(ndfString)) - - // ndfData is the json string defining the ndf - ndfData, err := ndfReader.ReadBytes('\n') - ndfData = ndfData[:len(ndfData)-1] - if err != nil { - return nil, err - } - - // ndfSignature is the second line of the file, used to verify - // integrity. - ndfSignature, err := ndfReader.ReadBytes('\n') - if err != nil { - return nil, err - } - ndfSignature, err = base64.StdEncoding.DecodeString( - string(ndfSignature[:len(ndfSignature)-1])) - if err != nil { - return nil, err - } - ndf, _, err := ndf.DecodeNDF(ndfString) if err != nil { return nil, err } - // Load the TLS cert given to us, and from that get the RSA public key - cert, err := tls.LoadCertificate(ndf.Registration.TlsCertificate) - if err != nil { - return nil, err - } - pubKey := cert.PublicKey.(*rsa.PublicKey) - - // Hash NDF JSON - rsaHash := sha256.New() - rsaHash.Write(ndfData) - - // Verify signature - err = rsa.Verify(pubKey, crypto.SHA256, - rsaHash.Sum(nil), ndfSignature, nil) - if err != nil { - return nil, err - } - return ndf, nil } diff --git a/api/user.go b/api/user.go index bc190327736e958984ce9ce2bf2ef383730d5bfb..7151a88437b2ad1006459733bb79a65c31bfca81 100644 --- a/api/user.go +++ b/api/user.go @@ -7,6 +7,7 @@ package api import ( + "encoding/binary" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/crypto/csprng" "gitlab.com/elixxir/crypto/cyclic" @@ -80,3 +81,30 @@ func createNewUser(rng csprng.Source, cmix, e2e *cyclic.Group) user { } // TODO: Add precanned user code structures here. +// creates a precanned user +func createPrecannedUser(precannedID uint, rng csprng.Source, cmix, e2e *cyclic.Group) user { + // DH Keygen + // FIXME: Why 256 bits? -- this is spec but not explained, it has + // to do with optimizing operations on one side and still preserves + // decent security -- cite this. Why valid for BOTH e2e and cmix? + e2eKeyBytes, err := csprng.GenerateInGroup(e2e.GetPBytes(), 256, rng) + if err != nil { + jww.FATAL.Panicf(err.Error()) + } + + // Salt, UID, etc gen + salt := make([]byte, SaltSize) + + userID := id.ID{} + binary.BigEndian.PutUint64(userID[:], uint64(precannedID)) + userID.SetType(id.User) + + return user{ + UID: &userID, + Salt: salt, + RSAKey: &rsa.PrivateKey{}, + CMixKey: cmix.NewInt(1), + E2EKey: e2e.NewIntFromBytes(e2eKeyBytes), + IsPrecanned: true, + } +} \ No newline at end of file diff --git a/bindings/interfaces.go b/bindings/interfaces.go index 5156dd6b896f10a18637b23e9929f80100c5f982..e7d3f4e272fe86cfb59a4fcce1f5d79300875889 100644 --- a/bindings/interfaces.go +++ b/bindings/interfaces.go @@ -8,7 +8,7 @@ package bindings import ( "gitlab.com/elixxir/client/api" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/stoppable" ) // Client is defined inside the api package. At minimum, it implements all of diff --git a/interfaces/healthTracker.go b/interfaces/healthTracker.go new file mode 100644 index 0000000000000000000000000000000000000000..6208e6cdca6ae7ca08ac68a29922f48c611bad2f --- /dev/null +++ b/interfaces/healthTracker.go @@ -0,0 +1,7 @@ +package interfaces + +type HealthTracker interface { + AddChannel(chan bool) + AddFunc(f func(bool)) + IsHealthy() bool +} diff --git a/context/message/encryptionType.go b/interfaces/message/encryptionType.go similarity index 100% rename from context/message/encryptionType.go rename to interfaces/message/encryptionType.go diff --git a/context/message/receiveMessage.go b/interfaces/message/receiveMessage.go similarity index 100% rename from context/message/receiveMessage.go rename to interfaces/message/receiveMessage.go diff --git a/context/message/sendMessage.go b/interfaces/message/sendMessage.go similarity index 100% rename from context/message/sendMessage.go rename to interfaces/message/sendMessage.go diff --git a/context/message/type.go b/interfaces/message/type.go similarity index 100% rename from context/message/type.go rename to interfaces/message/type.go diff --git a/context/networkManager.go b/interfaces/networkManager.go similarity index 61% rename from context/networkManager.go rename to interfaces/networkManager.go index b2803eb68b7a2ff27770bff5c5c4211ec98bad2f..d2414bd973c4229489ea641fa11725fd04759d3e 100644 --- a/context/networkManager.go +++ b/interfaces/networkManager.go @@ -1,9 +1,9 @@ -package context +package interfaces import ( - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" @@ -18,8 +18,5 @@ type NetworkManager interface { GetStoppable() stoppable.Stoppable } -type HealthTracker interface { - AddChannel(chan bool) - AddFunc(f func(bool)) - IsHealthy() bool -} +//for use in key exchange which needs to be callable inside of network +type SendE2E func(m message.Send, p params.E2E) ([]id.Round, error) \ No newline at end of file diff --git a/context/params/CMIX.go b/interfaces/params/CMIX.go similarity index 100% rename from context/params/CMIX.go rename to interfaces/params/CMIX.go diff --git a/context/params/CMIX_test.go b/interfaces/params/CMIX_test.go similarity index 100% rename from context/params/CMIX_test.go rename to interfaces/params/CMIX_test.go diff --git a/context/params/E2E.go b/interfaces/params/E2E.go similarity index 100% rename from context/params/E2E.go rename to interfaces/params/E2E.go diff --git a/context/params/E2E_test.go b/interfaces/params/E2E_test.go similarity index 100% rename from context/params/E2E_test.go rename to interfaces/params/E2E_test.go diff --git a/context/params/Unsafe.go b/interfaces/params/Unsafe.go similarity index 100% rename from context/params/Unsafe.go rename to interfaces/params/Unsafe.go diff --git a/context/params/message.go b/interfaces/params/message.go similarity index 100% rename from context/params/message.go rename to interfaces/params/message.go diff --git a/context/params/network.go b/interfaces/params/network.go similarity index 100% rename from context/params/network.go rename to interfaces/params/network.go diff --git a/context/params/node.go b/interfaces/params/node.go similarity index 100% rename from context/params/node.go rename to interfaces/params/node.go diff --git a/context/params/rounds.go b/interfaces/params/rounds.go similarity index 100% rename from context/params/rounds.go rename to interfaces/params/rounds.go diff --git a/network/keyExchange/confirm.go b/keyExchange/confirm.go similarity index 96% rename from network/keyExchange/confirm.go rename to keyExchange/confirm.go index 2e4e743f04c5641a15caedb1a1cafeb353938fd5..8083b3d8a68a1a01710c37a9a6df89c6f5067864 100644 --- a/network/keyExchange/confirm.go +++ b/keyExchange/confirm.go @@ -4,8 +4,8 @@ import ( "github.com/golang/protobuf/proto" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/e2e" ) diff --git a/network/keyExchange/exchange.go b/keyExchange/exchange.go similarity index 88% rename from network/keyExchange/exchange.go rename to keyExchange/exchange.go index c498d37a3e6c6bead8d6c9af8961ad92b1a8e28b..604d1b1d26f44c2cad3308079145daf8c3939562 100644 --- a/network/keyExchange/exchange.go +++ b/keyExchange/exchange.go @@ -1,9 +1,9 @@ package keyExchange import ( - "gitlab.com/elixxir/client/context" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/interfaces" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/switchboard" "gitlab.com/xx_network/primitives/id" @@ -15,7 +15,7 @@ const keyExchangeConfirmName = "KeyExchangeConfirm" const keyExchangeMulti = "KeyExchange" func Start(switchboard *switchboard.Switchboard, sess *storage.Session, - net context.NetworkManager, garbledMessageTrigger chan<- struct{}) stoppable.Stoppable { + net interfaces.NetworkManager, garbledMessageTrigger chan<- struct{}) stoppable.Stoppable { // register the rekey trigger thread triggerCh := make(chan message.Receive, 100) diff --git a/network/keyExchange/generate.sh b/keyExchange/generate.sh similarity index 100% rename from network/keyExchange/generate.sh rename to keyExchange/generate.sh diff --git a/network/keyExchange/rekey.go b/keyExchange/rekey.go similarity index 86% rename from network/keyExchange/rekey.go rename to keyExchange/rekey.go index a513c9739e5517ec9e31b496511ea44b2d995b36..a0f3b416327263ff61830a1b60117c85f52300d2 100644 --- a/network/keyExchange/rekey.go +++ b/keyExchange/rekey.go @@ -10,22 +10,21 @@ import ( "github.com/golang/protobuf/proto" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/context/utility" + "gitlab.com/elixxir/client/interfaces" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" + network2 "gitlab.com/elixxir/client/network" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/e2e" "gitlab.com/elixxir/comms/network" ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/crypto/diffieHellman" "gitlab.com/elixxir/primitives/states" - "gitlab.com/xx_network/primitives/id" "time" ) -type SendE2E func(msg message.Send, param params.E2E) ([]id.Round, error) - -func CheckKeyExchanges(instance *network.Instance, sendE2E SendE2E, sess *storage.Session, manager *e2e.Manager) { +func CheckKeyExchanges(instance *network.Instance, sendE2E interfaces.SendE2E, + sess *storage.Session, manager *e2e.Manager) { sessions := manager.TriggerNegotiations() for _, session := range sessions { go trigger(instance, sendE2E, sess, manager, session) @@ -36,7 +35,8 @@ func CheckKeyExchanges(instance *network.Instance, sendE2E SendE2E, sess *storag // session and negotiation, or resenting a negotiation for an already created // session. They run the same negotiation, the former does it on a newly created // session while the latter on an extand -func trigger(instance *network.Instance, sendE2E SendE2E, sess *storage.Session, manager *e2e.Manager, session *e2e.Session) { +func trigger(instance *network.Instance, sendE2E interfaces.SendE2E, + sess *storage.Session, manager *e2e.Manager, session *e2e.Session) { var negotiatingSession *e2e.Session switch session.NegotiationStatus() { // If the passed session is triggering a negotiation on a new session to @@ -65,7 +65,8 @@ func trigger(instance *network.Instance, sendE2E SendE2E, sess *storage.Session, } } -func negotiate(instance *network.Instance, sendE2E SendE2E, sess *storage.Session, session *e2e.Session) error { +func negotiate(instance *network.Instance, sendE2E interfaces.SendE2E, + sess *storage.Session, session *e2e.Session) error { e2eStore := sess.E2e() //generate public key @@ -115,7 +116,7 @@ func negotiate(instance *network.Instance, sendE2E SendE2E, sess *storage.Sessio } //Wait until the result tracking responds - success, numTimeOut, numRoundFail := utility.TrackResults(sendResults, len(rounds)) + success, numTimeOut, numRoundFail := network2.TrackResults(sendResults, len(rounds)) // If a single partition of the Key Negotiation request does not // transmit, the partner cannot read the result. Log the error and set diff --git a/network/keyExchange/trigger.go b/keyExchange/trigger.go similarity index 91% rename from network/keyExchange/trigger.go rename to keyExchange/trigger.go index a4c642e743bf6eadd8e11bd9bccf934dd2686bf8..19d31d52d4f6ba947ab8fca6c54d803ee5ee8b42 100644 --- a/network/keyExchange/trigger.go +++ b/keyExchange/trigger.go @@ -5,11 +5,11 @@ import ( "github.com/golang/protobuf/proto" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/context/stoppable" - "gitlab.com/elixxir/client/context/utility" + "gitlab.com/elixxir/client/interfaces" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" + "gitlab.com/elixxir/client/network" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/e2e" ds "gitlab.com/elixxir/comms/network/dataStructures" @@ -23,7 +23,7 @@ const ( errUnknown = "unknown trigger from partner %s" ) -func startTrigger(sess *storage.Session, net context.NetworkManager, c chan message.Receive, +func startTrigger(sess *storage.Session, net interfaces.NetworkManager, c chan message.Receive, stop *stoppable.Single, garbledMessageTrigger chan<- struct{}) { for true { select { @@ -39,7 +39,7 @@ func startTrigger(sess *storage.Session, net context.NetworkManager, c chan mess } } -func handleTrigger(sess *storage.Session, net context.NetworkManager, request message.Receive, +func handleTrigger(sess *storage.Session, net interfaces.NetworkManager, request message.Receive, garbledMessageTrigger chan<- struct{}) error { //ensure the message was encrypted properly if request.Encryption != message.E2E { @@ -131,7 +131,7 @@ func handleTrigger(sess *storage.Session, net context.NetworkManager, request me } //Wait until the result tracking responds - success, numTimeOut, numRoundFail := utility.TrackResults(sendResults, len(rounds)) + success, numTimeOut, numRoundFail := network.TrackResults(sendResults, len(rounds)) // If a single partition of the Key Negotiation request does not // transmit, the partner will not be able to read the confirmation. If diff --git a/network/keyExchange/xchange.pb.go b/keyExchange/xchange.pb.go similarity index 100% rename from network/keyExchange/xchange.pb.go rename to keyExchange/xchange.pb.go diff --git a/network/keyExchange/xchange.proto b/keyExchange/xchange.proto similarity index 100% rename from network/keyExchange/xchange.proto rename to keyExchange/xchange.proto diff --git a/network/health/healthTracker.go b/network/health/healthTracker.go index 81008b09853c4d71878318eef36139579f124b1a..3fd4f78dbc37d3688ae7cb1d6b95feca8030a29d 100644 --- a/network/health/healthTracker.go +++ b/network/health/healthTracker.go @@ -10,7 +10,7 @@ package health import ( jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/comms/network" "sync" "time" diff --git a/network/manager.go b/network/manager.go index 48fc5d3fd20ce70fbc501f367e641205b9c5d39d..0231702d24bc6a39706466d672a1b24d95df4393 100644 --- a/network/manager.go +++ b/network/manager.go @@ -11,15 +11,15 @@ package network import ( "github.com/pkg/errors" - "gitlab.com/elixxir/client/context" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/interfaces" + "gitlab.com/elixxir/client/interfaces/params" + "gitlab.com/elixxir/client/keyExchange" "gitlab.com/elixxir/client/network/health" "gitlab.com/elixxir/client/network/internal" - "gitlab.com/elixxir/client/network/keyExchange" "gitlab.com/elixxir/client/network/message" "gitlab.com/elixxir/client/network/node" "gitlab.com/elixxir/client/network/rounds" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/switchboard" "gitlab.com/elixxir/comms/client" @@ -51,7 +51,7 @@ type manager struct { // NewManager builds a new reception manager object using inputted key fields func NewManager(session *storage.Session, switchboard *switchboard.Switchboard, rng *fastRNG.StreamGenerator, comms *client.Comms, - params params.Network, ndf *ndf.NetworkDefinition) (context.NetworkManager, error) { + params params.Network, ndf *ndf.NetworkDefinition) (interfaces.NetworkManager, error) { //start network instance instance, err := network.NewInstance(comms.ProtoComms, ndf, nil, nil) @@ -62,8 +62,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{ @@ -95,7 +95,8 @@ func (m *manager) StartRunners() error { m.runners.Add(m.Health) // Node Updates - m.runners.Add(node.StartRegistration(m.Instance, m.Session, m.Rng, m.Comms, m.NodeRegistration)) // Adding/Keys + m.runners.Add(node.StartRegistration(m.Instance, m.Session, m.Rng, + m.Comms, m.NodeRegistration)) // Adding/Keys //TODO-remover //m.runners.Add(StartNodeRemover(m.Context)) // Removing @@ -111,7 +112,8 @@ func (m *manager) StartRunners() error { m.runners.Add(m.round.StartProcessors()) // Key exchange - m.runners.Add(keyExchange.Start(m.Switchboard, m.Session, m, m.message.GetTriggerGarbledCheckChannel())) + m.runners.Add(keyExchange.Start(m.Switchboard, m.Session, m, + m.message.GetTriggerGarbledCheckChannel())) return nil } @@ -122,7 +124,7 @@ func (m *manager) GetStoppable() stoppable.Stoppable { } // GetHealthTracker returns the health tracker -func (m *manager) GetHealthTracker() context.HealthTracker { +func (m *manager) GetHealthTracker() interfaces.HealthTracker { return m.Health } diff --git a/network/message/critical.go b/network/message/critical.go index 130b43afc45fceffb5cdce40f88d271256203254..42caa9421ddc12c2a3c3dca8cce3bb72b3473ea5 100644 --- a/network/message/critical.go +++ b/network/message/critical.go @@ -2,9 +2,9 @@ package message import ( jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/context/utility" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" + "gitlab.com/elixxir/client/network" ds "gitlab.com/elixxir/comms/network/dataStructures" "gitlab.com/elixxir/primitives/states" "time" @@ -46,7 +46,7 @@ func (m *Manager) criticalMessages() { roundEvents.AddRoundEventChan(r, sendResults, 1*time.Minute, states.COMPLETED, states.FAILED) } - success, numTimeOut, numRoundFail := utility.TrackResults(sendResults, len(rounds)) + success, numTimeOut, numRoundFail := network.TrackResults(sendResults, len(rounds)) if !success { jww.ERROR.Printf("critical message send failed to transmit "+ "transmit %v/%v paritions: %v round failures, %v timeouts", diff --git a/network/message/garbled.go b/network/message/garbled.go index b9327fe19aa1e58993ae656d67f3aba4d7e0f3a1..c4fe424b9ccda33a5e9b72c36bde9f86b509e136 100644 --- a/network/message/garbled.go +++ b/network/message/garbled.go @@ -1,7 +1,7 @@ package message import ( - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "time" ) diff --git a/network/message/manager.go b/network/message/manager.go index 6776f88640025cbc13aa8bcc1157e1e9cf97a709..56a45a49fa2892cdc0a949f9cac74e842e5d6a56 100644 --- a/network/message/manager.go +++ b/network/message/manager.go @@ -2,10 +2,10 @@ package message import ( "fmt" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/network/internal" "gitlab.com/elixxir/client/network/message/parse" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/primitives/format" ) diff --git a/network/message/parse/firstMessagePart.go b/network/message/parse/firstMessagePart.go index 3b208326bd04046df31eacf710f51714f0cbf0ff..1d928536a4a105446ec1bc87b255138980b027f0 100644 --- a/network/message/parse/firstMessagePart.go +++ b/network/message/parse/firstMessagePart.go @@ -3,7 +3,7 @@ package parse import ( "encoding/binary" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "time" ) diff --git a/network/message/parse/partition.go b/network/message/parse/partition.go index 8cbd07cd60d2a138a577c03b6df3159a3c268bff..b785e166c3014dc130e31a91518679bff2ac2701 100644 --- a/network/message/parse/partition.go +++ b/network/message/parse/partition.go @@ -3,7 +3,7 @@ package parse import ( "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/storage" "gitlab.com/xx_network/primitives/id" "time" diff --git a/network/message/reception.go b/network/message/reception.go index 656a893eac06f7e5724f07a7ed4789f2f8f5116c..e3cff5f91cf1cc448ce5724372012581b6c0251a 100644 --- a/network/message/reception.go +++ b/network/message/reception.go @@ -1,11 +1,11 @@ package message import ( - "gitlab.com/elixxir/client/context/message" + jww "github.com/spf13/jwalterweatherman" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" - jww "github.com/spf13/jwalterweatherman" "time" ) diff --git a/network/message/sendCmix.go b/network/message/sendCmix.go index 669fff55928c7fc77680d8b76251c350206f042f..34f910ee7a76d0dbb84d439f22453b6df44e2478 100644 --- a/network/message/sendCmix.go +++ b/network/message/sendCmix.go @@ -4,7 +4,7 @@ import ( "github.com/golang-collections/collections/set" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/params" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/network" "gitlab.com/elixxir/primitives/format" diff --git a/network/message/sendE2E.go b/network/message/sendE2E.go index c36cc9d25b4b91d4c7fd309e8101c7895380a3ff..92907519a8a1055536c5329d4554268f1b746814 100644 --- a/network/message/sendE2E.go +++ b/network/message/sendE2E.go @@ -8,9 +8,9 @@ package message import ( "github.com/pkg/errors" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/network/keyExchange" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" + "gitlab.com/elixxir/client/keyExchange" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" "sync" diff --git a/network/message/sendUnsafe.go b/network/message/sendUnsafe.go index 9dc16de8885ca564e80d67ddb245cc69af932d3b..2cabff6fcc194bffe01fc05648af666029d079f0 100644 --- a/network/message/sendUnsafe.go +++ b/network/message/sendUnsafe.go @@ -2,8 +2,8 @@ package message import ( "github.com/pkg/errors" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/crypto/e2e" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" diff --git a/network/node/register.go b/network/node/register.go index 02a882f3f64788b467a24381bfef4a790eb67b1e..37859fee51e40093aa10be6a4377efa97353bf01 100644 --- a/network/node/register.go +++ b/network/node/register.go @@ -8,7 +8,7 @@ import ( "fmt" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" "gitlab.com/elixxir/client/storage/cmix" "gitlab.com/elixxir/client/storage/user" diff --git a/network/node/register_test.go b/network/node/register_test.go index 3d5c27bcdb203d8ddf5360e359a27db184d2b126..a005733131a134e68c600edd57e8eb8b3fa07f27 100644 --- a/network/node/register_test.go +++ b/network/node/register_test.go @@ -2,7 +2,7 @@ package node import ( "crypto/rand" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/client/storage" pb "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/elixxir/comms/network" diff --git a/network/rounds/manager.go b/network/rounds/manager.go index 8ebedad1038a13ce3857afdfce5552d57edc921c..23d53cd3675af38d0cd90b23ed25b09ae17fc8d9 100644 --- a/network/rounds/manager.go +++ b/network/rounds/manager.go @@ -2,10 +2,10 @@ package rounds import ( "fmt" - "gitlab.com/elixxir/client/context/params" - "gitlab.com/elixxir/client/context/stoppable" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/network/internal" "gitlab.com/elixxir/client/network/message" + "gitlab.com/elixxir/client/stoppable" "gitlab.com/elixxir/comms/mixmessages" "gitlab.com/xx_network/primitives/id" ) diff --git a/network/send.go b/network/send.go index 017704acfc010efae74f1b783f7247f1b25f8f01..7e6aeb84e73ca0a30a1ff660aee3855dea4196a8 100644 --- a/network/send.go +++ b/network/send.go @@ -3,8 +3,8 @@ package network import ( "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/primitives/format" "gitlab.com/xx_network/primitives/id" ) diff --git a/context/utility/trackResults.go b/network/trackResults.go similarity index 97% rename from context/utility/trackResults.go rename to network/trackResults.go index 200615a6eb15db6704bba6b4bf5bfe05ee3661da..9b0bd241689556f84803dd20781ef5dbe138c384 100644 --- a/context/utility/trackResults.go +++ b/network/trackResults.go @@ -1,4 +1,4 @@ -package utility +package network import ( ds "gitlab.com/elixxir/comms/network/dataStructures" diff --git a/context/stoppable/cleanup.go b/stoppable/cleanup.go similarity index 90% rename from context/stoppable/cleanup.go rename to stoppable/cleanup.go index a733d74bc175d09403d2a681c8108b528a31d9f2..ffe3cdae60b6c14ca081e18dce3aa0a44b21380d 100644 --- a/context/stoppable/cleanup.go +++ b/stoppable/cleanup.go @@ -37,7 +37,7 @@ func (c *Cleanup) IsRunning() bool { // Name returns the name of the stoppable denoting it has cleanup. func (c *Cleanup) Name() string { - return c.stop.Name() + " with cleanup" + return Name() + " with cleanup" } // Close stops the contained stoppable and runs the cleanup function after. The @@ -51,9 +51,9 @@ func (c *Cleanup) Close(timeout time.Duration) error { start := time.Now() // Run the stoppable - if err := c.stop.Close(timeout); err != nil { + if err := Close(timeout); err != nil { err = errors.WithMessagef(err, "Cleanup for %s not executed", - c.stop.Name()) + Name()) return } @@ -71,10 +71,10 @@ func (c *Cleanup) Close(timeout time.Duration) error { case err := <-complete: if err != nil { err = errors.WithMessagef(err, "Cleanup for %s failed", - c.stop.Name()) + Name()) } case <-timer.C: - err = errors.Errorf("Clean up for %s timeout", c.stop.Name()) + err = errors.Errorf("Clean up for %s timeout", Name()) } }) diff --git a/context/stoppable/cleanup_test.go b/stoppable/cleanup_test.go similarity index 100% rename from context/stoppable/cleanup_test.go rename to stoppable/cleanup_test.go diff --git a/context/stoppable/multi.go b/stoppable/multi.go similarity index 96% rename from context/stoppable/multi.go rename to stoppable/multi.go index 061be492dd4efd2d6c618d7f9772a18fb8cc7ab7..a0f947d02d7a81d359435c8a53597a7bbf3fd714 100644 --- a/context/stoppable/multi.go +++ b/stoppable/multi.go @@ -43,7 +43,7 @@ func (m *Multi) Name() string { m.mux.RLock() names := m.name + ": {" for _, s := range m.stoppables { - names += s.Name() + ", " + names += Name() + ", " } if len(m.stoppables) > 0 { names = names[:len(names)-2] @@ -69,7 +69,7 @@ func (m *Multi) Close(timeout time.Duration) error { for _, stoppable := range m.stoppables { wg.Add(1) go func(stoppable Stoppable) { - if stoppable.Close(timeout) != nil { + if Close(timeout) != nil { atomic.AddUint32(&numErrors, 1) } wg.Done() diff --git a/context/stoppable/multi_test.go b/stoppable/multi_test.go similarity index 100% rename from context/stoppable/multi_test.go rename to stoppable/multi_test.go diff --git a/context/stoppable/single.go b/stoppable/single.go similarity index 100% rename from context/stoppable/single.go rename to stoppable/single.go diff --git a/context/stoppable/single_test.go b/stoppable/single_test.go similarity index 100% rename from context/stoppable/single_test.go rename to stoppable/single_test.go diff --git a/context/stoppable/stoppable.go b/stoppable/stoppable.go similarity index 100% rename from context/stoppable/stoppable.go rename to stoppable/stoppable.go diff --git a/storage/e2e/manager.go b/storage/e2e/manager.go index e8b4f6f369b5a8439a9ce18d5036032a53c9d944..306aeeb3763c6f2992c822aa134de16492cb5ba1 100644 --- a/storage/e2e/manager.go +++ b/storage/e2e/manager.go @@ -9,7 +9,7 @@ package e2e import ( "fmt" "github.com/pkg/errors" - "gitlab.com/elixxir/client/context/params" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/crypto/cyclic" dh "gitlab.com/elixxir/crypto/diffieHellman" diff --git a/storage/partition/multiPartMessage.go b/storage/partition/multiPartMessage.go index 9ffa13cac3725dea3e5932e57fcbc83d2cebf6b7..4fadbc03b5a1a4032487206eeb82da7ee8121db0 100644 --- a/storage/partition/multiPartMessage.go +++ b/storage/partition/multiPartMessage.go @@ -4,7 +4,7 @@ import ( "encoding/json" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" "os" diff --git a/storage/partition/store.go b/storage/partition/store.go index 1126292322cac4d2359c6a8040583ef955680c0c..b372bf1705dee0a5947aad1ca8a86f70ee94cb59 100644 --- a/storage/partition/store.go +++ b/storage/partition/store.go @@ -3,7 +3,7 @@ package partition import ( "crypto/md5" "encoding/binary" - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" "sync" diff --git a/storage/utility/e2eMessageBuffer.go b/storage/utility/e2eMessageBuffer.go index ae9cd73d446c7b8632fd6e563933c74d61c81924..2600016e881361f67c47a986b32c4f8faddea5a3 100644 --- a/storage/utility/e2eMessageBuffer.go +++ b/storage/utility/e2eMessageBuffer.go @@ -5,8 +5,8 @@ import ( "encoding/binary" "encoding/json" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/xx_network/primitives/id" "time" diff --git a/storage/utility/e2eMessageBuffer_test.go b/storage/utility/e2eMessageBuffer_test.go index 067f5d46abce37cb65574411b6e181bba7dff1ea..c5bc81013c41c032197fd6b0a5b9b831defb5104 100644 --- a/storage/utility/e2eMessageBuffer_test.go +++ b/storage/utility/e2eMessageBuffer_test.go @@ -2,8 +2,8 @@ package utility import ( "encoding/json" - "gitlab.com/elixxir/client/context/message" - "gitlab.com/elixxir/client/context/params" + "gitlab.com/elixxir/client/interfaces/message" + "gitlab.com/elixxir/client/interfaces/params" "gitlab.com/elixxir/client/storage/versioned" "gitlab.com/elixxir/ekv" "gitlab.com/xx_network/primitives/id" diff --git a/switchboard/any.go b/switchboard/any.go index aef95e3780a5a917606cb0352a9bb44460977ea0..b460ecac01ba20f5c453d1f90d157bb13bd0ed5f 100644 --- a/switchboard/any.go +++ b/switchboard/any.go @@ -1,7 +1,7 @@ package switchboard import ( - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/xx_network/primitives/id" ) diff --git a/switchboard/byType.go b/switchboard/byType.go index f9a7c6a273115c24499e15388a868459c1319e27..7bf703d75bd1212896c96864ba90d2c71a750273 100644 --- a/switchboard/byType.go +++ b/switchboard/byType.go @@ -2,7 +2,7 @@ package switchboard import ( "github.com/golang-collections/collections/set" - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" ) type byType struct { diff --git a/switchboard/byType_test.go b/switchboard/byType_test.go index fb385195f1cf92a7babea8362af6d438d621aeb6..2570f6a3360efe446aa6ff4957ecd33363e76826 100644 --- a/switchboard/byType_test.go +++ b/switchboard/byType_test.go @@ -2,7 +2,7 @@ package switchboard import ( "github.com/golang-collections/collections/set" - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "testing" ) diff --git a/switchboard/listener.go b/switchboard/listener.go index abd6bea71c77d6c7e3afc7c3920ebe0bc381e9e4..8bc313f51789016bbc23adba454df77b42043934 100644 --- a/switchboard/listener.go +++ b/switchboard/listener.go @@ -8,7 +8,7 @@ package switchboard import ( jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/xx_network/primitives/id" ) diff --git a/switchboard/listener_test.go b/switchboard/listener_test.go index 295310bfbcd34fa8f62f1bbada9ad2c40c75f321..11ea5159902121be678a632db76e196bd0f52682 100644 --- a/switchboard/listener_test.go +++ b/switchboard/listener_test.go @@ -7,7 +7,7 @@ package switchboard import ( - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/xx_network/primitives/id" "reflect" "testing" diff --git a/switchboard/switchboard.go b/switchboard/switchboard.go index 3c04a5a5577b8958e593fab48a729d9fc5520729..2c4eb69cee13a1724f911ca3504900b46f36117f 100644 --- a/switchboard/switchboard.go +++ b/switchboard/switchboard.go @@ -3,7 +3,7 @@ package switchboard import ( "github.com/golang-collections/collections/set" jww "github.com/spf13/jwalterweatherman" - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/xx_network/primitives/id" "sync" ) @@ -135,7 +135,7 @@ func (sw *Switchboard) Speak(item message.Receive) { //Execute hear on all matched listeners in a new goroutine matches.Do(func(i interface{}) { r := i.(Listener) - go Hear(item) + go r.Hear(item) }) // print to log if nothing was heard diff --git a/switchboard/switchboard_test.go b/switchboard/switchboard_test.go index de5a5bbc945fb25ade99357ff91e452f64e9104a..27a7635c2ad301099a854a1945fd6d2bf54761b0 100644 --- a/switchboard/switchboard_test.go +++ b/switchboard/switchboard_test.go @@ -1,7 +1,7 @@ package switchboard import ( - "gitlab.com/elixxir/client/context/message" + "gitlab.com/elixxir/client/interfaces/message" "gitlab.com/xx_network/primitives/id" "strings" "testing"