@@ -55,7 +55,7 @@ func (w *Watcher) Start() {
5555 }
5656
5757 // initialize the watcher with currently available logs
58- w .addNewlyAvailableLogs ()
58+ w .updateLogs ()
5959
6060 log .Println ("Started CT watcher" )
6161 go certHandler (w .certChan )
@@ -69,33 +69,39 @@ func (w *Watcher) Start() {
6969// This method is blocking. It can be stopped by cancelling the context.
7070func (w * Watcher ) watchNewLogs () {
7171 // Add all available logs to the watcher
72- w .addNewlyAvailableLogs ()
72+ w .updateLogs ()
7373
7474 // Check for new logs once every hour
7575 ticker := time .NewTicker (1 * time .Hour )
7676 for {
7777 select {
7878 case <- ticker .C :
79- w .addNewlyAvailableLogs ()
79+ w .updateLogs ()
8080 case <- w .context .Done ():
8181 ticker .Stop ()
8282 return
8383 }
8484 }
8585}
8686
87- // The transparency log list is constantly updated with new Log servers.
88- // This function checks for new ct logs and adds them to the watcher.
89- func (w * Watcher ) addNewlyAvailableLogs () {
90- log .Println ("Checking for new ct logs..." )
91-
87+ func (w * Watcher ) updateLogs () {
9288 // Get a list of urls of all CT logs
9389 logList , err := getAllLogs ()
9490 if err != nil {
9591 log .Println (err )
9692 return
9793 }
9894
95+ w .addNewlyAvailableLogs (logList )
96+ if * config .AppConfig .General .DropOldLogs {
97+ w .dropRemovedLogs (logList )
98+ }
99+ }
100+
101+ // addNewlyAvailableLogs checks the transparency log list for new Log servers and adds workers for those to the watcher.
102+ func (w * Watcher ) addNewlyAvailableLogs (logList loglist3.LogList ) {
103+ log .Println ("Checking for new ct logs..." )
104+
99105 newCTs := 0
100106
101107 // Check the ct log list for new, unwatched logs
@@ -139,6 +145,12 @@ func (w *Watcher) addNewlyAvailableLogs() {
139145
140146 log .Printf ("New ct logs found: %d\n " , newCTs )
141147 log .Printf ("Currently monitored ct logs: %d\n " , len (w .workers ))
148+ }
149+
150+ // dropRemovedLogs checks if any of the currently monitored logs are no longer in the log list.
151+ // If they are not, the CT Logs are probably no longer relevant and the corresponding workers will be stopped.
152+ func (w * Watcher ) dropRemovedLogs (logList loglist3.LogList ) {
153+ removedCTs := 0
142154
143155 // Iterate over all workers and check if they are still in the logList
144156 // If they are not, the CT Logs are probably no longer relevant.
@@ -163,9 +175,13 @@ func (w *Watcher) addNewlyAvailableLogs() {
163175 // If the log is not in the loglist, stop the worker
164176 if ! onLogList {
165177 log .Printf ("Stopping worker. CT URL not found in LogList: '%s'\n " , ctWorker .ctURL )
178+ removedCTs ++
166179 ctWorker .stop ()
167180 }
168181 }
182+
183+ log .Printf ("Removed ct logs: %d\n " , removedCTs )
184+ log .Printf ("Currently monitored ct logs: %d\n " , len (w .workers ))
169185}
170186
171187// Stop stops the watcher.
0 commit comments