diff --git a/cmd/root.go b/cmd/root.go index f4de36d5f2e17a1d2df6284132fda3503f192140..4fe59246c05ee9ac47df68cff958e0c3b22e0fb5 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,14 +15,6 @@ import ( "github.com/spf13/cobra" jww "github.com/spf13/jwalterweatherman" "github.com/spf13/viper" - "gitlab.com/elixxir/client/api" - "gitlab.com/elixxir/client/cmixproto" - "gitlab.com/elixxir/client/globals" - "gitlab.com/elixxir/client/network" - "gitlab.com/elixxir/client/network/keyExchange" - "gitlab.com/elixxir/client/parse" - "gitlab.com/elixxir/client/user" - "gitlab.com/elixxir/client/userRegistry" "gitlab.com/elixxir/primitives/switchboard" "gitlab.com/elixxir/primitives/utils" "gitlab.com/xx_network/crypto/signature/rsa" @@ -397,199 +389,18 @@ var rootCmd = &cobra.Command{ if logPath == "" && viper.Get("logPath") != nil { logPath = viper.GetString("logPath") } - globals.Log = globals.InitLog(verbose, logPath) // Disable stdout output jww.SetStdoutOutput(ioutil.Discard) - // Main client run function - userID, _, client := sessionInitialization() - err := client.RegisterWithNodes() + // Use log file + logOutput, err := os.OpenFile(logPath, + os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { - globals.Log.ERROR.Println(err) + panic(err.Error()) } - // Set Key parameters if defined - if len(keyParams) == 5 { - setKeyParams(client) + jww.SetLogOutput(logOutput) + if verbose { + jww.SetLogThreshold(verbose) } - - // Set up the listeners for both of the types the client needs for - // the integration test - // Normal text messages - text := TextListener{} - client.Listen(&id.ZeroUser, int32(keyExchange.Type_TEXT_MESSAGE), - &text) - // All other messages - fallback := FallbackListener{} - client.Listen(&id.ZeroUser, int32(keyExchange.Type_NO_TYPE), - &fallback) - - // Log the user in, for now using the first gateway specified - // This will also register the user email with UDB - globals.Log.INFO.Println("Logging in...") - cb := func(err error) { - globals.Log.ERROR.Print(err) - } - - err = client.InitListeners() - if err != nil { - globals.Log.FATAL.Panicf("Could not initialize receivers: %+v\n", err) - } - - err = client.StartMessageReceiver(cb) - - if err != nil { - globals.Log.FATAL.Panicf("Could Not start message reciever: %s\n", err) - } - globals.Log.INFO.Println("Logged In!") - globals.Log.INFO.Printf("session prior to udb reg: %v", client.GetSession()) - - // todo: since this is in the root cmd, would checking the regstate directly really be bad? - // It's correct that it should be an error state for RegisterWithUDB, however for this, it's start up code - regState, err := network.SessionV2.GetRegState() - if err != nil { - globals.Log.FATAL.Panicf("Could not retrieve registration state: %v", err) - } - - if username != "" && regState == user.PermissioningComplete { - err := client.RegisterWithUDB(username, 2*time.Minute) - if err != nil { - globals.Log.ERROR.Printf("%+v", err) - } - } - - cryptoType := parse.Unencrypted - if end2end { - cryptoType = parse.E2E - } - - var recipientId *id.ID - - if destinationUserId != 0 && destinationUserIDBase64 != "" { - globals.Log.FATAL.Panicf("Two destiantions set for the message, can only have one") - } - - if destinationUserId == 0 && destinationUserIDBase64 == "" { - recipientId = userID - } else if destinationUserIDBase64 != "" { - recipientIdBytes, err := base64.StdEncoding.DecodeString(destinationUserIDBase64) - if err != nil { - globals.Log.FATAL.Panic("Could not decode the destination user ID") - } - recipientId, err = id.Unmarshal(recipientIdBytes) - if err != nil { - // Destination user ID must be 33 bytes and include the id type - globals.Log.FATAL.Panicf("Could not unmarshal destination user ID: %v", err) - } - } else { - recipientId = new(id.ID) - binary.BigEndian.PutUint64(recipientId[:], destinationUserId) - recipientId.SetType(id.User) - } - - if message != "" { - // Get the recipient's nick - recipientNick := "" - u, ok := userRegistry.Users.GetUser(recipientId) - if ok { - recipientNick = u.Username - } - - // Handle sending to UDB - if recipientId.Cmp(&id.UDB) { - parseUdbMessage(message, client) - } else { - // Handle sending to any other destination - wireOut := api.FormatTextMessage(message) - - for i := uint(0); i < messageCnt; i++ { - logMsg := fmt.Sprintf( - "Sending Message to "+ - "%s, %v: %s\n", printIDNice(recipientId), - recipientNick, message) - globals.Log.INFO.Printf(logMsg) - fmt.Printf(logMsg) - if i != 0 { - time.Sleep(1 * time.Second) - } - // Send the message - err := client.Send(&parse.Message{ - Sender: userID, - TypedBody: parse.TypedBody{ - MessageType: int32(keyExchange.Type_TEXT_MESSAGE), - Body: wireOut, - }, - InferredType: cryptoType, - Receiver: recipientId, - }) - if err != nil { - globals.Log.ERROR.Printf("Error sending message: %+v", err) - } - } - } - } - - var udbLister api.SearchCallback - - if searchForUser != "" { - udbLister = newUserSearcher() - client.SearchForUser(searchForUser, udbLister, 2*time.Minute) - } - - if message != "" { - // Wait up to 45s to receive a message - lastCnt := int64(0) - ticker := time.Tick(1 * time.Second) - for end, timeout := false, time.After(50*time.Second); !end; { - numMsgReceived := atomic.LoadInt64(&text.MessagesReceived) - - select { - case <-ticker: - globals.Log.INFO.Printf("Messages recieved: %v\n\tMessages needed: %v", numMsgReceived, waitForMessages) - } - - if numMsgReceived >= int64(waitForMessages) { - end = true - } - if numMsgReceived != lastCnt { - lastCnt = numMsgReceived - timeout = time.After(45 * time.Second) - } - - select { - case <-timeout: - fmt.Printf("Timing out client, %v/%v "+ - "message(s) been received\n", - numMsgReceived, waitForMessages) - end = true - default: - } - } - } - - if searchForUser != "" { - foundUser := <-udbLister.(*userSearcher).foundUserChan - if isValid, uid := isValidUser(foundUser); isValid { - globals.Log.INFO.Printf("Found User %s at ID: %s", - searchForUser, printIDNice(uid)) - } else { - globals.Log.INFO.Printf("Found User %s is invalid", searchForUser) - } - } - - if notificationToken != "" { - err = client.RegisterForNotifications([]byte(notificationToken)) - if err != nil { - globals.Log.FATAL.Printf("failed to register for notifications: %+v", err) - } - } - - //Logout - err = client.Logout(500 * time.Millisecond) - - if err != nil { - globals.Log.ERROR.Printf("Could not logout: %s\n", err.Error()) - return - } - }, } diff --git a/go.mod b/go.mod index 8e9b9723ee02f93fab7f9cb384a2ec59398985c7..eb9aa936004d997747417a194cb114604e907436 100644 --- a/go.mod +++ b/go.mod @@ -15,14 +15,14 @@ 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-20200917172539-929fc227eb0c - gitlab.com/elixxir/crypto v0.0.0-20200917184612-bb2ad1c493ce + gitlab.com/elixxir/comms v0.0.0-20200921200427-5955a0a798b9 + gitlab.com/elixxir/crypto v0.0.0-20200921195205-bca0178268ec gitlab.com/elixxir/ekv v0.1.1 - gitlab.com/elixxir/primitives v0.0.0-20200916172343-37503735c7a1 + gitlab.com/elixxir/primitives v0.0.0-20200915190719-f4586ec93f50 gitlab.com/xx_network/comms v0.0.0-20200915154643-d533291041b7 gitlab.com/xx_network/crypto v0.0.0-20200812183430-c77a5281c686 gitlab.com/xx_network/primitives v0.0.0-20200812183720-516a65a4a9b2 - golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a + golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect golang.org/x/sys v0.0.0-20200828194041-157a740278f4 // indirect google.golang.org/protobuf v1.25.0 gopkg.in/ini.v1 v1.52.0 // indirect diff --git a/go.sum b/go.sum index 59c1eee54265b1e9425143059bdac624ce23ded3..8a8d17271cfcfdbed1e482526736e30371e14cbe 100644 --- a/go.sum +++ b/go.sum @@ -188,6 +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/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= @@ -211,6 +213,7 @@ gitlab.com/elixxir/crypto v0.0.0-20200827170914-14227f20900c h1:1vkxQ0Ol/Kr6szWa gitlab.com/elixxir/crypto v0.0.0-20200827170914-14227f20900c/go.mod h1:D65u4dPjMLSHiENn7fvnleWUcuuSeT48Ttw760Wt3xQ= gitlab.com/elixxir/crypto v0.0.0-20200907171019-008a9d4aa264 h1:8jk4yHw15PpjTPHMpHo5g7io/qp+ryHBxe6S8vllfLs= gitlab.com/elixxir/crypto v0.0.0-20200907171019-008a9d4aa264/go.mod h1:zUczcFuZGqLchDX1sjgBo189soeDK2p5Mx+GNNrkTLI= +gitlab.com/elixxir/crypto v0.0.0-20200915165059-c7f41bbc86b4 h1:Y9xWVPUD/cf0dWKphKWg7dRdEjDgqoHXZLhqOMOs9Ac= gitlab.com/elixxir/crypto v0.0.0-20200915165059-c7f41bbc86b4/go.mod h1:LthCESQ1AfV1H26URYL9kr+XgXXCE7JfEEPpomFPxIo= gitlab.com/elixxir/crypto v0.0.0-20200915172523-b2f2c63560c9 h1:omuo67rgWzlorzLlQQumUkES1w3M5elKFq4PmB+HjJw= gitlab.com/elixxir/crypto v0.0.0-20200915172523-b2f2c63560c9/go.mod h1:zUczcFuZGqLchDX1sjgBo189soeDK2p5Mx+GNNrkTLI= @@ -218,6 +221,10 @@ 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= gitlab.com/elixxir/ekv v0.0.0-20200729182028-159355ea5842/go.mod h1:bXY0kgbV5BHYda4YY5/hiG5bjimGK+R3PYub5yM9C/s= gitlab.com/elixxir/ekv v0.1.1 h1:Em3rF8sv+tNbQGXbcpYzAS2blWRAP708JGhYlkN74Kg=