@@ -60,8 +60,8 @@ DEFINE_int32(target_poll_frequency_seconds, 10,
6060 " How often should the target log be polled for updates." );
6161DEFINE_int32 (num_http_server_threads, 16 ,
6262 " Number of threads for servicing the incoming HTTP requests." );
63- DEFINE_string (target_log_uri, " http://ct.googleapis.com/pilot " ,
64- " URI of the log to mirror." );
63+ DEFINE_string (target_log_uri, " " ,
64+ " URI of the log to mirror, or empty to disable mirroring ." );
6565DEFINE_string (
6666 target_public_key, " " ,
6767 " PEM-encoded server public key file of the log we're mirroring." );
@@ -251,6 +251,25 @@ void STHUpdater(Database* db, ClusterStateController* cluster_state_controller,
251251}
252252
253253
254+ shared_ptr<RemotePeer> createTargetPeerFromFlags (
255+ ThreadPool* pool, UrlFetcher* url_fetcher, EVP_PKEY* pubkey, Task* task,
256+ function<void (const ct::SignedTreeHead&)> new_sth) {
257+ if (FLAGS_target_log_uri.empty ()) {
258+ LOG (WARNING) << " Empty target_log_uri flag; mirroring DISABLED" ;
259+ return shared_ptr<RemotePeer>();
260+ }
261+
262+ return make_shared<RemotePeer>(
263+ unique_ptr<AsyncLogClient>(new AsyncLogClient (CHECK_NOTNULL (pool),
264+ CHECK_NOTNULL (url_fetcher),
265+ FLAGS_target_log_uri)),
266+ unique_ptr<LogVerifier>(new LogVerifier (
267+ new LogSigVerifier (CHECK_NOTNULL (pubkey)),
268+ new MerkleVerifier (unique_ptr<Sha256Hasher>(new Sha256Hasher)))),
269+ new_sth, CHECK_NOTNULL (task)->AddChild (
270+ [](Task*) { LOG (INFO) << " RemotePeer exited." ; }));
271+ }
272+
254273int main (int argc, char * argv[]) {
255274 // Ignore various signals whilst we start up.
256275 signal (SIGHUP, SIG_IGN);
@@ -329,7 +348,6 @@ int main(int argc, char* argv[]) {
329348 server.election ()->WaitToBecomeMaster ();
330349 }
331350
332- CHECK (!FLAGS_target_log_uri.empty ());
333351
334352 ThreadPool pool (16 );
335353 SyncTask fetcher_task (&pool);
@@ -350,16 +368,13 @@ int main(int argc, char* argv[]) {
350368 queue.insert (make_pair (sth.tree_size (), sth));
351369 });
352370
353- const shared_ptr<RemotePeer> peer (make_shared<RemotePeer>(
354- unique_ptr<AsyncLogClient>(
355- new AsyncLogClient (&pool, &url_fetcher, FLAGS_target_log_uri)),
356- unique_ptr<LogVerifier>(new LogVerifier (
357- new LogSigVerifier (pubkey.ValueOrDie ()),
358- new MerkleVerifier (unique_ptr<Sha256Hasher>(new Sha256Hasher)))),
359- new_sth, fetcher_task.task ()->AddChild (
360- [](Task*) { LOG (INFO) << " RemotePeer exited." ; })));
361-
362- server.continuous_fetcher ()->AddPeer (" target" , peer);
371+ const shared_ptr<RemotePeer> peer (
372+ createTargetPeerFromFlags (&pool, &url_fetcher, pubkey.ValueOrDie (),
373+ fetcher_task.task (), new_sth));
374+ if (peer) {
375+ LOG (INFO) << " Adding remote peer for target log." ;
376+ server.continuous_fetcher ()->AddPeer (" target" , peer);
377+ }
363378
364379 server.WaitForReplication ();
365380
0 commit comments