derp: move write timeout to package constant.
Signed-off-by: David Anderson <dave@natulte.net>pull/203/head
parent
dbfc916273
commit
1e031001db
|
@ -118,7 +118,6 @@ func main() {
|
||||||
letsEncrypt := tsweb.IsProd443(*addr)
|
letsEncrypt := tsweb.IsProd443(*addr)
|
||||||
|
|
||||||
s := derp.NewServer(key.Private(cfg.PrivateKey), log.Printf)
|
s := derp.NewServer(key.Private(cfg.PrivateKey), log.Printf)
|
||||||
s.WriteTimeout = 2 * time.Second
|
|
||||||
expvar.Publish("derp", s.ExpVar())
|
expvar.Publish("derp", s.ExpVar())
|
||||||
|
|
||||||
// Create our own mux so we don't expose /debug/ stuff to the world.
|
// Create our own mux so we don't expose /debug/ stuff to the world.
|
||||||
|
|
|
@ -31,7 +31,10 @@ import (
|
||||||
|
|
||||||
var debug, _ = strconv.ParseBool(os.Getenv("DERP_DEBUG_LOGS"))
|
var debug, _ = strconv.ParseBool(os.Getenv("DERP_DEBUG_LOGS"))
|
||||||
|
|
||||||
const perClientSendQueueDepth = 32 // packets buffered for sending
|
const (
|
||||||
|
perClientSendQueueDepth = 32 // packets buffered for sending
|
||||||
|
writeTimeout = 2 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
// Server is a DERP server.
|
// Server is a DERP server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
@ -560,9 +563,7 @@ func (c *sclient) sendLoop(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *sclient) sendKeepalive() error {
|
func (c *sclient) sendKeepalive() error {
|
||||||
if c.s.WriteTimeout != 0 {
|
c.nc.SetWriteDeadline(time.Now().Add(writeTimeout))
|
||||||
c.nc.SetWriteDeadline(time.Now().Add(c.s.WriteTimeout))
|
|
||||||
}
|
|
||||||
if err := writeFrame(c.bw, frameKeepAlive, nil); err != nil {
|
if err := writeFrame(c.bw, frameKeepAlive, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -583,9 +584,7 @@ func (c *sclient) sendPacket(srcKey key.Public, contents []byte) (err error) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if c.s.WriteTimeout != 0 {
|
c.nc.SetWriteDeadline(time.Now().Add(writeTimeout))
|
||||||
c.nc.SetWriteDeadline(time.Now().Add(c.s.WriteTimeout))
|
|
||||||
}
|
|
||||||
|
|
||||||
withKey := !srcKey.IsZero()
|
withKey := !srcKey.IsZero()
|
||||||
pktLen := len(contents)
|
pktLen := len(contents)
|
||||||
|
|
Loading…
Reference in New Issue