Changeset 276 in code for trunk


Ignore:
Timestamp:
Apr 29, 2020, 5:34:44 PM (5 years ago)
Author:
contact
Message:

Add support for away-notify

This makes use of cap-notify to dynamically advertise support for
away-notify. away-notify is advertised to downstream connections if all
upstreams support it.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r275 r276  
    5454// capabilities.
    5555var permanentDownstreamCaps = map[string]string{
    56         "batch": "",
    57         "cap-notify": "",
     56        "batch":        "",
     57        "cap-notify":   "",
    5858        "echo-message": "",
    5959        "message-tags": "",
    60         "sasl": "PLAIN",
    61         "server-time": "",
     60        "sasl":         "PLAIN",
     61        "server-time":  "",
    6262}
    6363
     
    8989        logger := &prefixLogger{srv.Logger, fmt.Sprintf("downstream %q: ", netConn.RemoteAddr())}
    9090        dc := &downstreamConn{
    91                 conn: *newConn(srv, netConn, logger),
    92                 id:   id,
     91                conn:          *newConn(srv, netConn, logger),
     92                id:            id,
    9393                supportedCaps: make(map[string]string),
    94                 caps: make(map[string]bool),
     94                caps:          make(map[string]bool),
    9595        }
    9696        dc.hostname = netConn.RemoteAddr().String()
     
    459459                for k, v := range dc.supportedCaps {
    460460                        if dc.capVersion >= 302 && v != "" {
    461                                 caps = append(caps, k + "=" + v)
     461                                caps = append(caps, k+"="+v)
    462462                        } else {
    463463                                caps = append(caps, k)
     
    594594                Params:  []string{replyTo, "DEL", name},
    595595        })
     596}
     597
     598func (dc *downstreamConn) updateSupportedCaps() {
     599        awayNotifySupported := true
     600        dc.forEachUpstream(func(uc *upstreamConn) {
     601                awayNotifySupported = awayNotifySupported && uc.awayNotifySupported
     602        })
     603
     604        if awayNotifySupported {
     605                dc.setSupportedCap("away-notify", "")
     606        } else {
     607                dc.unsetSupportedCap("away-notify")
     608        }
    596609}
    597610
  • trunk/upstream.go

    r274 r276  
    4747        modes      userModes
    4848        channels   map[string]*upstreamChannel
    49         caps       map[string]string
     49        caps       map[string]string // available capabilities
    5050        batches    map[string]batch
    5151        away       bool
    5252
    53         tagsSupported   bool
    54         labelsSupported bool
    55         nextLabelID     uint64
     53        tagsSupported       bool
     54        awayNotifySupported bool
     55        labelsSupported     bool
     56        nextLabelID         uint64
    5657
    5758        saslClient  sasl.Client
     
    318319
    319320                        requestCaps := make([]string, 0, 16)
    320                         for _, c := range []string{"message-tags", "batch", "labeled-response", "server-time"} {
     321                        for _, c := range []string{"message-tags", "batch", "labeled-response", "server-time", "away-notify"} {
    321322                                if _, ok := uc.caps[c]; ok {
    322323                                        requestCaps = append(requestCaps, c)
     
    450451                uc.registered = true
    451452                uc.logger.Printf("connection registered")
     453
     454                uc.forEachDownstream(func(dc *downstreamConn) {
     455                        dc.updateSupportedCaps()
     456                })
    452457
    453458                for _, ch := range uc.network.channels {
     
    11491154                        })
    11501155                })
     1156        case "AWAY":
     1157                if msg.Prefix == nil {
     1158                        return fmt.Errorf("expected a prefix")
     1159                }
     1160
     1161                uc.forEachDownstream(func(dc *downstreamConn) {
     1162                        if !dc.caps["away-notify"] {
     1163                                return
     1164                        }
     1165                        dc.SendMessage(&irc.Message{
     1166                                Prefix:  dc.marshalUserPrefix(uc.network, msg.Prefix),
     1167                                Command: "AWAY",
     1168                                Params:  msg.Params,
     1169                        })
     1170                })
    11511171        case "TAGMSG":
    11521172                // TODO: relay to downstream connections that accept message-tags
     
    12631283
    12641284func (uc *upstreamConn) handleCapAck(name string, ok bool) error {
    1265         auth := &uc.network.SASL
    12661285        switch name {
    12671286        case "sasl":
     
    12711290                }
    12721291
     1292                auth := &uc.network.SASL
    12731293                switch auth.Mechanism {
    12741294                case "PLAIN":
     
    12871307        case "labeled-response":
    12881308                uc.labelsSupported = ok
     1309        case "away-notify":
     1310                uc.awayNotifySupported = ok
    12891311        case "batch", "server-time":
    12901312                // Nothing to do
  • trunk/user.go

    r267 r276  
    256256
    257257                        uc.forEachDownstream(func(dc *downstreamConn) {
     258                                dc.updateSupportedCaps()
    258259                                sendServiceNOTICE(dc, fmt.Sprintf("connected to %s", uc.network.GetName()))
    259260                        })
     
    271272
    272273                        uc.endPendingLISTs(true)
     274
     275                        uc.forEachDownstream(func(dc *downstreamConn) {
     276                                dc.updateSupportedCaps()
     277                        })
    273278
    274279                        if uc.network.lastError == nil {
     
    315320                                uc.updateAway()
    316321                        })
     322
     323                        dc.updateSupportedCaps()
    317324                case eventDownstreamDisconnected:
    318325                        dc := e.dc
Note: See TracChangeset for help on using the changeset viewer.