liuxiaolong
2020-03-11 7848ce12f101f8e825b01a52e620f75514900ea9
mangos.go
@@ -13,6 +13,11 @@
   pubCh        chan Message  //publish msg chan
   surveyors    gopherdiscovery.StringSet
   svr *gopherdiscovery.DiscoveryServer
   cli *gopherdiscovery.DiscoveryClient
   cliInfo map[string]interface{}
   recvCh chan Message  //recv msg chan
}
@@ -22,9 +27,8 @@
   var err error
   var (
      defaultOpts = gopherdiscovery.Options{
         SurveyTime:   3 * time.Second,
         //RecvDeadline: 3 * time.Second,
         PollTime:     5 * time.Second,
         SurveyTime:   1500 * time.Millisecond,
         PollTime:     2 * time.Second,
      }
   )
@@ -36,6 +40,7 @@
      heartBeatUrl: heartBeatUrl,
      surveyors:    gopherdiscovery.NewStringSet(),
      pubCh:        make(chan Message, 50),
      svr: discoveryServer,
   }
   var msgCache = make(map[string]Message)
   //clientMsgCh := make(map[string]chan Message)
@@ -76,6 +81,7 @@
            }
            pub.surveyors = nodeIds
            pub.cliInfo = discoveryServer.SvInfo()
            time.Sleep(10 * time.Millisecond)
         }
      }
@@ -101,6 +107,7 @@
      heartBeatUrl: heartBeatUrl,
      recvCh: make(chan Message,50),
      surveyors: gopherdiscovery.NewStringSet(),
      cli: client,
   }
   var receivedCache = make(map[string]string)
   go func() {
@@ -150,3 +157,16 @@
func (ps *mangosPubSub) Recv() chan Message {
   return ps.recvCh
}
func (ps *mangosPubSub) GetCliInfo() map[string]interface{} {
   if ps.svr != nil {
      return ps.cliInfo
   }
   return nil
}
func (ps *mangosPubSub) SetResp(r interface{}) {
   if ps.cli != nil {
      ps.cli.SetResp(r)
   }
}