mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-25 13:29:27 +01:00
fix #190
This commit is contained in:
parent
8fd1446627
commit
d1f5c59eef
@ -86,7 +86,9 @@ type Client struct {
|
|||||||
// NewClient returns a client with all the appropriate info setup.
|
// NewClient returns a client with all the appropriate info setup.
|
||||||
func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
|
func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
socket := NewSocket(conn, server.MaxSendQBytes)
|
limits := server.Limits()
|
||||||
|
fullLineLenLimit := limits.LineLen.Tags + limits.LineLen.Rest
|
||||||
|
socket := NewSocket(conn, fullLineLenLimit*2, server.MaxSendQBytes())
|
||||||
go socket.RunSocketWriter()
|
go socket.RunSocketWriter()
|
||||||
client := &Client{
|
client := &Client{
|
||||||
atime: now,
|
atime: now,
|
||||||
@ -230,7 +232,11 @@ func (client *Client) run() {
|
|||||||
|
|
||||||
line, err = client.socket.Read()
|
line, err = client.socket.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Quit("connection closed")
|
quitMessage := "connection closed"
|
||||||
|
if err == errReadQ {
|
||||||
|
quitMessage = "readQ exceeded"
|
||||||
|
}
|
||||||
|
client.Quit(quitMessage)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ type Config struct {
|
|||||||
ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
|
ProxyAllowedFrom []string `yaml:"proxy-allowed-from"`
|
||||||
WebIRC []webircConfig `yaml:"webirc"`
|
WebIRC []webircConfig `yaml:"webirc"`
|
||||||
MaxSendQString string `yaml:"max-sendq"`
|
MaxSendQString string `yaml:"max-sendq"`
|
||||||
MaxSendQBytes uint64
|
MaxSendQBytes int
|
||||||
ConnectionLimiter connection_limits.LimiterConfig `yaml:"connection-limits"`
|
ConnectionLimiter connection_limits.LimiterConfig `yaml:"connection-limits"`
|
||||||
ConnectionThrottler connection_limits.ThrottlerConfig `yaml:"connection-throttling"`
|
ConnectionThrottler connection_limits.ThrottlerConfig `yaml:"connection-throttling"`
|
||||||
}
|
}
|
||||||
@ -520,10 +520,11 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Server.MaxSendQBytes, err = bytefmt.ToBytes(config.Server.MaxSendQString)
|
maxSendQBytes, err := bytefmt.ToBytes(config.Server.MaxSendQString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Could not parse maximum SendQ size (make sure it only contains whole numbers): %s", err.Error())
|
return nil, fmt.Errorf("Could not parse maximum SendQ size (make sure it only contains whole numbers): %s", err.Error())
|
||||||
}
|
}
|
||||||
|
config.Server.MaxSendQBytes = int(maxSendQBytes)
|
||||||
|
|
||||||
// get language files
|
// get language files
|
||||||
config.Languages.Data = make(map[string]languages.LangData)
|
config.Languages.Data = make(map[string]languages.LangData)
|
||||||
|
@ -40,6 +40,7 @@ var (
|
|||||||
var (
|
var (
|
||||||
errNoPeerCerts = errors.New("Client did not provide a certificate")
|
errNoPeerCerts = errors.New("Client did not provide a certificate")
|
||||||
errNotTLS = errors.New("Not a TLS connection")
|
errNotTLS = errors.New("Not a TLS connection")
|
||||||
|
errReadQ = errors.New("ReadQ Exceeded")
|
||||||
)
|
)
|
||||||
|
|
||||||
// String Errors
|
// String Errors
|
||||||
|
@ -6,8 +6,17 @@ package irc
|
|||||||
import (
|
import (
|
||||||
"github.com/oragono/oragono/irc/isupport"
|
"github.com/oragono/oragono/irc/isupport"
|
||||||
"github.com/oragono/oragono/irc/modes"
|
"github.com/oragono/oragono/irc/modes"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (server *Server) MaxSendQBytes() int {
|
||||||
|
return int(atomic.LoadUint64(&server.maxSendQBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) SetMaxSendQBytes(m int) {
|
||||||
|
atomic.StoreUint64(&server.maxSendQBytes, uint64(m))
|
||||||
|
}
|
||||||
|
|
||||||
func (server *Server) ISupport() *isupport.List {
|
func (server *Server) ISupport() *isupport.List {
|
||||||
server.configurableStateMutex.RLock()
|
server.configurableStateMutex.RLock()
|
||||||
defer server.configurableStateMutex.RUnlock()
|
defer server.configurableStateMutex.RUnlock()
|
||||||
|
@ -109,7 +109,7 @@ type Server struct {
|
|||||||
limits Limits
|
limits Limits
|
||||||
listeners map[string]*ListenerWrapper
|
listeners map[string]*ListenerWrapper
|
||||||
logger *logger.Manager
|
logger *logger.Manager
|
||||||
MaxSendQBytes uint64
|
maxSendQBytes uint64
|
||||||
monitorManager *MonitorManager
|
monitorManager *MonitorManager
|
||||||
motdLines []string
|
motdLines []string
|
||||||
name string
|
name string
|
||||||
@ -932,16 +932,7 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
|||||||
server.configurableStateMutex.Unlock()
|
server.configurableStateMutex.Unlock()
|
||||||
|
|
||||||
// set new sendqueue size
|
// set new sendqueue size
|
||||||
if config.Server.MaxSendQBytes != server.MaxSendQBytes {
|
server.SetMaxSendQBytes(config.Server.MaxSendQBytes)
|
||||||
server.configurableStateMutex.Lock()
|
|
||||||
server.MaxSendQBytes = config.Server.MaxSendQBytes
|
|
||||||
server.configurableStateMutex.Unlock()
|
|
||||||
|
|
||||||
// update on all clients
|
|
||||||
for _, sClient := range server.clients.AllClients() {
|
|
||||||
sClient.socket.MaxSendQBytes = config.Server.MaxSendQBytes
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// set RPL_ISUPPORT
|
// set RPL_ISUPPORT
|
||||||
var newISupportReplies [][]string
|
var newISupportReplies [][]string
|
||||||
|
@ -29,7 +29,7 @@ type Socket struct {
|
|||||||
conn net.Conn
|
conn net.Conn
|
||||||
reader *bufio.Reader
|
reader *bufio.Reader
|
||||||
|
|
||||||
MaxSendQBytes uint64
|
maxSendQBytes int
|
||||||
|
|
||||||
// coordination system for asynchronous writes
|
// coordination system for asynchronous writes
|
||||||
buffer []byte
|
buffer []byte
|
||||||
@ -41,11 +41,11 @@ type Socket struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewSocket returns a new Socket.
|
// NewSocket returns a new Socket.
|
||||||
func NewSocket(conn net.Conn, maxSendQBytes uint64) Socket {
|
func NewSocket(conn net.Conn, maxReadQBytes int, maxSendQBytes int) Socket {
|
||||||
return Socket{
|
return Socket{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
reader: bufio.NewReader(conn),
|
reader: bufio.NewReaderSize(conn, maxReadQBytes),
|
||||||
MaxSendQBytes: maxSendQBytes,
|
maxSendQBytes: maxSendQBytes,
|
||||||
lineToSendExists: make(chan bool, 1),
|
lineToSendExists: make(chan bool, 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,10 +92,13 @@ func (socket *Socket) Read() (string, error) {
|
|||||||
return "", io.EOF
|
return "", io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
lineBytes, err := socket.reader.ReadBytes('\n')
|
lineBytes, isPrefix, err := socket.reader.ReadLine()
|
||||||
|
if isPrefix {
|
||||||
|
return "", errReadQ
|
||||||
|
}
|
||||||
|
|
||||||
// convert bytes to string
|
// convert bytes to string
|
||||||
line := string(lineBytes[:])
|
line := string(lineBytes)
|
||||||
|
|
||||||
// read last message properly (such as ERROR/QUIT/etc), just fail next reads/writes
|
// read last message properly (such as ERROR/QUIT/etc), just fail next reads/writes
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
@ -108,7 +111,7 @@ func (socket *Socket) Read() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimRight(line, "\r\n"), nil
|
return line, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write sends the given string out of Socket.
|
// Write sends the given string out of Socket.
|
||||||
@ -116,7 +119,7 @@ func (socket *Socket) Write(data string) (err error) {
|
|||||||
socket.Lock()
|
socket.Lock()
|
||||||
if socket.closed {
|
if socket.closed {
|
||||||
err = io.EOF
|
err = io.EOF
|
||||||
} else if uint64(len(data)+len(socket.buffer)) > socket.MaxSendQBytes {
|
} else if len(data)+len(socket.buffer) > socket.maxSendQBytes {
|
||||||
socket.sendQExceeded = true
|
socket.sendQExceeded = true
|
||||||
err = errSendQExceeded
|
err = errSendQExceeded
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user