Adds timeout to dialer so that things wont get so bogged down
This commit is contained in:
parent
caa127ceff
commit
3bac06083d
12
main.go
12
main.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -18,6 +19,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var swPath, fPath string
|
var swPath, fPath string
|
||||||
|
var timeout time.Duration = time.Duration(5) * time.Second
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
// Startup & helpers
|
// Startup & helpers
|
||||||
|
@ -222,9 +224,10 @@ func retrieve(addr string) (string, error) {
|
||||||
}
|
}
|
||||||
conf := &tls.Config{
|
conf := &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := tls.Dial("tcp", hostResource[0], conf)
|
conn, err := tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", hostResource[0], conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("TLS Dial Error: %s", err.Error())
|
return "", fmt.Errorf("TLS Dial Error: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -235,16 +238,19 @@ func retrieve(addr string) (string, error) {
|
||||||
|
|
||||||
_, err = conn.Write([]byte(send))
|
_, err = conn.Write([]byte(send))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Write error:")
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := ioutil.ReadAll(conn)
|
result, err := ioutil.ReadAll(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("Read error:")
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := strings.SplitN(string(result), "\r\n", 2)
|
resp := strings.SplitN(string(result), "\r\n", 2)
|
||||||
if resp[0][0] != '2' || len(resp) < 2 {
|
if len(resp[0]) <= 0 || resp[0][0] != '2' || len(resp) < 2 {
|
||||||
|
fmt.Println(string(result))
|
||||||
return "", fmt.Errorf("Invalid server response")
|
return "", fmt.Errorf("Invalid server response")
|
||||||
}
|
}
|
||||||
h := md5.New()
|
h := md5.New()
|
||||||
|
@ -267,7 +273,7 @@ func checkForUpdate(c []string, r chan []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("UPDATED: %s\n", c[0])
|
fmt.Printf("\033[1mUPDATED: %s\033[0m\n", c[0])
|
||||||
c[2] = chksum
|
c[2] = chksum
|
||||||
currentTime := time.Now()
|
currentTime := time.Now()
|
||||||
c[3] = currentTime.Format("2006-01-02")
|
c[3] = currentTime.Format("2006-01-02")
|
||||||
|
|
Loading…
Reference in New Issue