MCPcopy Create free account
hub / github.com/DOSNetwork/core / queryLoop

Method queryLoop

dosnode/dos_query_handler.go:15–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13)
14
15func (d *DosNode) queryLoop() {
16 defer d.logger.Info("[DOS] End queryLoop")
17 bufSign := make(map[string][]*vss.Signature)
18 reqSign := make(map[string]request)
19 peerMsg, _ := d.p.SubscribeMsg(50, vss.Signature{})
20 defer d.p.UnSubscribeMsg(vss.Signature{})
21 watchdog := time.NewTicker(30 * time.Minute)
22 defer watchdog.Stop()
23 for {
24 select {
25 case <-d.ctx.Done():
26 defer d.logger.Info("[DOS] End queryLoop ctx.Done")
27 return
28 case <-watchdog.C:
29 for _, req := range reqSign {
30 select {
31 case <-req.ctx.Done():
32 close(req.reply)
33 delete(bufSign, req.requestID)
34 delete(reqSign, req.requestID)
35 default:
36 }
37 }
38 case msg, ok := <-peerMsg:
39 if ok {
40 if content, ok := msg.Msg.Message.(*vss.Signature); ok {
41 requestID := string(content.RequestId)
42 if req := reqSign[requestID]; req.requestID == requestID {
43 select {
44 case <-req.ctx.Done():
45 case req.reply <- content:
46 }
47 } else {
48 bufSign[requestID] = append(bufSign[requestID], content)
49 }
50 }
51 }
52 case req, ok := <-d.reqSignc:
53 if ok {
54 //1)Check buf to see if it has enough signatures
55 reqSign[req.requestID] = req
56 if signs := bufSign[req.requestID]; len(signs) >= 0 {
57 for _, sign := range signs {
58 select {
59 case <-req.ctx.Done():
60 case req.reply <- sign:
61 }
62 }
63 bufSign[req.requestID] = nil
64 }
65 }
66 }
67 }
68}
69
70func (d *DosNode) handleQuery(ids [][]byte, pubPoly *share.PubPoly, sec *share.PriShare, groupID string, requestID, lastRand, useSeed *big.Int, url, selector string, pType uint32) {
71 queryCtx, cancel := context.WithTimeout(context.Background(), time.Duration(60*15*time.Second))

Callers 1

StartMethod · 0.95

Calls 3

InfoMethod · 0.65
SubscribeMsgMethod · 0.65
UnSubscribeMsgMethod · 0.65

Tested by

no test coverage detected