Changeset 435 in code for trunk/downstream.go


Ignore:
Timestamp:
Dec 14, 2020, 7:54:02 PM (4 years ago)
Author:
delthas
Message:

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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r431 r435  
    11581158                        })
    11591159
    1160                         ch := &Channel{Name: upstreamName, Key: key, Detached: false}
    1161                         if current, ok := uc.network.channels[ch.Name]; ok && key == "" {
     1160                        var ch *Channel
     1161                        var ok bool
     1162                        if ch, ok = uc.network.channels[upstreamName]; ok {
    11621163                                // Don't clear the channel key if there's one set
    11631164                                // TODO: add a way to unset the channel key
    1164                                 ch.Key = current.Key
    1165                         }
    1166                         if err := uc.network.createUpdateChannel(ch); err != nil {
     1165                                if key != "" {
     1166                                        ch.Key = key
     1167                                }
     1168                                uc.network.attach(ch)
     1169                        } else {
     1170                                ch = &Channel{
     1171                                        Name: upstreamName,
     1172                                        Key:  key,
     1173                                }
     1174                                uc.network.channels[upstreamName] = ch
     1175                        }
     1176                        if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
    11671177                                dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err)
    11681178                        }
     
    11861196
    11871197                        if strings.EqualFold(reason, "detach") {
    1188                                 ch := &Channel{Name: upstreamName, Detached: true}
    1189                                 if err := uc.network.createUpdateChannel(ch); err != nil {
    1190                                         dc.logger.Printf("failed to detach channel %q: %v", upstreamName, err)
     1198                                var ch *Channel
     1199                                var ok bool
     1200                                if ch, ok = uc.network.channels[upstreamName]; ok {
     1201                                        uc.network.detach(ch)
     1202                                } else {
     1203                                        ch = &Channel{
     1204                                                Name:     name,
     1205                                                Detached: true,
     1206                                        }
     1207                                        uc.network.channels[upstreamName] = ch
     1208                                }
     1209                                if err := dc.srv.db.StoreChannel(uc.network.ID, ch); err != nil {
     1210                                        dc.logger.Printf("failed to create or update channel %q: %v", upstreamName, err)
    11911211                                }
    11921212                        } else {
     
    16141634                        }
    16151635                        uc.produce(upstreamName, echoMsg, dc)
     1636
     1637                        uc.updateChannelAutoDetach(upstreamName)
    16161638                }
    16171639        case "NOTICE":
     
    16371659                                Params:  []string{upstreamName, unmarshaledText},
    16381660                        })
     1661
     1662                        uc.updateChannelAutoDetach(upstreamName)
    16391663                }
    16401664        case "TAGMSG":
     
    16591683                                Params:  []string{upstreamName},
    16601684                        })
     1685
     1686                        uc.updateChannelAutoDetach(upstreamName)
    16611687                }
    16621688        case "INVITE":
Note: See TracChangeset for help on using the changeset viewer.