diff --git a/api/client.go b/api/client.go index 50f157bbb4ea0ac732e95d761f67ee10fcf50b43..6502059e746f2553a8d985b98045499298f94f5d 100644 --- a/api/client.go +++ b/api/client.go @@ -149,41 +149,50 @@ func NewClient(s globals.Storage, loc string, ndfJSON *ndf.NetworkDefinition) (* // using TLS filepaths to create credential information // for connection establishment func (cl *Client) Connect() error { + var err error if len(cl.ndf.Gateways) < 1 { - globals.Log.ERROR.Printf("Connect: Invalid number of nodes") return errors.New("could not connect due to invalid number of nodes") } - //connect to all gateways + // connect to all gateways for i, gateway := range cl.ndf.Gateways { var gwCreds []byte - var err error if gateway.TlsCertificate != "" { gwCreds = []byte(gateway.TlsCertificate) } gwID := id.NewNodeFromBytes(cl.ndf.Nodes[i].ID).NewGateway() + globals.Log.INFO.Printf("Connecting to gateway at %s...", + gateway.Address) err = (cl.comm).(*io.Messaging).Comms.ConnectToGateway(gwID, gateway.Address, gwCreds) if err != nil { - globals.Log.ERROR.Printf("Failed to connect to gateway %s: %+v", gateway.Address, err) + return errors.New(fmt.Sprintf("Failed to connect to gateway %s: %+v", + gateway.Address, err)) } + globals.Log.INFO.Printf("Connected to gateway at %v successfully!", + gateway.Address) } //connect to the registration server if cl.ndf.Registration.Address != "" { var regCert []byte - var err error if cl.ndf.Registration.TlsCertificate != "" { regCert = []byte(cl.ndf.Registration.TlsCertificate) } addr := io.ConnAddr("registration") + globals.Log.INFO.Printf("Connecting to permissioning at %s...", + cl.ndf.Registration.Address) err = (cl.comm).(*io.Messaging).Comms.ConnectToRegistration(addr, cl.ndf.Registration.Address, regCert) if err != nil { - globals.Log.ERROR.Printf("Failed connecting to permissioning: %+v", err) + return errors.New(fmt.Sprintf( + "Failed connecting to permissioning: %+v", err)) } + globals.Log.INFO.Printf( + "Connected to permissioning at %v successfully!", + cl.ndf.Registration.Address) } else { - globals.Log.WARN.Printf("Unable to find registration server") + globals.Log.WARN.Printf("Unable to find permissioning server!") } - return nil + return err } // Registers user and returns the User ID. @@ -443,10 +452,6 @@ func (cl *Client) Login(UID *id.User) (string, error) { return "", err } - if session == nil { - return "", errors.New("Unable to load session: " + err.Error()) - } - cl.session = session return cl.session.GetCurrentUser().Nick, nil } diff --git a/cmd/root.go b/cmd/root.go index 5391d302a88d6c32ef0da25527926223e82a2207..7e761275eab0b0ffe2644889d69a8050c724091b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -150,13 +150,10 @@ func sessionInitialization() (*id.User, string, *api.Client) { } // Connect to gateways and reg server - globals.Log.INFO.Println("Connecting...") err = client.Connect() - if err != nil { globals.Log.FATAL.Panicf("Could not call connect on client: %+v", err) } - globals.Log.INFO.Println("Connected!") // Holds the User ID var uid *id.User @@ -622,7 +619,6 @@ func initLog() { // specified from the commandline. func overwriteNDF(n *ndf.NetworkDefinition) { if len(ndfRegistration) == 3 { - n.Registration.DsaPublicKey = ndfRegistration[0] n.Registration.Address = ndfRegistration[1] n.Registration.TlsCertificate = ndfRegistration[2] @@ -637,7 +633,6 @@ func overwriteNDF(n *ndf.NetworkDefinition) { } n.UDB.ID = udbIdString - n.UDB.DsaPublicKey = ndfUDB[1] globals.Log.WARN.Println("Overwrote UDB values in the " + "NetworkDefinition from the commandline")