3232// Watcher describes a component that watches for new certificates in a CT log.
3333type Watcher struct {
3434 workers []* worker
35+ certChan chan certstream.Entry
3536 cancelFunc context.CancelFunc
3637}
3738
39+ // NewWatcher creates a new Watcher.
40+ func NewWatcher (certChan chan certstream.Entry ) * Watcher {
41+ return & Watcher {
42+ certChan : certChan ,
43+ }
44+ }
45+
3846// Start starts the watcher. This method is blocking.
3947func (w * Watcher ) Start () {
4048 // Get a list of urls of all CT logs
@@ -46,7 +54,11 @@ func (w *Watcher) Start() {
4654
4755 ctx , cancel := context .WithCancel (context .Background ())
4856 w .cancelFunc = cancel
49- certChan := make (chan certstream.Entry , 5000 )
57+
58+ // Create new certChan if it doesn't exist yet
59+ if w .certChan == nil {
60+ w .certChan = make (chan certstream.Entry , 5000 )
61+ }
5062
5163 var wg sync.WaitGroup
5264
@@ -58,7 +70,7 @@ func (w *Watcher) Start() {
5870 name : transparencyLog .Description ,
5971 operatorName : operator .Name ,
6072 ctURL : transparencyLog .URL ,
61- entryChan : certChan ,
73+ entryChan : w . certChan ,
6274 }
6375 w .workers = append (w .workers , & ctWorker )
6476
@@ -71,10 +83,10 @@ func (w *Watcher) Start() {
7183 }
7284
7385 log .Println ("Started CT watcher" )
74- go certHandler (certChan )
86+ go certHandler (w . certChan )
7587
7688 wg .Wait ()
77- close (certChan )
89+ close (w . certChan )
7890}
7991
8092// Stop stops the watcher.
0 commit comments