dd
This commit is contained in:
1 parent
4300a32f6b
commit
8c98346546
3 files changed
+19
-28
No files matched your search
+6
-2
@@ -26,7 +26,11 @@ type Broker struct {
|
|||||||
remotes sync.Map
|
remotes sync.Map
|
||||||
sl *Sublist
|
sl *Sublist
|
||||||
rl *RetainList
|
rl *RetainList
|
||||||
queues map[string]int
|
queues map[string]Queue
|
||||||
|
}
|
||||||
|
type Queue struct {
|
||||||
|
count int
|
||||||
|
index int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBroker(config *Config) (*Broker, error) {
|
func NewBroker(config *Config) (*Broker, error) {
|
||||||
@@ -35,7 +39,7 @@ func NewBroker(config *Config) (*Broker, error) {
|
|||||||
config: config,
|
config: config,
|
||||||
sl: NewSublist(),
|
sl: NewSublist(),
|
||||||
rl: NewRetainList(),
|
rl: NewRetainList(),
|
||||||
queues: make(map[string]int),
|
queues: make(map[string]Queue),
|
||||||
}
|
}
|
||||||
if b.config.TlsPort != "" {
|
if b.config.TlsPort != "" {
|
||||||
tlsconfig, err := NewTLSConfig(b.config.TlsInfo)
|
tlsconfig, err := NewTLSConfig(b.config.TlsInfo)
|
||||||
|
|||||||
+13
-26
@@ -221,7 +221,10 @@ func (c *client) ProcessPublishMessage(packet *packets.PublishPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qnum := 0
|
idx, exist := b.queues[topic]
|
||||||
|
if exist {
|
||||||
|
|
||||||
|
}
|
||||||
for _, sub := range r.qsubs {
|
for _, sub := range r.qsubs {
|
||||||
if sub.client.typ == ROUTER {
|
if sub.client.typ == ROUTER {
|
||||||
if typ == ROUTER {
|
if typ == ROUTER {
|
||||||
@@ -234,31 +237,6 @@ func (c *client) ProcessPublishMessage(packet *packets.PublishPacket) {
|
|||||||
qnum = qnum + sub.client.rsubs[topic].num
|
qnum = qnum + sub.client.rsubs[topic].num
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var qsub *subscription
|
|
||||||
min := 0
|
|
||||||
max := 0
|
|
||||||
if cnt, exist := b.queues[topic]; exist {
|
|
||||||
for i, sub := range r.qsubs {
|
|
||||||
if sub.client.typ == ROUTER {
|
|
||||||
if typ == ROUTER {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if sub.client.typ == CLIENT {
|
|
||||||
max = max + 1
|
|
||||||
} else {
|
|
||||||
max = max + sub.client.rsubs[topic].num
|
|
||||||
}
|
|
||||||
|
|
||||||
if cnt >= min && cnt <= max {
|
|
||||||
qsub = r.qsubs[i]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
min = max
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
b.queues[topic] = (b.queues[topic] + 1) % qnum
|
|
||||||
|
|
||||||
if qsub != nil {
|
if qsub != nil {
|
||||||
err := qsub.client.WriterPacket(packet)
|
err := qsub.client.WriterPacket(packet)
|
||||||
@@ -294,6 +272,12 @@ func (c *client) ProcessSubscribe(packet *packets.SubscribePacket) {
|
|||||||
if queue {
|
if queue {
|
||||||
if len(t) > 7 {
|
if len(t) > 7 {
|
||||||
t = t[7:]
|
t = t[7:]
|
||||||
|
if _, exists := b.queues[topic]; !exists {
|
||||||
|
b.queues[topic] = Queue{
|
||||||
|
count: 0,
|
||||||
|
index: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
retcodes = append(retcodes, QosFailure)
|
retcodes = append(retcodes, QosFailure)
|
||||||
continue
|
continue
|
||||||
@@ -309,6 +293,7 @@ func (c *client) ProcessSubscribe(packet *packets.SubscribePacket) {
|
|||||||
case CLIENT:
|
case CLIENT:
|
||||||
if _, exist := c.subs[topic]; !exist {
|
if _, exist := c.subs[topic]; !exist {
|
||||||
c.subs[topic] = sub
|
c.subs[topic] = sub
|
||||||
|
b.queues[topic].count++
|
||||||
} else {
|
} else {
|
||||||
//if exist ,check whether qos change
|
//if exist ,check whether qos change
|
||||||
c.subs[topic].qos = qoss[i]
|
c.subs[topic].qos = qoss[i]
|
||||||
@@ -319,9 +304,11 @@ func (c *client) ProcessSubscribe(packet *packets.SubscribePacket) {
|
|||||||
if subinfo, exist := c.rsubs[topic]; !exist {
|
if subinfo, exist := c.rsubs[topic]; !exist {
|
||||||
sinfo := &subInfo{sub: sub, num: 1}
|
sinfo := &subInfo{sub: sub, num: 1}
|
||||||
c.rsubs[topic] = sinfo
|
c.rsubs[topic] = sinfo
|
||||||
|
b.queues[topic].count++
|
||||||
} else {
|
} else {
|
||||||
subinfo.num = subinfo.num + 1
|
subinfo.num = subinfo.num + 1
|
||||||
retcodes = append(retcodes, qoss[i])
|
retcodes = append(retcodes, qoss[i])
|
||||||
|
b.queues[topic].count++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user