diff --git a/adc/conn.go b/adc/conn.go index efc4cd1..5f549fa 100644 --- a/adc/conn.go +++ b/adc/conn.go @@ -143,8 +143,8 @@ func (c *Conn) SetWriteTimeout(dt time.Duration) { } } -func (c *Conn) ZOn() error { - return c.w.EnableZlib() +func (c *Conn) ZOn(lvl int) error { + return c.w.EnableZlibLevel(lvl) } // Close closes the connection. diff --git a/hub/cmds.go b/hub/cmds.go index 4afed85..2f9d689 100644 --- a/hub/cmds.go +++ b/hub/cmds.go @@ -548,7 +548,7 @@ func cmdParseString(text string) (string, string, error) { if len(text) == 0 { return "", text, errCmdInvalidArg } - if text[0] != '"' && text[1] != '`' { + if text[0] != '"' && text[0] != '`' { // unquoted string i := strings.IndexByte(text, ' ') if i < 0 { diff --git a/hub/config.go b/hub/config.go index c69836b..3d6b955 100644 --- a/hub/config.go +++ b/hub/config.go @@ -16,6 +16,10 @@ const ( ConfigHubMOTD = "hub.motd" ) +const ( + ConfigZlibLevel = "zlib.level" +) + var configAliases = map[string]string{ "name": ConfigHubName, "desc": ConfigHubDesc, @@ -132,6 +136,7 @@ func (h *Hub) ConfigKeys() []string { ConfigHubOwner, ConfigHubWebsite, ConfigHubEmail, + ConfigZlibLevel, } h.conf.RLock() for k := range h.conf.m { @@ -162,6 +167,12 @@ func (h *Hub) GetConfig(key string) (interface{}, bool) { return nil, false } return v, true + case ConfigZlibLevel: + v, ok := h.GetConfigInt(key) + if !ok { + return nil, false + } + return v, true } h.conf.RLock() v, ok := h.conf.m[key] @@ -309,6 +320,8 @@ func (h *Hub) setConfigInt(key string, val int64) { return } switch key { + case ConfigZlibLevel: + h.setZlibLevel(int(val)) default: h.setConfigMap(key, val) } @@ -324,6 +337,8 @@ func (h *Hub) GetConfigInt(key string) (int64, bool) { key = alias } switch key { + case ConfigZlibLevel: + return int64(h.zlibLevel()), true default: v, ok := h.getConfigMap(key) if !ok || v == nil { diff --git a/hub/hub.go b/hub/hub.go index 7973f2f..5bf20db 100644 --- a/hub/hub.go +++ b/hub/hub.go @@ -66,6 +66,7 @@ func NewHub(conf Config) (*Hub, error) { tls: conf.TLS, } h.conf.Config = conf + h.setZlibLevel(-1) if conf.FallbackEncoding != "" { enc, err := htmlindex.Get(conf.FallbackEncoding) if err != nil { @@ -145,6 +146,9 @@ type Hub struct { names map[string]struct{} // no aliases byName map[string]*Command } + zlib struct { + level int32 + } globalChat *Room rooms rooms @@ -172,6 +176,20 @@ func (h *Hub) decShare(v uint64) { cntShare.Add(-float64(v)) } +func (h *Hub) zlibLevel() int { + return int(atomic.LoadInt32(&h.zlib.level)) +} + +func (h *Hub) setZlibLevel(level int) { + if level < -1 { + level = -1 + } + if level > 9 { + level = 9 + } + atomic.StoreInt32(&h.zlib.level, int32(level)) +} + type Stats struct { Name string `json:"name"` Desc string `json:"desc,omitempty"` diff --git a/hub/hub_adc.go b/hub/hub_adc.go index 2ef45bd..89b4f67 100644 --- a/hub/hub_adc.go +++ b/hub/hub_adc.go @@ -221,12 +221,12 @@ func (h *Hub) adcStageProtocol(c *adc.Conn, cinfo *ConnInfo) (*adcPeer, error) { return nil, fmt.Errorf("client does not support TIGR") } - if mutual.IsSet(adc.FeaZLIF) { + if lvl := h.zlibLevel(); lvl != 0 && mutual.IsSet(adc.FeaZLIF) { err = c.WriteInfoMsg(adc.ZOn{}) if err != nil { return nil, err } - err = c.ZOn() + err = c.ZOn(lvl) if err != nil { return nil, err } diff --git a/hub/hub_nmdc.go b/hub/hub_nmdc.go index 7a5d565..e57dec0 100644 --- a/hub/hub_nmdc.go +++ b/hub/hub_nmdc.go @@ -333,8 +333,8 @@ func (h *Hub) nmdcAccept(peer *nmdcPeer) error { if err != nil { return err } - if peer.fea.Has(nmdcp.ExtZPipe0) { - err = c.ZOn() // flushes + if lvl := h.zlibLevel(); lvl != 0 && peer.fea.Has(nmdcp.ExtZPipe0) { + err = c.ZOn(lvl) // flushes } else { err = c.Flush() } diff --git a/hub/plugins/tor/go.sum b/hub/plugins/tor/go.sum index 53ca9da..0f6d06e 100644 --- a/hub/plugins/tor/go.sum +++ b/hub/plugins/tor/go.sum @@ -83,6 +83,7 @@ github.com/direct-connect/go-dc v0.7.2/go.mod h1:AwUTf54jhNPJvs+QNHoZxEb3p0LS8ik github.com/direct-connect/go-dc v0.7.3/go.mod h1:AwUTf54jhNPJvs+QNHoZxEb3p0LS8ik+2t0R8b4+MdI= github.com/direct-connect/go-dc v0.7.4/go.mod h1:AwUTf54jhNPJvs+QNHoZxEb3p0LS8ik+2t0R8b4+MdI= github.com/direct-connect/go-dc v0.8.0/go.mod h1:AwUTf54jhNPJvs+QNHoZxEb3p0LS8ik+2t0R8b4+MdI= +github.com/direct-connect/go-dc v0.8.1 h1:PSE7WRV+XU+CHkis1RPo73Jnky/Kzn1JZipsGyQm3Dg= github.com/direct-connect/go-dc v0.8.1/go.mod h1:AwUTf54jhNPJvs+QNHoZxEb3p0LS8ik+2t0R8b4+MdI= github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= @@ -307,6 +308,7 @@ golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaE golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480 h1:O5YqonU5IWby+w98jVUG9h7zlCWCcH4RHyPVReBmhzk= golang.org/x/crypto v0.0.0-20190418165655-df01cb2cc480/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 h1:p/H982KKEjUnLJkM3tt/LemDnOc1GiZL5FCVlORJ5zo= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -341,6 +343,7 @@ golang.org/x/net v0.0.0-20190420063019-afa5a82059c6/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190502183928-7f726cade0ab/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c h1:uOCk1iQW6Vc18bnC13MfzScl+wdKBmM9Y9kU7Z83/lw= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -376,6 +379,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2 h1:z99zHgr7hKfrUcX/KsoJk5FJfjTceCKIp96+biqP4To= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/nmdc/conn.go b/nmdc/conn.go index 1e53fa6..1420579 100644 --- a/nmdc/conn.go +++ b/nmdc/conn.go @@ -204,8 +204,8 @@ func (c *Conn) SetFallbackEncoding(enc encoding.Encoding) { c.fallback = enc } -func (c *Conn) ZOn() error { - return c.w.ZOn() +func (c *Conn) ZOn(lvl int) error { + return c.w.ZOnLevel(lvl) } // Close closes the connection.