logger -> recorder

Free up namespace for a traditional runtime logger.
This commit is contained in:
Greg Fitzgerald
2018-03-19 10:16:16 -06:00
parent 9f9b79f30b
commit 64af37e0cd
7 changed files with 38 additions and 38 deletions

View File

@@ -10,7 +10,7 @@ use transaction::Transaction;
use signature::{KeyPair, PublicKey, Signature};
use mint::Mint;
use historian::{reserve_signature, Historian};
use logger::Signal;
use recorder::Signal;
use std::sync::mpsc::SendError;
use std::collections::{HashMap, HashSet};
use std::result;
@@ -43,8 +43,8 @@ impl Accountant {
{
let mut entries = entries.into_iter();
// The first item in the log is required to be an entry with zero num_hashes,
// which implies its id can be used as the log's seed.
// The first item in the ledger is required to be an entry with zero num_hashes,
// which implies its id can be used as the ledger's seed.
let entry0 = entries.next().unwrap();
let start_hash = entry0.id;
@@ -59,7 +59,7 @@ impl Accountant {
last_time: Utc.timestamp(0, 0),
};
// The second item in the log is a special transaction where the to and from
// The second item in the ledger is a special transaction where the to and from
// fields are the same. That entry should be treated as a deposit, not a
// transfer to oneself.
let entry1 = entries.next().unwrap();
@@ -240,7 +240,7 @@ impl Accountant {
mod tests {
use super::*;
use signature::KeyPairUtil;
use logger::ExitReason;
use recorder::ExitReason;
#[test]
fn test_accountant() {

View File

@@ -4,7 +4,7 @@ use silk::historian::Historian;
use silk::hash::Hash;
use silk::entry::Entry;
use silk::ledger::verify_slice;
use silk::logger::Signal;
use silk::recorder::Signal;
use silk::signature::{KeyPair, KeyPairUtil};
use silk::transaction::Transaction;
use silk::event::Event;

View File

@@ -7,7 +7,7 @@ use std::sync::mpsc::{sync_channel, Receiver, SyncSender};
use std::time::Instant;
use hash::{hash, Hash};
use entry::Entry;
use logger::{ExitReason, Logger, Signal};
use recorder::{ExitReason, Recorder, Signal};
use signature::Signature;
pub struct Historian {
@@ -22,7 +22,7 @@ impl Historian {
let (sender, event_receiver) = sync_channel(1000);
let (entry_sender, receiver) = sync_channel(1000);
let thread_hdl =
Historian::create_logger(*start_hash, ms_per_tick, event_receiver, entry_sender);
Historian::create_recorder(*start_hash, ms_per_tick, event_receiver, entry_sender);
let signatures = HashSet::new();
Historian {
sender,
@@ -34,22 +34,22 @@ impl Historian {
/// A background thread that will continue tagging received Event messages and
/// sending back Entry messages until either the receiver or sender channel is closed.
fn create_logger(
fn create_recorder(
start_hash: Hash,
ms_per_tick: Option<u64>,
receiver: Receiver<Signal>,
sender: SyncSender<Entry>,
) -> JoinHandle<ExitReason> {
spawn(move || {
let mut logger = Logger::new(receiver, sender, start_hash);
let mut recorder = Recorder::new(receiver, sender, start_hash);
let now = Instant::now();
loop {
if let Err(err) = logger.process_events(now, ms_per_tick) {
if let Err(err) = recorder.process_events(now, ms_per_tick) {
return err;
}
if ms_per_tick.is_some() {
logger.last_id = hash(&logger.last_id);
logger.num_hashes += 1;
recorder.last_id = hash(&recorder.last_id);
recorder.num_hashes += 1;
}
}
})

View File

@@ -7,7 +7,7 @@ pub mod event;
pub mod entry;
pub mod ledger;
pub mod mint;
pub mod logger;
pub mod recorder;
pub mod historian;
pub mod streamer;
pub mod accountant;

View File

@@ -1,5 +1,5 @@
//! The `logger` crate provides an object for generating a Proof-of-History.
//! It logs Event items on behalf of its users. It continuously generates
//! The `recorder` crate provides an object for generating a Proof-of-History.
//! It records Event items on behalf of its users. It continuously generates
//! new hashes, only stopping to check if it has been sent an Event item. It
//! tags each Event with an Entry and sends it back. The Entry includes the
//! Event, the latest hash, and the number of hashes since the last event.
@@ -24,7 +24,7 @@ pub enum ExitReason {
SendDisconnected,
}
pub struct Logger {
pub struct Recorder {
pub sender: SyncSender<Entry>,
pub receiver: Receiver<Signal>,
pub last_id: Hash,
@@ -33,9 +33,9 @@ pub struct Logger {
pub num_ticks: u64,
}
impl Logger {
impl Recorder {
pub fn new(receiver: Receiver<Signal>, sender: SyncSender<Entry>, start_hash: Hash) -> Self {
Logger {
Recorder {
receiver,
sender,
last_id: start_hash,
@@ -45,7 +45,7 @@ impl Logger {
}
}
pub fn log_entry(&mut self) -> Result<Entry, ExitReason> {
pub fn record_entry(&mut self) -> Result<Entry, ExitReason> {
let events = mem::replace(&mut self.events, vec![]);
let entry = create_entry_mut(&mut self.last_id, &mut self.num_hashes, events);
println!("{}", serde_json::to_string(&entry).unwrap());
@@ -60,7 +60,7 @@ impl Logger {
loop {
if let Some(ms) = ms_per_tick {
if epoch.elapsed() > Duration::from_millis((self.num_ticks + 1) * ms) {
self.log_entry()?;
self.record_entry()?;
self.num_ticks += 1;
}
}
@@ -68,7 +68,7 @@ impl Logger {
match self.receiver.try_recv() {
Ok(signal) => match signal {
Signal::Tick => {
let entry = self.log_entry()?;
let entry = self.record_entry()?;
self.sender
.send(entry)
.or(Err(ExitReason::SendDisconnected))?;