Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions internal/broadcast/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,21 @@ func (bm *Dispatcher) broadcaster() {

// Take entry out of broadcast channel and generate JSON representations for the entry.
entry := <-bm.MessageQueue
dataLite := entry.JSONLite()
dataFull := entry.JSON()
dataDomain := entry.JSONDomains()

bm.clientLock.RLock()

for _, c := range bm.clients {
switch c.SubType() {
case SubTypeLite:
data = dataLite
data = entry.JSONLite()
case SubTypeFull:
data = dataFull
data = entry.JSON()
case SubTypeDomain:
data = dataDomain
data = entry.JSONDomains()
default:
// This should never happen, but if it does, we log it and skip the client.
log.Printf("Unknown subscription type '%d' for client '%s'. Skipping this client!\n", c.SubType(), c.Name())
log.Printf("Unknown subscription type '%d' on client '%s'. Skipping this client!\n", c.SubType(), c.Name())
continue
}

c.Write(data)
}

Expand Down
24 changes: 16 additions & 8 deletions internal/models/certstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import (
)

type Entry struct {
Data Data `json:"data"`
MessageType string `json:"message_type"`
cachedJSON []byte
cachedJSONLite []byte
Data Data `json:"data"`
MessageType string `json:"message_type"`
cachedJSON []byte
cachedJSONLite []byte
cachedJSONDomains []byte
}

// Clone returns a new copy of the Entry.
func (e *Entry) Clone() Entry {
return Entry{
Data: e.Data,
MessageType: e.MessageType,
cachedJSON: e.cachedJSON,
cachedJSONLite: e.cachedJSONLite,
Data: e.Data,
MessageType: e.MessageType,
cachedJSON: e.cachedJSON,
cachedJSONLite: e.cachedJSONLite,
cachedJSONDomains: e.cachedJSONDomains,
}
}

Expand Down Expand Up @@ -61,6 +63,10 @@ func (e *Entry) JSONLiteNoCache() []byte {

// JSONDomains returns the JSON encoded domains (DomainsEntry) as byte slice.
func (e *Entry) JSONDomains() []byte {
if len(e.cachedJSONDomains) > 0 {
return e.cachedJSONDomains
}

domainsEntry := DomainsEntry{
Data: e.Data.LeafCert.AllDomains,
MessageType: "dns_entries",
Expand All @@ -71,6 +77,8 @@ func (e *Entry) JSONDomains() []byte {
log.Println(err)
}

e.cachedJSONDomains = domainsEntryBytes

return domainsEntryBytes
}

Expand Down
Loading