registry: log subscribe/unsubscribe messages only when the action actually takes place

This commit is contained in:
Michał Matczuk 2017-11-25 23:39:47 +01:00
parent c2c50bfba6
commit 1700712f7f

View file

@ -54,12 +54,6 @@ var voidRegistryItem = &RegistryItem{}
// Subscribe allows to connect client with a given identifier.
func (r *registry) Subscribe(identifier id.ID) {
r.logger.Log(
"level", 1,
"action", "subscribe",
"identifier", identifier,
)
r.mu.Lock()
defer r.mu.Unlock()
@ -67,6 +61,12 @@ func (r *registry) Subscribe(identifier id.ID) {
return
}
r.logger.Log(
"level", 1,
"action", "subscribe",
"identifier", identifier,
)
r.items[identifier] = voidRegistryItem
}
@ -93,12 +93,6 @@ func (r *registry) Subscriber(hostPort string) (id.ID, *Auth, bool) {
// Unsubscribe removes client from registry and returns it's RegistryItem.
func (r *registry) Unsubscribe(identifier id.ID) *RegistryItem {
r.logger.Log(
"level", 1,
"action", "unsubscribe",
"identifier", identifier,
)
r.mu.Lock()
defer r.mu.Unlock()
@ -107,6 +101,12 @@ func (r *registry) Unsubscribe(identifier id.ID) *RegistryItem {
return nil
}
r.logger.Log(
"level", 1,
"action", "unsubscribe",
"identifier", identifier,
)
if i.Hosts != nil {
for _, h := range i.Hosts {
delete(r.hosts, h.Host)