Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for insertion of dummy entry points into the local table #346

Merged
merged 1 commit into from
Jun 13, 2018
Merged
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
34 changes: 22 additions & 12 deletions src/crdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ use pnet::datalink;
use rayon::prelude::*;
use result::{Error, Result};
use ring::rand::{SecureRandom, SystemRandom};
use signature::{KeyPair, KeyPairUtil};
use signature::{PublicKey, Signature};
use signature::{KeyPair, KeyPairUtil, PublicKey, Signature};
use std;
use std::collections::HashMap;
use std::collections::VecDeque;
Expand Down Expand Up @@ -134,6 +133,17 @@ impl ReplicatedData {
repair_addr,
)
}
pub fn new_entry_point(gossip_addr: SocketAddr) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by entry_point here? Would new_from_base_addr make more sense?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By entry point I meant that it’s a gossip network entry point, it’s a dummy entry that had an invalid public key. It’s used to attach to the network initially and will eventually get purged

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add code comments? You don't add a test in this PR and the only explanation is in the PR description and the review comment above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I just didn't grok the test.

let daddr: SocketAddr = "0.0.0.0:0".parse().unwrap();
ReplicatedData::new(
PublicKey::default(),
gossip_addr,
daddr.clone(),
daddr.clone(),
daddr.clone(),
daddr,
)
}
}

/// `Crdt` structure keeps a table of `ReplicatedData` structs
Expand Down Expand Up @@ -411,7 +421,7 @@ impl Crdt {
//trace!("get updates since {}", v);
let data = self.table
.values()
.filter(|x| self.local[&x.id] > v)
.filter(|x| x.id != PublicKey::default() && self.local[&x.id] > v)
.cloned()
.collect();
let id = self.me;
Expand Down Expand Up @@ -829,14 +839,21 @@ mod tests {
assert_eq!(key, d1.id);
assert_eq!(ix, 3);
assert_eq!(ups.len(), 3);
assert_eq!(sorted(&ups), sorted(&vec![d2.clone(), d1, d3]));
assert_eq!(
sorted(&ups),
sorted(&vec![d1.clone(), d2.clone(), d3.clone()])
);
let mut crdt2 = Crdt::new(d2.clone());
crdt2.apply_updates(key, ix, &ups);
assert_eq!(crdt2.table.values().len(), 3);
assert_eq!(
sorted(&crdt2.table.values().map(|x| x.clone()).collect()),
sorted(&crdt.table.values().map(|x| x.clone()).collect())
);
let d4 = ReplicatedData::new_entry_point("127.0.0.4:1234".parse().unwrap());
crdt.insert(&d4);
let (_key, _ix, ups) = crdt.get_updates_since(0);
assert_eq!(sorted(&ups), sorted(&vec![d2.clone(), d1, d3]));
}
#[test]
fn window_index_request() {
Expand Down Expand Up @@ -927,14 +944,7 @@ mod tests {
let rv = crdt.gossip_request().unwrap();
assert_eq!(rv.0, nxt1.gossip_addr);

let nxt2 = ReplicatedData::new(
KeyPair::new().pubkey(),
"127.0.0.3:1234".parse().unwrap(),
"127.0.0.1:1235".parse().unwrap(),
"127.0.0.1:1236".parse().unwrap(),
"127.0.0.1:1237".parse().unwrap(),
"127.0.0.1:1238".parse().unwrap(),
);
let nxt2 = ReplicatedData::new_entry_point("127.0.0.3:1234".parse().unwrap());
crdt.insert(&nxt2);
// check that the service works
// and that it eventually produces a request for both nodes
Expand Down