2020-03-16 10:18:41 +00:00
|
|
|
package soju
|
|
|
|
|
|
|
|
import (
|
2020-08-11 08:36:14 +00:00
|
|
|
"crypto/sha256"
|
|
|
|
"encoding/binary"
|
2020-08-19 09:24:25 +00:00
|
|
|
"encoding/hex"
|
2020-04-04 02:48:25 +00:00
|
|
|
"fmt"
|
2020-03-16 10:18:41 +00:00
|
|
|
"time"
|
2020-03-16 11:44:59 +00:00
|
|
|
|
|
|
|
"gopkg.in/irc.v3"
|
2020-03-16 10:18:41 +00:00
|
|
|
)
|
|
|
|
|
2020-03-27 15:33:19 +00:00
|
|
|
type event interface{}
|
|
|
|
|
|
|
|
type eventUpstreamMessage struct {
|
2020-03-16 11:44:59 +00:00
|
|
|
msg *irc.Message
|
|
|
|
uc *upstreamConn
|
|
|
|
}
|
|
|
|
|
2020-04-04 02:48:25 +00:00
|
|
|
type eventUpstreamConnectionError struct {
|
|
|
|
net *network
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2020-04-01 10:05:25 +00:00
|
|
|
type eventUpstreamConnected struct {
|
|
|
|
uc *upstreamConn
|
|
|
|
}
|
|
|
|
|
2020-03-27 23:51:58 +00:00
|
|
|
type eventUpstreamDisconnected struct {
|
|
|
|
uc *upstreamConn
|
|
|
|
}
|
|
|
|
|
2020-04-04 02:48:25 +00:00
|
|
|
type eventUpstreamError struct {
|
|
|
|
uc *upstreamConn
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
2020-03-27 15:33:19 +00:00
|
|
|
type eventDownstreamMessage struct {
|
2020-03-16 11:44:59 +00:00
|
|
|
msg *irc.Message
|
|
|
|
dc *downstreamConn
|
|
|
|
}
|
|
|
|
|
2020-03-27 16:21:05 +00:00
|
|
|
type eventDownstreamConnected struct {
|
|
|
|
dc *downstreamConn
|
|
|
|
}
|
|
|
|
|
2020-03-27 16:55:03 +00:00
|
|
|
type eventDownstreamDisconnected struct {
|
|
|
|
dc *downstreamConn
|
|
|
|
}
|
|
|
|
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
type eventChannelDetach struct {
|
|
|
|
uc *upstreamConn
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
2020-08-03 16:45:13 +00:00
|
|
|
type eventStop struct{}
|
|
|
|
|
2021-03-26 10:19:58 +00:00
|
|
|
type deliveredClientMap map[string]string // client name -> msg ID
|
|
|
|
|
2021-03-29 15:49:50 +00:00
|
|
|
type deliveredStore struct {
|
|
|
|
m deliveredCasemapMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDeliveredStore() deliveredStore {
|
|
|
|
return deliveredStore{deliveredCasemapMap{newCasemapMap(0)}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ds deliveredStore) HasTarget(target string) bool {
|
|
|
|
return ds.m.Value(target) != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ds deliveredStore) LoadID(target, clientName string) string {
|
|
|
|
clients := ds.m.Value(target)
|
|
|
|
if clients == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return clients[clientName]
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ds deliveredStore) StoreID(target, clientName, msgID string) {
|
|
|
|
clients := ds.m.Value(target)
|
|
|
|
if clients == nil {
|
|
|
|
clients = make(deliveredClientMap)
|
|
|
|
ds.m.SetValue(target, clients)
|
|
|
|
}
|
|
|
|
clients[clientName] = msgID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ds deliveredStore) ForEachTarget(f func(target string)) {
|
|
|
|
for _, entry := range ds.m.innerMap {
|
|
|
|
f(entry.originalKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 17:16:08 +00:00
|
|
|
func (ds deliveredStore) ForEachClient(f func(clientName string)) {
|
|
|
|
clients := make(map[string]struct{})
|
|
|
|
for _, entry := range ds.m.innerMap {
|
|
|
|
delivered := entry.value.(deliveredClientMap)
|
|
|
|
for clientName := range delivered {
|
|
|
|
clients[clientName] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for clientName := range clients {
|
|
|
|
f(clientName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
type network struct {
|
|
|
|
Network
|
2020-04-01 13:40:20 +00:00
|
|
|
user *user
|
|
|
|
stopped chan struct{}
|
2020-03-20 21:48:17 +00:00
|
|
|
|
2021-03-29 14:55:57 +00:00
|
|
|
conn *upstreamConn
|
|
|
|
channels channelCasemapMap
|
2021-03-29 15:49:50 +00:00
|
|
|
delivered deliveredStore
|
2021-03-29 14:55:57 +00:00
|
|
|
lastError error
|
|
|
|
casemap casemapping
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
|
2020-04-11 15:00:40 +00:00
|
|
|
func newNetwork(user *user, record *Network, channels []Channel) *network {
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
m := channelCasemapMap{newCasemapMap(0)}
|
2020-04-11 15:00:40 +00:00
|
|
|
for _, ch := range channels {
|
2020-05-01 00:02:41 +00:00
|
|
|
ch := ch
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
m.SetValue(ch.Name, &ch)
|
2020-04-11 15:00:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
return &network{
|
2021-03-29 14:55:57 +00:00
|
|
|
Network: *record,
|
|
|
|
user: user,
|
|
|
|
stopped: make(chan struct{}),
|
|
|
|
channels: m,
|
2021-03-29 15:49:50 +00:00
|
|
|
delivered: newDeliveredStore(),
|
2021-03-29 14:55:57 +00:00
|
|
|
casemap: casemapRFC1459,
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-04 02:48:25 +00:00
|
|
|
func (net *network) forEachDownstream(f func(*downstreamConn)) {
|
|
|
|
net.user.forEachDownstream(func(dc *downstreamConn) {
|
|
|
|
if dc.network != nil && dc.network != net {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
f(dc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-03 15:28:31 +00:00
|
|
|
func (net *network) isStopped() bool {
|
|
|
|
select {
|
|
|
|
case <-net.stopped:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 08:36:14 +00:00
|
|
|
func userIdent(u *User) string {
|
|
|
|
// The ident is a string we will send to upstream servers in clear-text.
|
|
|
|
// For privacy reasons, make sure it doesn't expose any meaningful user
|
|
|
|
// metadata. We just use the base64-encoded hashed ID, so that people don't
|
|
|
|
// start relying on the string being an integer or following a pattern.
|
|
|
|
var b [64]byte
|
|
|
|
binary.LittleEndian.PutUint64(b[:], uint64(u.ID))
|
|
|
|
h := sha256.Sum256(b[:])
|
2020-08-19 09:24:25 +00:00
|
|
|
return hex.EncodeToString(h[:16])
|
2020-08-11 08:36:14 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
func (net *network) run() {
|
|
|
|
var lastTry time.Time
|
|
|
|
for {
|
2020-06-03 15:28:31 +00:00
|
|
|
if net.isStopped() {
|
2020-04-01 13:40:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-08-19 17:28:29 +00:00
|
|
|
if dur := time.Now().Sub(lastTry); dur < retryConnectDelay {
|
|
|
|
delay := retryConnectDelay - dur
|
2020-03-16 10:18:41 +00:00
|
|
|
net.user.srv.Logger.Printf("waiting %v before trying to reconnect to %q", delay.Truncate(time.Second), net.Addr)
|
|
|
|
time.Sleep(delay)
|
|
|
|
}
|
|
|
|
lastTry = time.Now()
|
|
|
|
|
|
|
|
uc, err := connectToUpstream(net)
|
|
|
|
if err != nil {
|
|
|
|
net.user.srv.Logger.Printf("failed to connect to upstream server %q: %v", net.Addr, err)
|
2020-04-04 02:48:25 +00:00
|
|
|
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to connect: %v", err)}
|
2020-03-16 10:18:41 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-08-11 08:36:14 +00:00
|
|
|
if net.user.srv.Identd != nil {
|
|
|
|
net.user.srv.Identd.Store(uc.RemoteAddr().String(), uc.LocalAddr().String(), userIdent(&net.user.User))
|
|
|
|
}
|
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
uc.register()
|
2020-04-01 10:14:36 +00:00
|
|
|
if err := uc.runUntilRegistered(); err != nil {
|
2020-08-19 21:35:12 +00:00
|
|
|
text := err.Error()
|
|
|
|
if regErr, ok := err.(registrationError); ok {
|
|
|
|
text = string(regErr)
|
|
|
|
}
|
|
|
|
uc.logger.Printf("failed to register: %v", text)
|
|
|
|
net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to register: %v", text)}
|
2020-04-01 10:14:36 +00:00
|
|
|
uc.Close()
|
|
|
|
continue
|
|
|
|
}
|
2020-03-16 10:18:41 +00:00
|
|
|
|
2020-06-03 15:28:31 +00:00
|
|
|
// TODO: this is racy with net.stopped. If the network is stopped
|
|
|
|
// before the user goroutine receives eventUpstreamConnected, the
|
|
|
|
// connection won't be closed.
|
2020-04-01 10:05:25 +00:00
|
|
|
net.user.events <- eventUpstreamConnected{uc}
|
2020-03-27 15:33:19 +00:00
|
|
|
if err := uc.readMessages(net.user.events); err != nil {
|
2020-03-16 10:18:41 +00:00
|
|
|
uc.logger.Printf("failed to handle messages: %v", err)
|
2020-04-04 02:48:25 +00:00
|
|
|
net.user.events <- eventUpstreamError{uc, fmt.Errorf("failed to handle messages: %v", err)}
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
uc.Close()
|
2020-03-27 23:51:58 +00:00
|
|
|
net.user.events <- eventUpstreamDisconnected{uc}
|
2020-08-11 08:36:14 +00:00
|
|
|
|
|
|
|
if net.user.srv.Identd != nil {
|
|
|
|
net.user.srv.Identd.Delete(uc.RemoteAddr().String(), uc.LocalAddr().String())
|
|
|
|
}
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 14:18:56 +00:00
|
|
|
func (net *network) stop() {
|
2020-06-03 15:28:31 +00:00
|
|
|
if !net.isStopped() {
|
2020-04-01 13:40:20 +00:00
|
|
|
close(net.stopped)
|
|
|
|
}
|
|
|
|
|
2020-04-30 08:25:16 +00:00
|
|
|
if net.conn != nil {
|
|
|
|
net.conn.Close()
|
2020-04-01 13:40:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
func (net *network) detach(ch *Channel) {
|
|
|
|
if ch.Detached {
|
|
|
|
return
|
2020-04-11 15:00:40 +00:00
|
|
|
}
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
ch.Detached = true
|
|
|
|
net.user.srv.Logger.Printf("network %q: detaching channel %q", net.GetName(), ch.Name)
|
|
|
|
|
|
|
|
if net.conn != nil {
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
uch := net.conn.channels.Value(ch.Name)
|
|
|
|
if uch != nil {
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
uch.updateAutoDetach(0)
|
|
|
|
}
|
2020-04-05 13:04:52 +00:00
|
|
|
}
|
2020-04-28 13:27:41 +00:00
|
|
|
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
net.forEachDownstream(func(dc *downstreamConn) {
|
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.prefix(),
|
|
|
|
Command: "PART",
|
|
|
|
Params: []string{dc.marshalEntity(net, ch.Name), "Detach"},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2020-04-28 13:27:41 +00:00
|
|
|
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
func (net *network) attach(ch *Channel) {
|
|
|
|
if !ch.Detached {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ch.Detached = false
|
|
|
|
net.user.srv.Logger.Printf("network %q: attaching channel %q", net.GetName(), ch.Name)
|
2020-04-28 13:27:41 +00:00
|
|
|
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
var uch *upstreamChannel
|
|
|
|
if net.conn != nil {
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
uch = net.conn.channels.Value(ch.Name)
|
2020-04-28 13:27:41 +00:00
|
|
|
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
net.conn.updateChannelAutoDetach(ch.Name)
|
2020-04-28 13:27:41 +00:00
|
|
|
}
|
|
|
|
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
net.forEachDownstream(func(dc *downstreamConn) {
|
|
|
|
dc.SendMessage(&irc.Message{
|
|
|
|
Prefix: dc.prefix(),
|
|
|
|
Command: "JOIN",
|
|
|
|
Params: []string{dc.marshalEntity(net, ch.Name)},
|
|
|
|
})
|
|
|
|
|
|
|
|
if uch != nil {
|
|
|
|
forwardChannel(dc, uch)
|
|
|
|
}
|
|
|
|
|
2021-02-10 12:50:10 +00:00
|
|
|
dc.sendTargetBacklog(net, ch.Name)
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
})
|
2020-04-05 13:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (net *network) deleteChannel(name string) error {
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
ch := net.channels.Value(name)
|
|
|
|
if ch == nil {
|
2020-09-06 15:00:42 +00:00
|
|
|
return fmt.Errorf("unknown channel %q", name)
|
|
|
|
}
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
if net.conn != nil {
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
uch := net.conn.channels.Value(ch.Name)
|
|
|
|
if uch != nil {
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
uch.updateAutoDetach(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-06 15:00:42 +00:00
|
|
|
if err := net.user.srv.db.DeleteChannel(ch.ID); err != nil {
|
2020-04-11 15:00:40 +00:00
|
|
|
return err
|
|
|
|
}
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
net.channels.Delete(name)
|
2020-04-11 15:00:40 +00:00
|
|
|
return nil
|
2020-04-05 13:04:52 +00:00
|
|
|
}
|
|
|
|
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
func (net *network) updateCasemapping(newCasemap casemapping) {
|
|
|
|
net.casemap = newCasemap
|
|
|
|
net.channels.SetCasemapping(newCasemap)
|
2021-03-29 15:49:50 +00:00
|
|
|
net.delivered.m.SetCasemapping(newCasemap)
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
if net.conn != nil {
|
|
|
|
net.conn.channels.SetCasemapping(newCasemap)
|
|
|
|
for _, entry := range net.conn.channels.innerMap {
|
|
|
|
uch := entry.value.(*upstreamChannel)
|
|
|
|
uch.Members.SetCasemapping(newCasemap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 17:16:08 +00:00
|
|
|
func (net *network) storeClientDeliveryReceipts(clientName string) {
|
|
|
|
if !net.user.hasPersistentMsgStore() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var receipts []DeliveryReceipt
|
|
|
|
net.delivered.ForEachTarget(func(target string) {
|
|
|
|
msgID := net.delivered.LoadID(target, clientName)
|
|
|
|
if msgID == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
receipts = append(receipts, DeliveryReceipt{
|
|
|
|
Target: target,
|
|
|
|
InternalMsgID: msgID,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
if err := net.user.srv.db.StoreClientDeliveryReceipts(net.ID, clientName, receipts); err != nil {
|
|
|
|
net.user.srv.Logger.Printf("failed to store delivery receipts for user %q, client %q, network %q: %v", net.user.Username, clientName, net.GetName(), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
type user struct {
|
|
|
|
User
|
|
|
|
srv *Server
|
|
|
|
|
2020-03-27 15:33:19 +00:00
|
|
|
events chan event
|
2020-08-07 13:30:05 +00:00
|
|
|
done chan struct{}
|
2020-03-16 11:44:59 +00:00
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
networks []*network
|
|
|
|
downstreamConns []*downstreamConn
|
2021-01-04 13:24:00 +00:00
|
|
|
msgStore messageStore
|
Add LIST support
This commit adds support for downstream LIST messages from multiple
concurrent downstreams to multiple concurrent upstreams, including
support for multiple pending LIST requests from the same downstream.
Because a unique RPL_LISTEND message must be sent to the requesting
downstream, and that there might be multiple upstreams, each sending
their own RPL_LISTEND, a cache of RPL_LISTEND replies of some sort is
required to match RPL_LISTEND together in order to only send one back
downstream.
This commit adds a list of "pending LIST" structs, which each contain a
map of all upstreams that yet need to send a RPL_LISTEND, and the
corresponding LIST request associated with that response. This list of
pending LISTs is sorted according to the order that the requesting
downstreams sent the LIST messages in. Each pending set also stores the
id of the requesting downstream, in order to only forward the replies to
it and no other downstream. (This is important because LIST replies can
typically amount to several thousands messages on large servers.)
When a single downstream makes multiple LIST requests, only the first
one will be immediately sent to the upstream servers. The next ones will
be buffered until the first one is completed. Distinct downstreams can
make concurrent LIST requests without any request buffering.
Each RPL_LIST message is forwarded to the downstream of the first
matching pending LIST struct.
When an upstream sends an RPL_LISTEND message, the upstream is removed
from the first matching pending LIST struct, but that message is not
immediately forwarded downstream. If there are no remaining pending LIST
requests in that struct is then empty, that means all upstreams have
sent back all their RPL_LISTEND replies (which means they also sent all
their RPL_LIST replies); so a unique RPL_LISTEND is sent to downstream
and that pending LIST set is removed from the cache.
Upstreams are removed from the pending LIST structs in two other cases:
- when they are closed (to avoid stalling because of a disconnected
upstream that will never reply to the LIST message): they are removed
from all pending LIST structs
- when they reply with an ERR_UNKNOWNCOMMAND or RPL_TRYAGAIN LIST reply,
which is typically used when a user is not allowed to LIST because they
just joined the server: they are removed from the first pending LIST
struct, as if an RPL_LISTEND message was received
2020-03-26 01:40:30 +00:00
|
|
|
|
|
|
|
// LIST commands in progress
|
2020-03-27 23:51:58 +00:00
|
|
|
pendingLISTs []pendingLIST
|
Add LIST support
This commit adds support for downstream LIST messages from multiple
concurrent downstreams to multiple concurrent upstreams, including
support for multiple pending LIST requests from the same downstream.
Because a unique RPL_LISTEND message must be sent to the requesting
downstream, and that there might be multiple upstreams, each sending
their own RPL_LISTEND, a cache of RPL_LISTEND replies of some sort is
required to match RPL_LISTEND together in order to only send one back
downstream.
This commit adds a list of "pending LIST" structs, which each contain a
map of all upstreams that yet need to send a RPL_LISTEND, and the
corresponding LIST request associated with that response. This list of
pending LISTs is sorted according to the order that the requesting
downstreams sent the LIST messages in. Each pending set also stores the
id of the requesting downstream, in order to only forward the replies to
it and no other downstream. (This is important because LIST replies can
typically amount to several thousands messages on large servers.)
When a single downstream makes multiple LIST requests, only the first
one will be immediately sent to the upstream servers. The next ones will
be buffered until the first one is completed. Distinct downstreams can
make concurrent LIST requests without any request buffering.
Each RPL_LIST message is forwarded to the downstream of the first
matching pending LIST struct.
When an upstream sends an RPL_LISTEND message, the upstream is removed
from the first matching pending LIST struct, but that message is not
immediately forwarded downstream. If there are no remaining pending LIST
requests in that struct is then empty, that means all upstreams have
sent back all their RPL_LISTEND replies (which means they also sent all
their RPL_LIST replies); so a unique RPL_LISTEND is sent to downstream
and that pending LIST set is removed from the cache.
Upstreams are removed from the pending LIST structs in two other cases:
- when they are closed (to avoid stalling because of a disconnected
upstream that will never reply to the LIST message): they are removed
from all pending LIST structs
- when they reply with an ERR_UNKNOWNCOMMAND or RPL_TRYAGAIN LIST reply,
which is typically used when a user is not allowed to LIST because they
just joined the server: they are removed from the first pending LIST
struct, as if an RPL_LISTEND message was received
2020-03-26 01:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type pendingLIST struct {
|
|
|
|
downstreamID uint64
|
|
|
|
// list of per-upstream LIST commands not yet sent or completed
|
|
|
|
pendingCommands map[int64]*irc.Message
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newUser(srv *Server, record *User) *user {
|
2021-01-04 13:24:00 +00:00
|
|
|
var msgStore messageStore
|
2020-10-25 10:13:51 +00:00
|
|
|
if srv.LogPath != "" {
|
2021-01-04 13:24:00 +00:00
|
|
|
msgStore = newFSMessageStore(srv.LogPath, record.Username)
|
2021-01-04 16:18:30 +00:00
|
|
|
} else {
|
|
|
|
msgStore = newMemoryMessageStore()
|
2020-10-25 10:13:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
return &user{
|
2021-02-10 17:16:08 +00:00
|
|
|
User: *record,
|
|
|
|
srv: srv,
|
|
|
|
events: make(chan event, 64),
|
|
|
|
done: make(chan struct{}),
|
|
|
|
msgStore: msgStore,
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *user) forEachNetwork(f func(*network)) {
|
|
|
|
for _, network := range u.networks {
|
|
|
|
f(network)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *user) forEachUpstream(f func(uc *upstreamConn)) {
|
|
|
|
for _, network := range u.networks {
|
2020-04-30 08:25:16 +00:00
|
|
|
if network.conn == nil {
|
2020-03-16 10:18:41 +00:00
|
|
|
continue
|
|
|
|
}
|
2020-04-30 08:25:16 +00:00
|
|
|
f(network.conn)
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *user) forEachDownstream(f func(dc *downstreamConn)) {
|
|
|
|
for _, dc := range u.downstreamConns {
|
|
|
|
f(dc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *user) getNetwork(name string) *network {
|
|
|
|
for _, network := range u.networks {
|
|
|
|
if network.Addr == name {
|
|
|
|
return network
|
|
|
|
}
|
2020-04-01 13:02:59 +00:00
|
|
|
if network.Name != "" && network.Name == name {
|
|
|
|
return network
|
|
|
|
}
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
func (u *user) getNetworkByID(id int64) *network {
|
|
|
|
for _, net := range u.networks {
|
|
|
|
if net.ID == id {
|
|
|
|
return net
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
func (u *user) run() {
|
2020-10-25 10:13:51 +00:00
|
|
|
defer func() {
|
|
|
|
if u.msgStore != nil {
|
|
|
|
if err := u.msgStore.Close(); err != nil {
|
|
|
|
u.srv.Logger.Printf("failed to close message store for user %q: %v", u.Username, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(u.done)
|
|
|
|
}()
|
2020-08-07 13:30:05 +00:00
|
|
|
|
2020-10-24 13:14:23 +00:00
|
|
|
networks, err := u.srv.db.ListNetworks(u.ID)
|
2020-03-16 10:18:41 +00:00
|
|
|
if err != nil {
|
|
|
|
u.srv.Logger.Printf("failed to list networks for user %q: %v", u.Username, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, record := range networks {
|
2020-05-01 00:02:41 +00:00
|
|
|
record := record
|
2020-04-11 15:00:40 +00:00
|
|
|
channels, err := u.srv.db.ListChannels(record.ID)
|
|
|
|
if err != nil {
|
|
|
|
u.srv.Logger.Printf("failed to list channels for user %q, network %q: %v", u.Username, record.GetName(), err)
|
2020-07-09 12:20:23 +00:00
|
|
|
continue
|
2020-04-11 15:00:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
network := newNetwork(u, &record, channels)
|
2020-03-16 10:18:41 +00:00
|
|
|
u.networks = append(u.networks, network)
|
|
|
|
|
2021-02-10 17:16:08 +00:00
|
|
|
if u.hasPersistentMsgStore() {
|
|
|
|
receipts, err := u.srv.db.ListDeliveryReceipts(record.ID)
|
|
|
|
if err != nil {
|
|
|
|
u.srv.Logger.Printf("failed to load delivery receipts for user %q, network %q: %v", u.Username, network.GetName(), err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, rcpt := range receipts {
|
|
|
|
network.delivered.StoreID(rcpt.Target, rcpt.Client, rcpt.InternalMsgID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
go network.run()
|
|
|
|
}
|
2020-03-16 11:44:59 +00:00
|
|
|
|
2020-03-27 15:33:19 +00:00
|
|
|
for e := range u.events {
|
|
|
|
switch e := e.(type) {
|
2020-04-01 10:05:25 +00:00
|
|
|
case eventUpstreamConnected:
|
2020-04-01 10:16:32 +00:00
|
|
|
uc := e.uc
|
2020-04-01 10:21:31 +00:00
|
|
|
|
|
|
|
uc.network.conn = uc
|
|
|
|
|
2020-04-01 10:16:32 +00:00
|
|
|
uc.updateAway()
|
2020-04-04 02:48:25 +00:00
|
|
|
|
|
|
|
uc.forEachDownstream(func(dc *downstreamConn) {
|
2020-04-29 14:28:33 +00:00
|
|
|
dc.updateSupportedCaps()
|
2020-04-05 13:15:42 +00:00
|
|
|
sendServiceNOTICE(dc, fmt.Sprintf("connected to %s", uc.network.GetName()))
|
2020-04-30 22:37:42 +00:00
|
|
|
|
|
|
|
dc.updateNick()
|
2020-04-04 02:48:25 +00:00
|
|
|
})
|
|
|
|
uc.network.lastError = nil
|
2020-03-27 23:51:58 +00:00
|
|
|
case eventUpstreamDisconnected:
|
2020-06-02 09:39:53 +00:00
|
|
|
u.handleUpstreamDisconnected(e.uc)
|
2020-04-04 02:48:25 +00:00
|
|
|
case eventUpstreamConnectionError:
|
|
|
|
net := e.net
|
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
stopped := false
|
|
|
|
select {
|
|
|
|
case <-net.stopped:
|
|
|
|
stopped = true
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
if !stopped && (net.lastError == nil || net.lastError.Error() != e.err.Error()) {
|
2020-04-04 02:48:25 +00:00
|
|
|
net.forEachDownstream(func(dc *downstreamConn) {
|
2020-04-05 13:15:42 +00:00
|
|
|
sendServiceNOTICE(dc, fmt.Sprintf("failed connecting/registering to %s: %v", net.GetName(), e.err))
|
2020-04-04 02:48:25 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
net.lastError = e.err
|
|
|
|
case eventUpstreamError:
|
|
|
|
uc := e.uc
|
|
|
|
|
|
|
|
uc.forEachDownstream(func(dc *downstreamConn) {
|
2020-04-05 13:15:42 +00:00
|
|
|
sendServiceNOTICE(dc, fmt.Sprintf("disconnected from %s: %v", uc.network.GetName(), e.err))
|
2020-04-04 02:48:25 +00:00
|
|
|
})
|
|
|
|
uc.network.lastError = e.err
|
2020-03-27 15:33:19 +00:00
|
|
|
case eventUpstreamMessage:
|
|
|
|
msg, uc := e.msg, e.uc
|
2020-03-27 22:08:35 +00:00
|
|
|
if uc.isClosed() {
|
2020-03-21 07:29:44 +00:00
|
|
|
uc.logger.Printf("ignoring message on closed connection: %v", msg)
|
|
|
|
break
|
|
|
|
}
|
2020-03-16 11:44:59 +00:00
|
|
|
if err := uc.handleMessage(msg); err != nil {
|
|
|
|
uc.logger.Printf("failed to handle message %q: %v", msg, err)
|
|
|
|
}
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
case eventChannelDetach:
|
|
|
|
uc, name := e.uc, e.name
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
c := uc.network.channels.Value(name)
|
|
|
|
if c == nil || c.Detached {
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
uc.network.detach(c)
|
|
|
|
if err := uc.srv.db.StoreChannel(uc.network.ID, c); err != nil {
|
|
|
|
u.srv.Logger.Printf("failed to store updated detached channel %q: %v", c.Name, err)
|
|
|
|
}
|
2020-03-27 16:21:05 +00:00
|
|
|
case eventDownstreamConnected:
|
|
|
|
dc := e.dc
|
2020-03-27 18:17:58 +00:00
|
|
|
|
|
|
|
if err := dc.welcome(); err != nil {
|
|
|
|
dc.logger.Printf("failed to handle new registered connection: %v", err)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-03-27 16:21:05 +00:00
|
|
|
u.downstreamConns = append(u.downstreamConns, dc)
|
2020-04-01 10:16:32 +00:00
|
|
|
|
2021-03-16 08:41:07 +00:00
|
|
|
dc.forEachNetwork(func(network *network) {
|
|
|
|
if network.lastError != nil {
|
|
|
|
sendServiceNOTICE(dc, fmt.Sprintf("disconnected from %s: %v", network.GetName(), network.lastError))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-04-01 10:16:32 +00:00
|
|
|
u.forEachUpstream(func(uc *upstreamConn) {
|
|
|
|
uc.updateAway()
|
|
|
|
})
|
2020-03-27 16:55:03 +00:00
|
|
|
case eventDownstreamDisconnected:
|
|
|
|
dc := e.dc
|
2020-04-01 14:02:31 +00:00
|
|
|
|
2020-03-27 16:55:03 +00:00
|
|
|
for i := range u.downstreamConns {
|
|
|
|
if u.downstreamConns[i] == dc {
|
|
|
|
u.downstreamConns = append(u.downstreamConns[:i], u.downstreamConns[i+1:]...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2020-04-01 10:16:32 +00:00
|
|
|
|
2021-02-10 17:16:08 +00:00
|
|
|
dc.forEachNetwork(func(net *network) {
|
|
|
|
net.storeClientDeliveryReceipts(dc.clientName)
|
|
|
|
})
|
|
|
|
|
2020-04-01 10:16:32 +00:00
|
|
|
u.forEachUpstream(func(uc *upstreamConn) {
|
|
|
|
uc.updateAway()
|
|
|
|
})
|
2020-03-27 15:33:19 +00:00
|
|
|
case eventDownstreamMessage:
|
|
|
|
msg, dc := e.msg, e.dc
|
2020-03-21 07:29:44 +00:00
|
|
|
if dc.isClosed() {
|
|
|
|
dc.logger.Printf("ignoring message on closed connection: %v", msg)
|
|
|
|
break
|
|
|
|
}
|
2020-03-16 11:44:59 +00:00
|
|
|
err := dc.handleMessage(msg)
|
|
|
|
if ircErr, ok := err.(ircError); ok {
|
|
|
|
ircErr.Message.Prefix = dc.srv.prefix()
|
|
|
|
dc.SendMessage(ircErr.Message)
|
|
|
|
} else if err != nil {
|
|
|
|
dc.logger.Printf("failed to handle message %q: %v", msg, err)
|
|
|
|
dc.Close()
|
|
|
|
}
|
2020-08-03 16:45:13 +00:00
|
|
|
case eventStop:
|
|
|
|
u.forEachDownstream(func(dc *downstreamConn) {
|
|
|
|
dc.Close()
|
|
|
|
})
|
|
|
|
for _, n := range u.networks {
|
|
|
|
n.stop()
|
2021-02-10 17:16:08 +00:00
|
|
|
|
|
|
|
n.delivered.ForEachClient(func(clientName string) {
|
|
|
|
n.storeClientDeliveryReceipts(clientName)
|
|
|
|
})
|
2020-08-03 16:45:13 +00:00
|
|
|
}
|
|
|
|
return
|
2020-03-27 15:33:19 +00:00
|
|
|
default:
|
|
|
|
u.srv.Logger.Printf("received unknown event type: %T", e)
|
2020-03-16 11:44:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-16 10:18:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
func (u *user) handleUpstreamDisconnected(uc *upstreamConn) {
|
|
|
|
uc.network.conn = nil
|
|
|
|
|
|
|
|
uc.endPendingLISTs(true)
|
|
|
|
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
for _, entry := range uc.channels.innerMap {
|
|
|
|
uch := entry.value.(*upstreamChannel)
|
Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.
The `FilterDefault` values of the messages filters are currently
hardcoded.
The values of the message filters are not currently user-settable.
This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).
2020-11-30 21:08:33 +00:00
|
|
|
uch.updateAutoDetach(0)
|
|
|
|
}
|
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
uc.forEachDownstream(func(dc *downstreamConn) {
|
|
|
|
dc.updateSupportedCaps()
|
|
|
|
})
|
|
|
|
|
|
|
|
if uc.network.lastError == nil {
|
|
|
|
uc.forEachDownstream(func(dc *downstreamConn) {
|
|
|
|
sendServiceNOTICE(dc, fmt.Sprintf("disconnected from %s", uc.network.GetName()))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *user) addNetwork(network *network) {
|
|
|
|
u.networks = append(u.networks, network)
|
|
|
|
go network.run()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *user) removeNetwork(network *network) {
|
|
|
|
network.stop()
|
|
|
|
|
|
|
|
u.forEachDownstream(func(dc *downstreamConn) {
|
|
|
|
if dc.network != nil && dc.network == network {
|
|
|
|
dc.Close()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
for i, net := range u.networks {
|
|
|
|
if net == network {
|
|
|
|
u.networks = append(u.networks[:i], u.networks[i+1:]...)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
panic("tried to remove a non-existing network")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *user) createNetwork(record *Network) (*network, error) {
|
|
|
|
if record.ID != 0 {
|
2020-03-25 10:28:25 +00:00
|
|
|
panic("tried creating an already-existing network")
|
|
|
|
}
|
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
network := newNetwork(u, record, nil)
|
2020-10-24 13:14:23 +00:00
|
|
|
err := u.srv.db.StoreNetwork(u.ID, &network.Network)
|
2020-03-16 10:18:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-03-25 10:28:25 +00:00
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
u.addNetwork(network)
|
2020-03-25 10:28:25 +00:00
|
|
|
|
2020-03-16 10:18:41 +00:00
|
|
|
return network, nil
|
|
|
|
}
|
2020-04-01 13:40:20 +00:00
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
func (u *user) updateNetwork(record *Network) (*network, error) {
|
|
|
|
if record.ID == 0 {
|
|
|
|
panic("tried updating a new network")
|
|
|
|
}
|
|
|
|
|
|
|
|
network := u.getNetworkByID(record.ID)
|
|
|
|
if network == nil {
|
|
|
|
panic("tried updating a non-existing network")
|
|
|
|
}
|
|
|
|
|
2020-10-24 13:14:23 +00:00
|
|
|
if err := u.srv.db.StoreNetwork(u.ID, record); err != nil {
|
2020-06-02 09:39:53 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Most network changes require us to re-connect to the upstream server
|
|
|
|
|
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)
== What is casemapping? ==
see <https://modern.ircdocs.horse/#casemapping-parameter>
== Casemapping and multi-upstream ==
Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],
1. soju must also update the database accordingly to upstreams'
casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
that is a subset of all supported casemappings (here, ascii).
[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.
Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.
downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.
Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).
== Message forwarding and casemapping ==
downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user. This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).
marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters. ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).
== Casemapping changes ==
Casemapping changes are not fully supported by this patch and will
result in loss of history. This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-16 09:00:34 +00:00
|
|
|
channels := make([]Channel, 0, network.channels.Len())
|
|
|
|
for _, entry := range network.channels.innerMap {
|
|
|
|
ch := entry.value.(*Channel)
|
2020-06-02 09:39:53 +00:00
|
|
|
channels = append(channels, *ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
updatedNetwork := newNetwork(u, record, channels)
|
2020-04-01 13:40:20 +00:00
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
// If we're currently connected, disconnect and perform the necessary
|
|
|
|
// bookkeeping
|
|
|
|
if network.conn != nil {
|
|
|
|
network.stop()
|
|
|
|
// Note: this will set network.conn to nil
|
|
|
|
u.handleUpstreamDisconnected(network.conn)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Patch downstream connections to use our fresh updated network
|
|
|
|
u.forEachDownstream(func(dc *downstreamConn) {
|
|
|
|
if dc.network != nil && dc.network == network {
|
|
|
|
dc.network = updatedNetwork
|
2020-04-01 13:40:20 +00:00
|
|
|
}
|
2020-06-02 09:39:53 +00:00
|
|
|
})
|
2020-04-01 13:40:20 +00:00
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
// We need to remove the network after patching downstream connections,
|
|
|
|
// otherwise they'll get closed
|
|
|
|
u.removeNetwork(network)
|
|
|
|
|
|
|
|
// This will re-connect to the upstream server
|
|
|
|
u.addNetwork(updatedNetwork)
|
2020-04-01 13:40:20 +00:00
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
return updatedNetwork, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *user) deleteNetwork(id int64) error {
|
|
|
|
network := u.getNetworkByID(id)
|
|
|
|
if network == nil {
|
|
|
|
panic("tried deleting a non-existing network")
|
2020-04-01 13:40:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 09:39:53 +00:00
|
|
|
if err := u.srv.db.DeleteNetwork(network.ID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
u.removeNetwork(network)
|
|
|
|
return nil
|
2020-04-01 13:40:20 +00:00
|
|
|
}
|
2020-04-08 12:20:00 +00:00
|
|
|
|
|
|
|
func (u *user) updatePassword(hashed string) error {
|
|
|
|
u.User.Password = hashed
|
2020-06-08 09:59:03 +00:00
|
|
|
return u.srv.db.StoreUser(&u.User)
|
2020-04-08 12:20:00 +00:00
|
|
|
}
|
2020-08-03 16:45:13 +00:00
|
|
|
|
|
|
|
func (u *user) stop() {
|
|
|
|
u.events <- eventStop{}
|
2020-08-07 13:30:05 +00:00
|
|
|
<-u.done
|
2020-08-03 16:45:13 +00:00
|
|
|
}
|
2021-02-10 17:16:08 +00:00
|
|
|
|
|
|
|
func (u *user) hasPersistentMsgStore() bool {
|
|
|
|
if u.msgStore == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
_, isMem := u.msgStore.(*memoryMessageStore)
|
|
|
|
return !isMem
|
|
|
|
}
|