Skip to content
Snippets Groups Projects
Commit f49eadc0 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

fixed some various log messages around connection

parent 03910933
No related branches found
No related tags found
No related merge requests found
...@@ -149,41 +149,43 @@ func NewClient(s globals.Storage, loc string, ndfJSON *ndf.NetworkDefinition) (* ...@@ -149,41 +149,43 @@ func NewClient(s globals.Storage, loc string, ndfJSON *ndf.NetworkDefinition) (*
// using TLS filepaths to create credential information // using TLS filepaths to create credential information
// for connection establishment // for connection establishment
func (cl *Client) Connect() error { func (cl *Client) Connect() error {
var err error
if len(cl.ndf.Gateways) < 1 { 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") 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 { for i, gateway := range cl.ndf.Gateways {
var gwCreds []byte var gwCreds []byte
var err error
if gateway.TlsCertificate != "" { if gateway.TlsCertificate != "" {
gwCreds = []byte(gateway.TlsCertificate) gwCreds = []byte(gateway.TlsCertificate)
} }
gwID := id.NewNodeFromBytes(cl.ndf.Nodes[i].ID).NewGateway() gwID := id.NewNodeFromBytes(cl.ndf.Nodes[i].ID).NewGateway()
globals.Log.INFO.Printf("Connecting to %s...", gateway.Address)
err = (cl.comm).(*io.Messaging).Comms.ConnectToGateway(gwID, gateway.Address, gwCreds) err = (cl.comm).(*io.Messaging).Comms.ConnectToGateway(gwID, gateway.Address, gwCreds)
if err != nil { 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 %v successfully!", gateway.Address)
} }
//connect to the registration server //connect to the registration server
if cl.ndf.Registration.Address != "" { if cl.ndf.Registration.Address != "" {
var regCert []byte var regCert []byte
var err error
if cl.ndf.Registration.TlsCertificate != "" { if cl.ndf.Registration.TlsCertificate != "" {
regCert = []byte(cl.ndf.Registration.TlsCertificate) regCert = []byte(cl.ndf.Registration.TlsCertificate)
} }
addr := io.ConnAddr("registration") addr := io.ConnAddr("registration")
err = (cl.comm).(*io.Messaging).Comms.ConnectToRegistration(addr, cl.ndf.Registration.Address, regCert) err = (cl.comm).(*io.Messaging).Comms.ConnectToRegistration(addr, cl.ndf.Registration.Address, regCert)
if err != nil { if err != nil {
globals.Log.ERROR.Printf("Failed connecting to permissioning: %+v", err) return errors.New(fmt.Sprintf(
"Failed connecting to permissioning: %+v", err))
} }
} else { } else {
globals.Log.WARN.Printf("Unable to find registration server") globals.Log.WARN.Printf("Unable to find registration server!")
} }
return nil return err
} }
// Registers user and returns the User ID. // Registers user and returns the User ID.
......
...@@ -150,13 +150,10 @@ func sessionInitialization() (*id.User, string, *api.Client) { ...@@ -150,13 +150,10 @@ func sessionInitialization() (*id.User, string, *api.Client) {
} }
// Connect to gateways and reg server // Connect to gateways and reg server
globals.Log.INFO.Println("Connecting...")
err = client.Connect() err = client.Connect()
if err != nil { if err != nil {
globals.Log.FATAL.Panicf("Could not call connect on client: %+v", err) globals.Log.FATAL.Panicf("Could not call connect on client: %+v", err)
} }
globals.Log.INFO.Println("Connected!")
// Holds the User ID // Holds the User ID
var uid *id.User var uid *id.User
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment