From ff095c2312d86f0a58f24f643043327fb40e879f Mon Sep 17 00:00:00 2001 From: wangjian Date: Wed, 5 Apr 2023 17:30:22 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E6=94=B9bug,=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E8=BF=9E=E6=8E=A5=E6=8A=A5=E9=94=99=EF=BC=8C=E5=B0=B1?= =?UTF-8?q?=E4=BC=9A=E6=8B=92=E7=BB=9D=E6=9C=8D=E5=8A=A1=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router.go | 103 -------------------------------------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 router.go diff --git a/router.go b/router.go deleted file mode 100644 index 805b53f..0000000 --- a/router.go +++ /dev/null @@ -1,103 +0,0 @@ -package hpds_node - -import ( - "git.hpds.cc/Component/network" - "git.hpds.cc/pavement/hpds_node/config" - "sync" -) - -type router struct { - r *route -} - -func newRouter(functions []config.App) network.Router { - return &router{r: newRoute(functions)} -} - -func (r *router) Route(metadata network.Metadata) network.Route { - return r.r -} - -func (r *router) Clean() { - r.r = nil -} - -type route struct { - functions []config.App - data map[byte]map[string]string - mu sync.RWMutex -} - -func newRoute(functions []config.App) *route { - return &route{ - functions: functions, - data: make(map[byte]map[string]string), - } -} - -func (r *route) Add(connId string, name string, observeDataTags []byte) (err error) { - r.mu.Lock() - defer r.mu.Unlock() - - ok := false - for _, v := range r.functions { - if v.Name == name { - ok = true - break - } - } - if !ok { - //return fmt.Errorf("SFN[%s] does not exist in config functions", name) - //如果不存在,自动增加 - item := config.App{ - Name: name, - } - r.functions = append(r.functions, item) - } - //去除只能订阅一次的问题 - //LOOP: - //for _, connects := range r.data { - // for connKey, n := range connects { - // if n == name { - // err = hpds_err.NewDuplicateNameError(connKey, fmt.Errorf("node:Stream Function[%s] is already linked to another connection", name)) - // delete(connects, connKey) - // break LOOP - // } - // } - //} - - for _, tag := range observeDataTags { - connects := r.data[tag] - if connects == nil { - connects = make(map[string]string) - r.data[tag] = connects - } - r.data[tag][connId] = name - } - - return err -} - -func (r *route) Remove(connId string) error { - r.mu.Lock() - defer r.mu.Unlock() - - for _, connects := range r.data { - delete(connects, connId) - } - - return nil -} - -func (r *route) GetForwardRoutes(tag byte) []string { - r.mu.RLock() - defer r.mu.RUnlock() - - var keys []string - if connects := r.data[tag]; connects != nil { - for k := range connects { - keys = append(keys, k) - } - } - return keys -}