Browse Source

Adds timeout to dialer so that things wont get so bogged down

master
sloum 1 year ago
parent
commit
3bac06083d
  1. 12
      main.go

12
main.go

@ -9,6 +9,7 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/user"
"path/filepath"
@ -18,6 +19,7 @@ import (
)
var swPath, fPath string
var timeout time.Duration = time.Duration(5) * time.Second
///////////////////////////////
// Startup & helpers
@ -222,9 +224,10 @@ func retrieve(addr string) (string, error) {
}
conf := &tls.Config{
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 {
return "", fmt.Errorf("TLS Dial Error: %s", err.Error())
}
@ -235,16 +238,19 @@ func retrieve(addr string) (string, error) {
_, err = conn.Write([]byte(send))
if err != nil {
fmt.Println("Write error:")
return "", err
}
result, err := ioutil.ReadAll(conn)
if err != nil {
fmt.Println("Read error:")
return "", err
}
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")
}
h := md5.New()
@ -267,7 +273,7 @@ func checkForUpdate(c []string, r chan []string) {
return
}
fmt.Printf("UPDATED: %s\n", c[0])
fmt.Printf("\033[1mUPDATED: %s\033[0m\n", c[0])
c[2] = chksum
currentTime := time.Now()
c[3] = currentTime.Format("2006-01-02")

Loading…
Cancel
Save