diff --git a/Gopkg.toml b/Gopkg.toml index fbe6b7f6..7555b54f 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -37,10 +37,6 @@ name = "github.com/gorilla/websocket" version = "1.2.0" -[[constraint]] - name = "github.com/urfave/cli" - version = "1.20.0" - [prune] go-tests = true unused-packages = true diff --git a/client/client.go b/client/client.go index d8596572..ae6cbdbf 100644 --- a/client/client.go +++ b/client/client.go @@ -21,6 +21,7 @@ package client import ( + "crypto/tls" "encoding/json" "errors" "fmt" @@ -305,31 +306,56 @@ func (c *Client) Disconnect() { } } -// ConnectTo connects to the server at addr, for now the only supported protocol is tcp +// ConnectToTLS connects to the server at addr using TLS, for now the only supported protocol is tcp // this methods blocks as it also handles the messages from the server -func (c *Client) ConnectTo(addr string) error { - conn, err := net.Dial("tcp", addr) +func (c *Client) ConnectToTLS(addr string, skipVerify bool) error { + conn, err := tls.Dial("tcp", addr, &tls.Config{ + InsecureSkipVerify: skipVerify, + }) if err != nil { return err } c.conn = conn c.IncomingMsgChan = make(chan *message.Message, 10) - err = c.sendHandshakeRequest() - if err != nil { + if err = c.handleHandshake(); err != nil { return err } - err = c.handleHandshakeResponse() + c.closeChan = make(chan struct{}) + return nil +} + +// ConnectTo connects to the server at addr, for now the only supported protocol is tcp +// this methods blocks as it also handles the messages from the server +func (c *Client) ConnectTo(addr string) error { + conn, err := net.Dial("tcp", addr) if err != nil { return err } + c.conn = conn + c.IncomingMsgChan = make(chan *message.Message, 10) + + if err = c.handleHandshake(); err != nil { + return err + } c.closeChan = make(chan struct{}) return nil } +func (c *Client) handleHandshake() error { + if err := c.sendHandshakeRequest(); err != nil { + return err + } + + if err := c.handleHandshakeResponse(); err != nil { + return err + } + return nil +} + // SendRequest sends a request to the server func (c *Client) SendRequest(route string, data []byte) (uint, error) { return c.sendMsg(message.Request, route, data)