mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
server: Start roughly hacking in new message-tags support
This commit is contained in:
parent
d2e18962e3
commit
92626a178d
@ -23,7 +23,7 @@ const (
|
|||||||
ExtendedJoin Capability = "extended-join"
|
ExtendedJoin Capability = "extended-join"
|
||||||
InviteNotify Capability = "invite-notify"
|
InviteNotify Capability = "invite-notify"
|
||||||
MaxLine Capability = "draft/maxline"
|
MaxLine Capability = "draft/maxline"
|
||||||
MessageTags Capability = "draft/message-tags"
|
MessageTags Capability = "draft/message-tags-0.2"
|
||||||
MultiPrefix Capability = "multi-prefix"
|
MultiPrefix Capability = "multi-prefix"
|
||||||
SASL Capability = "sasl"
|
SASL Capability = "sasl"
|
||||||
ServerTime Capability = "server-time"
|
ServerTime Capability = "server-time"
|
||||||
|
@ -135,6 +135,21 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) *Client {
|
|||||||
// command goroutine
|
// command goroutine
|
||||||
//
|
//
|
||||||
|
|
||||||
|
func (client *Client) maxlens() (int, int) {
|
||||||
|
maxlenTags := 512
|
||||||
|
maxlenRest := 512
|
||||||
|
if client.capabilities[MessageTags] {
|
||||||
|
maxlenTags = 4096
|
||||||
|
}
|
||||||
|
if client.capabilities[MaxLine] {
|
||||||
|
if maxLineTagsLength > maxlenTags {
|
||||||
|
maxlenTags = maxLineTagsLength
|
||||||
|
}
|
||||||
|
maxlenRest = maxLineRestLength
|
||||||
|
}
|
||||||
|
return maxlenTags, maxlenRest
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) run() {
|
func (client *Client) run() {
|
||||||
var err error
|
var err error
|
||||||
var isExiting bool
|
var isExiting bool
|
||||||
@ -152,14 +167,9 @@ func (client *Client) run() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxLen int
|
maxlenTags, maxlenRest := client.maxlens()
|
||||||
if client.capabilities[MaxLine] {
|
|
||||||
maxLen = maxLineLength
|
|
||||||
} else {
|
|
||||||
maxLen = 512
|
|
||||||
}
|
|
||||||
|
|
||||||
msg, err = ircmsg.ParseLineMaxLen(line, maxLen)
|
msg, err = ircmsg.ParseLineMaxLen(line, maxlenTags, maxlenRest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Quit("received malformed line")
|
client.Quit("received malformed line")
|
||||||
break
|
break
|
||||||
@ -512,16 +522,10 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxLen int
|
|
||||||
if client.capabilities[MaxLine] {
|
|
||||||
maxLen = maxLineLength
|
|
||||||
} else {
|
|
||||||
maxLen = 512
|
|
||||||
}
|
|
||||||
|
|
||||||
// send out the message
|
// send out the message
|
||||||
message := ircmsg.MakeMessage(tags, prefix, command, params...)
|
message := ircmsg.MakeMessage(tags, prefix, command, params...)
|
||||||
line, err := message.LineMaxLen(maxLen)
|
maxlenTags, maxlenRest := client.maxlens()
|
||||||
|
line, err := message.LineMaxLen(maxlenTags, maxlenRest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try not to fail quietly - especially useful when running tests, as a note to dig deeper
|
// try not to fail quietly - especially useful when running tests, as a note to dig deeper
|
||||||
// log.Println("Error assembling message:")
|
// log.Println("Error assembling message:")
|
||||||
|
@ -116,6 +116,11 @@ type ConnectionThrottleConfig struct {
|
|||||||
Exempted []string
|
Exempted []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LineLenConfig struct {
|
||||||
|
Tags int
|
||||||
|
Rest int
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Network struct {
|
Network struct {
|
||||||
Name string
|
Name string
|
||||||
@ -155,11 +160,11 @@ type Config struct {
|
|||||||
ChanListModes uint `yaml:"chan-list-modes"`
|
ChanListModes uint `yaml:"chan-list-modes"`
|
||||||
ChannelLen uint `yaml:"channellen"`
|
ChannelLen uint `yaml:"channellen"`
|
||||||
KickLen uint `yaml:"kicklen"`
|
KickLen uint `yaml:"kicklen"`
|
||||||
LineLen uint `yaml:"linelen"`
|
|
||||||
MonitorEntries uint `yaml:"monitor-entries"`
|
MonitorEntries uint `yaml:"monitor-entries"`
|
||||||
NickLen uint `yaml:"nicklen"`
|
NickLen uint `yaml:"nicklen"`
|
||||||
TopicLen uint `yaml:"topiclen"`
|
TopicLen uint `yaml:"topiclen"`
|
||||||
WhowasEntries uint `yaml:"whowas-entries"`
|
WhowasEntries uint `yaml:"whowas-entries"`
|
||||||
|
LineLen LineLenConfig `yaml:"linelen"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,7 +341,7 @@ func LoadConfig(filename string) (config *Config, err error) {
|
|||||||
return nil, fmt.Errorf("Could not parse connection-throttle ban-duration: %s", err.Error())
|
return nil, fmt.Errorf("Could not parse connection-throttle ban-duration: %s", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if config.Limits.LineLen < 512 {
|
if config.Limits.LineLen.Tags < 512 || config.Limits.LineLen.Rest < 512 {
|
||||||
return nil, errors.New("Line length must be 512 or greater")
|
return nil, errors.New("Line length must be 512 or greater")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,8 @@ var (
|
|||||||
Ver = fmt.Sprintf("oragono-%s", SemVer)
|
Ver = fmt.Sprintf("oragono-%s", SemVer)
|
||||||
|
|
||||||
// Used as the standard maximum line length unless overridden at runtime.
|
// Used as the standard maximum line length unless overridden at runtime.
|
||||||
maxLineLength = 512
|
maxLineTagsLength = 512
|
||||||
|
maxLineRestLength = 512
|
||||||
// maxLastArgLength is used to simply cap off the final argument when creating general messages where we need to select a limit.
|
// maxLastArgLength is used to simply cap off the final argument when creating general messages where we need to select a limit.
|
||||||
// for instance, in MONITOR lists, RPL_ISUPPORT lists, etc.
|
// for instance, in MONITOR lists, RPL_ISUPPORT lists, etc.
|
||||||
maxLastArgLength = 400
|
maxLastArgLength = 400
|
||||||
|
@ -37,7 +37,7 @@ var (
|
|||||||
errDbOutOfDate = errors.New("Database schema is old.")
|
errDbOutOfDate = errors.New("Database schema is old.")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Limits holds the maximum limits for various things such as topic lengths
|
// Limits holds the maximum limits for various things such as topic lengths.
|
||||||
type Limits struct {
|
type Limits struct {
|
||||||
AwayLen int
|
AwayLen int
|
||||||
ChannelLen int
|
ChannelLen int
|
||||||
@ -46,7 +46,13 @@ type Limits struct {
|
|||||||
NickLen int
|
NickLen int
|
||||||
TopicLen int
|
TopicLen int
|
||||||
ChanListModes int
|
ChanListModes int
|
||||||
LineLen int
|
LineLen LineLenLimits
|
||||||
|
}
|
||||||
|
|
||||||
|
// LineLenLimits holds the maximum limits for IRC lines.
|
||||||
|
type LineLenLimits struct {
|
||||||
|
Tags int
|
||||||
|
Rest int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenerInterface represents an interface for a listener.
|
// ListenerInterface represents an interface for a listener.
|
||||||
@ -147,10 +153,9 @@ func NewServer(configFilename string, config *Config) *Server {
|
|||||||
SupportedCapabilities[SASL] = true
|
SupportedCapabilities[SASL] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Limits.LineLen > 512 {
|
if config.Limits.LineLen.Tags > 512 || config.Limits.LineLen.Rest > 512 {
|
||||||
maxLineLength = int(config.Limits.LineLen)
|
|
||||||
SupportedCapabilities[MaxLine] = true
|
SupportedCapabilities[MaxLine] = true
|
||||||
CapValues[MaxLine] = strconv.Itoa(int(config.Limits.LineLen))
|
CapValues[MaxLine] = fmt.Sprintf("%d,%d", config.Limits.LineLen.Tags, config.Limits.LineLen.Rest)
|
||||||
}
|
}
|
||||||
|
|
||||||
operClasses, err := config.OperatorClasses()
|
operClasses, err := config.OperatorClasses()
|
||||||
@ -191,7 +196,10 @@ func NewServer(configFilename string, config *Config) *Server {
|
|||||||
NickLen: int(config.Limits.NickLen),
|
NickLen: int(config.Limits.NickLen),
|
||||||
TopicLen: int(config.Limits.TopicLen),
|
TopicLen: int(config.Limits.TopicLen),
|
||||||
ChanListModes: int(config.Limits.ChanListModes),
|
ChanListModes: int(config.Limits.ChanListModes),
|
||||||
LineLen: int(config.Limits.LineLen),
|
LineLen: LineLenLimits{
|
||||||
|
Tags: config.Limits.LineLen.Tags,
|
||||||
|
Rest: config.Limits.LineLen.Rest,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
listeners: make(map[string]ListenerInterface),
|
listeners: make(map[string]ListenerInterface),
|
||||||
monitoring: make(map[string][]Client),
|
monitoring: make(map[string][]Client),
|
||||||
@ -1108,7 +1116,7 @@ func (server *Server) rehash() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// line lengths cannot be changed after launching the server
|
// line lengths cannot be changed after launching the server
|
||||||
if maxLineLength != int(config.Limits.LineLen) {
|
if maxLineTagsLength != config.Limits.LineLen.Tags || maxLineRestLength != config.Limits.LineLen.Rest {
|
||||||
return fmt.Errorf("Maximum line length (linelen) cannot be changed after launching the server, rehash aborted")
|
return fmt.Errorf("Maximum line length (linelen) cannot be changed after launching the server, rehash aborted")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,4 +204,9 @@ limits:
|
|||||||
chan-list-modes: 60
|
chan-list-modes: 60
|
||||||
|
|
||||||
# maximum length of IRC lines
|
# maximum length of IRC lines
|
||||||
linelen: 2048
|
linelen:
|
||||||
|
# tags section
|
||||||
|
tags: 2048
|
||||||
|
|
||||||
|
# rest of the message
|
||||||
|
rest: 2048
|
||||||
|
Loading…
Reference in New Issue
Block a user