Changeset 155 in code
- Timestamp:
- Mar 25, 2020, 10:20:56 PM (5 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/irc.go
r153 r155 199 199 Params []string 200 200 Outer *batch // if not-nil, this batch is nested in Outer 201 } 201 Label string 202 } -
trunk/upstream.go
r153 r155 4 4 "crypto/tls" 5 5 "encoding/base64" 6 "errors" 6 7 "fmt" 7 8 "io" … … 52 53 batches map[string]batch 53 54 54 tagsSupported bool 55 tagsSupported bool 56 labelsSupported bool 57 nextLabelId uint64 55 58 56 59 saslClient sasl.Client … … 128 131 } 129 132 133 func (uc *upstreamConn) forEachDownstreamById(id uint64, f func(*downstreamConn)) { 134 uc.forEachDownstream(func(dc *downstreamConn) { 135 if id != 0 && id != dc.id { 136 return 137 } 138 f(dc) 139 }) 140 } 141 130 142 func (uc *upstreamConn) getChannel(name string) (*upstreamChannel, error) { 131 143 ch, ok := uc.channels[name] … … 153 165 154 166 func (uc *upstreamConn) handleMessage(msg *irc.Message) error { 167 var label string 168 if l, ok := msg.GetTag("label"); ok { 169 label = l 170 } 171 155 172 var msgBatch *batch 156 173 if batchName, ok := msg.GetTag("batch"); ok { … … 160 177 } 161 178 msgBatch = &b 179 if label == "" { 180 label = msgBatch.Label 181 } 182 } 183 184 var downstreamId uint64 = 0 185 if label != "" { 186 var labelOffset uint64 187 n, err := fmt.Sscanf(label, "sd-%d-%d", &downstreamId, &labelOffset) 188 if err == nil && n < 2 { 189 err = errors.New("not enough arguments") 190 } 191 if err != nil { 192 return fmt.Errorf("unexpected message label: invalid downstream reference for label %q: %v", label, err) 193 } 162 194 } 163 195 … … 205 237 206 238 requestCaps := make([]string, 0, 16) 207 for _, c := range []string{"message-tags", "batch" } {239 for _, c := range []string{"message-tags", "batch", "labeled-response"} { 208 240 if _, ok := uc.caps[c]; ok { 209 241 requestCaps = append(requestCaps, c) … … 432 464 return err 433 465 } 466 label := label 467 if label == "" && msgBatch != nil { 468 label = msgBatch.Label 469 } 434 470 uc.batches[tag] = batch{ 435 471 Type: batchType, 436 472 Params: msg.Params[2:], 437 473 Outer: msgBatch, 474 Label: label, 438 475 } 439 476 } else if strings.HasPrefix(tag, "-") { … … 950 987 case "TAGMSG": 951 988 // TODO: relay to downstream connections that accept message-tags 989 case "ACK": 990 // Ignore 952 991 case irc.RPL_YOURHOST, irc.RPL_CREATED: 953 992 // Ignore … … 1048 1087 case "message-tags": 1049 1088 uc.tagsSupported = ok 1089 case "labeled-response": 1090 uc.labelsSupported = ok 1050 1091 } 1051 1092 return nil … … 1074 1115 uc.outgoing <- msg 1075 1116 } 1117 1118 func (uc *upstreamConn) SendMessageLabeled(dc *downstreamConn, msg *irc.Message) { 1119 if uc.labelsSupported { 1120 if msg.Tags == nil { 1121 msg.Tags = make(map[string]irc.TagValue) 1122 } 1123 msg.Tags["label"] = irc.TagValue(fmt.Sprintf("sd-%d-%d", dc.id, uc.nextLabelId)) 1124 uc.nextLabelId++ 1125 } 1126 uc.SendMessage(msg) 1127 }
Note:
See TracChangeset
for help on using the changeset viewer.