...
1
4 package common
5
6
7
8
9
10 import (
11 "sync"
12 )
13
14 var (
15 myservicenames []string
16 clients []*Service
17 blocked []*BlockedService
18 addlock sync.Mutex
19 )
20
21 type Service struct {
22 Name string
23 }
24
25 type BlockedService struct {
26 Name string
27 Counter int
28 }
29
30
31 func AddServiceName(s string) {
32 addlock.Lock()
33 defer addlock.Unlock()
34 for _, c := range clients {
35 if c.Name == s {
36 return
37 }
38 }
39 clients = append(clients, &Service{Name: s})
40 }
41
42
43 func GetConnectionNames() []*Service {
44 return clients
45 }
46
47
48 func GetBlockedConnectionNames() []*BlockedService {
49 addlock.Lock()
50 defer addlock.Unlock()
51 var res []*BlockedService
52 for _, x := range blocked {
53 if x.Counter > 0 {
54 res = append(res, x)
55 }
56 }
57 return res
58 }
59
60
61 func AddBlockedServiceName(s string) {
62 addlock.Lock()
63 defer addlock.Unlock()
64 for _, x := range blocked {
65 if x.Name == s {
66 x.Counter++
67 return
68 }
69 }
70 blocked = append(blocked, &BlockedService{Name: s, Counter: 1})
71 }
72
73
74 func RemoveBlockedServiceName(s string) {
75 addlock.Lock()
76 defer addlock.Unlock()
77 for _, x := range blocked {
78 if x.Name == s {
79 x.Counter = 0
80 return
81 }
82 }
83 }
84
85
86 func AddExportedServiceName(name string) {
87 addlock.Lock()
88 defer addlock.Unlock()
89 for _, m := range myservicenames {
90 if m == name {
91 return
92 }
93 }
94 myservicenames = append(myservicenames, name)
95 }
96
View as plain text