Skip to content
Snippets Groups Projects
Commit 1571dbab authored by Rick Carback's avatar Rick Carback
Browse files

Modify login and separate session loading to ensure that all listeners are...

Modify login and separate session loading to ensure that all listeners are lisening before message receiver starts processing messages
parent 658c404d
No related branches found
No related tags found
No related merge requests found
......@@ -436,51 +436,57 @@ func (cl *Client) Register(preCan bool, registrationCode, nick, email string) (*
return UID, nil
}
// Logs in user and sets session on client object
// returns the nickname or error if login fails
func (cl *Client) Login(UID *id.User) (string, error) {
// LoadSession loads the session object for the UID
func (cl *Client) LoadSession(UID *id.User) error {
session, err := user.LoadSession(cl.storage, UID)
if session == nil {
return "", errors.New("Unable to load session: " + err.Error())
}
(cl.comm).(*io.Messaging).SendGateway =
id.NewNodeFromBytes(cl.ndf.Nodes[0].ID).NewGateway()
(cl.comm).(*io.Messaging).ReceiveGateway =
id.NewNodeFromBytes(cl.ndf.Nodes[len(cl.ndf.Nodes)-1].ID).NewGateway()
if err != nil {
err = errors.New(fmt.Sprintf("Login: Could not login: %s",
err.Error()))
globals.Log.ERROR.Printf(err.Error())
return "", err
return err
}
if session == nil {
return errors.New("Unable to load session: " + err.Error())
}
cl.session = session
return nil
}
pollWaitTimeMillis := 1000 * time.Millisecond
// TODO Don't start the message receiver if it's already started.
// Should be a pretty rare occurrence except perhaps for mobile.
go cl.comm.MessageReceiver(session, pollWaitTimeMillis)
// Logs in user and sets session on client object
// returns the nickname or error if login fails
func (cl *Client) Login(UID *id.User) (string, error) {
(cl.comm).(*io.Messaging).SendGateway =
id.NewNodeFromBytes(cl.ndf.Nodes[0].ID).NewGateway()
(cl.comm).(*io.Messaging).ReceiveGateway =
id.NewNodeFromBytes(cl.ndf.Nodes[len(cl.ndf.Nodes)-1].ID).NewGateway()
// Initialize UDB and nickname "bot" stuff here
bots.InitBots(cl.session, cl.comm, cl.topology)
// Initialize Rekey listeners
rekey.InitRekey(cl.session, cl.comm, cl.topology)
email := session.GetCurrentUser().Email
pollWaitTimeMillis := 1000 * time.Millisecond
// TODO Don't start the message receiver if it's already started.
// Should be a pretty rare occurrence except perhaps for mobile.
go cl.comm.MessageReceiver(cl.session, pollWaitTimeMillis)
email := cl.session.GetCurrentUser().Email
if email != "" {
err = cl.registerForUserDiscovery(email)
globals.Log.INFO.Printf("Registering user as %s", email)
err := cl.registerForUserDiscovery(email)
if err != nil {
globals.Log.ERROR.Printf(
"Unable to register with UDB: %s", err)
return "", err
}
globals.Log.INFO.Printf("Registered!")
}
return session.GetCurrentUser().Nick, nil
return cl.session.GetCurrentUser().Nick, nil
}
// Send prepares and sends a message to the cMix network
......
......@@ -189,6 +189,12 @@ func sessionInitialization() (*id.User, *api.Client) {
globals.Log.INFO.Printf("Skipped Registration, user: %v", uid)
}
err = client.LoadSession(uid)
if err != nil {
globals.Log.FATAL.Panicf("Could not load session: %v", err)
}
return uid, client
}
......@@ -342,6 +348,7 @@ var rootCmd = &cobra.Command{
if len(keyParams) == 5 {
setKeyParams(client)
}
// Set up the listeners for both of the types the client needs for
// the integration test
// Normal text messages
......@@ -522,7 +529,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&userEmail,
"email", "E",
"default@default.com",
"",
"Email to register for User Discovery")
rootCmd.PersistentFlags().StringVar(&userNick,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment