Adds user configurable timeout to gopher and gemini connections (as single value) #178
|
@ -257,6 +257,10 @@ theme
|
||||||
Can toggle between visual modes. Valid values are \fInormal\fP, \fIcolor\fP, and \fIinverse\fP. When set to inverse, the normal mode colors are inverted. Both normal and inverse modes filter out terminal escape sequences. When set to color, Bombadillo will render terminal escape sequences representing colors when it finds them in documents.
|
Can toggle between visual modes. Valid values are \fInormal\fP, \fIcolor\fP, and \fIinverse\fP. When set to inverse, the normal mode colors are inverted. Both normal and inverse modes filter out terminal escape sequences. When set to color, Bombadillo will render terminal escape sequences representing colors when it finds them in documents.
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
|
timeout
|
||||||
|
The number of seconds after which connections to gopher or gemini servers should time out if the server has not responded.
|
||||||
|
.TP
|
||||||
|
.B
|
||||||
tlscertificate
|
tlscertificate
|
||||||
A path to a tls certificate file on a user's local filesystem. Defaults to NULL. Both \fItlscertificate\fP and \fItlskey\fP must be set for client certificates to work in gemini.
|
A path to a tls certificate file on a user's local filesystem. Defaults to NULL. Both \fItlscertificate\fP and \fItlskey\fP must be set for client certificates to work in gemini.
|
||||||
.TP
|
.TP
|
||||||
|
|
15
client.go
15
client.go
|
@ -455,6 +455,8 @@ func (c *client) doCommandAs(action string, values []string) {
|
||||||
c.Certs.LoadCertificate(c.Options["tlscertificate"], c.Options["tlskey"])
|
c.Certs.LoadCertificate(c.Options["tlscertificate"], c.Options["tlskey"])
|
||||||
} else if values[0] == "geminiblocks" {
|
} else if values[0] == "geminiblocks" {
|
||||||
gemini.BlockBehavior = c.Options[values[0]]
|
gemini.BlockBehavior = c.Options[values[0]]
|
||||||
|
} else if values[0] == "timeout" {
|
||||||
|
updateTimeouts(c.Options[values[0]])
|
||||||
} else if values[0] == "configlocation" {
|
} else if values[0] == "configlocation" {
|
||||||
c.SetMessage("Cannot set READ ONLY setting 'configlocation'", true)
|
c.SetMessage("Cannot set READ ONLY setting 'configlocation'", true)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
|
@ -1195,3 +1197,16 @@ func findAvailableFileName(fpath, fname string) (string, error) {
|
||||||
|
|
||||||
return savePath, nil
|
return savePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateTimeouts(timeoutString string) error {
|
||||||
|
sec, err := strconv.Atoi(timeoutString)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
timeout := time.Duration(sec) * time.Second
|
||||||
|
|
||||||
|
gopher.Timeout = timeout
|
||||||
|
gemini.TlsTimeout = timeout
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ var defaultOptions = map[string]string{
|
||||||
"showimages": "true",
|
"showimages": "true",
|
||||||
"telnetcommand": "telnet",
|
"telnetcommand": "telnet",
|
||||||
"theme": "normal", // "normal", "inverted", "color"
|
"theme": "normal", // "normal", "inverted", "color"
|
||||||
|
"timeout": "15", // connection timeout for gopher/gemini in seconds
|
||||||
"tlscertificate": "",
|
"tlscertificate": "",
|
||||||
"tlskey": "",
|
"tlskey": "",
|
||||||
"webmode": "none", // "none", "gui", "lynx", "w3m", "elinks"
|
"webmode": "none", // "none", "gui", "lynx", "w3m", "elinks"
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -25,7 +26,8 @@ type TofuDigest struct {
|
||||||
ClientCert tls.Certificate
|
ClientCert tls.Certificate
|
||||||
}
|
}
|
||||||
|
|
||||||
var BlockBehavior = "block"
|
var BlockBehavior string = "block"
|
||||||
|
var TlsTimeout time.Duration = time.Duration(15) * time.Second
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + R E C E I V E R S + + + \\
|
// + + + R E C E I V E R S + + + \\
|
||||||
|
@ -189,7 +191,7 @@ func Retrieve(host, port, resource string, td *TofuDigest) (string, error) {
|
||||||
return &td.ClientCert, nil
|
return &td.ClientCert, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := tls.Dial("tcp", addr, conf)
|
conn, err := tls.DialWithDialer(&net.Dialer{Timeout: TlsTimeout}, "tcp", addr, 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())
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ var types = map[string]string{
|
||||||
"T": "TEL",
|
"T": "TEL",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Timeout time.Duration = time.Duration(15) * time.Second
|
||||||
|
|
||||||
//------------------------------------------------\\
|
//------------------------------------------------\\
|
||||||
// + + + F U N C T I O N S + + + \\
|
// + + + F U N C T I O N S + + + \\
|
||||||
//--------------------------------------------------\\
|
//--------------------------------------------------\\
|
||||||
|
@ -49,7 +51,6 @@ var types = map[string]string{
|
||||||
// be better.
|
// be better.
|
||||||
func Retrieve(host, port, resource string) ([]byte, error) {
|
func Retrieve(host, port, resource string) ([]byte, error) {
|
||||||
nullRes := make([]byte, 0)
|
nullRes := make([]byte, 0)
|
||||||
timeOut := time.Duration(5) * time.Second
|
|
||||||
|
|
||||||
if host == "" || port == "" {
|
if host == "" || port == "" {
|
||||||
return nullRes, errors.New("Incomplete request url")
|
return nullRes, errors.New("Incomplete request url")
|
||||||
|
@ -57,7 +58,7 @@ func Retrieve(host, port, resource string) ([]byte, error) {
|
||||||
|
|
||||||
addr := host + ":" + port
|
addr := host + ":" + port
|
||||||
|
|
||||||
conn, err := net.DialTimeout("tcp", addr, timeOut)
|
conn, err := net.DialTimeout("tcp", addr, Timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nullRes, err
|
return nullRes, err
|
||||||
}
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -82,6 +82,14 @@ func validateOpt(opt, val string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opt == "timeout" {
|
||||||
|
_, err := strconv.Atoi(val)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +134,8 @@ func loadConfig() {
|
||||||
bombadillo.Options[lowerkey] = v.Value
|
bombadillo.Options[lowerkey] = v.Value
|
||||||
if lowerkey == "geminiblocks" {
|
if lowerkey == "geminiblocks" {
|
||||||
gemini.BlockBehavior = v.Value
|
gemini.BlockBehavior = v.Value
|
||||||
|
} else if lowerkey == "timeout" {
|
||||||
|
updateTimeouts(v.Value)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bombadillo.Options[lowerkey] = defaultOptions[lowerkey]
|
bombadillo.Options[lowerkey] = defaultOptions[lowerkey]
|
||||||
|
|
Loading…
Reference in New Issue