aboutsummaryrefslogtreecommitdiffstats
path: root/src/blah
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-07-31 22:45:14 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-07-31 22:46:27 -0700
commit7662f08f2ec0f0179d42a8f79bc5eeed70fd2dd8 (patch)
treeeec47c826555a822d67afc90be9c8393d0162917 /src/blah
parent7164f10355fcdc45d3be58bfcee2939937e01623 (diff)
downloadgeniza-old-wip.tar.gz
geniza-old-wip.zip
commit old WIPold-wip
Diffstat (limited to 'src/blah')
-rw-r--r--src/blah92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/blah b/src/blah
new file mode 100644
index 0000000..0384070
--- /dev/null
+++ b/src/blah
@@ -0,0 +1,92 @@
+
+ /// hyperdrive-specific helper for discovering the public key for the "content" feed
+ /// from the "metadata" feed , and sending a Feed message to initialize on this connection.
+ pub fn init_data_feed(&mut self) -> Result<()> {
+
+ if self.feeds.len() > 1 {
+ return Ok(());
+ }
+
+ let data_key = self.get_drive_data_key()?;
+ self.add_feed(&data_key[0..32])
+ }
+
+
+ /// hyperdrive-specific helper for returning the "data" feed public key (aka, index=1)
+ pub fn get_drive_data_key(&mut self) -> Result<Key> {
+
+ if self.feeds.len() > 1 {
+ // we already have the key
+ let key = self.feeds[1].clone();
+ return Ok(key);
+ }
+
+ // Info: downloading, not uploading
+ let mut im = Info::new();
+ im.set_uploading(false);
+ im.set_downloading(true);
+ self.conn.send_msg(&DatNetMessage::Info(im), 0)?;
+
+ // Have: nothing (so far)
+ let mut hm = Have::new();
+ hm.set_start(0);
+ hm.set_length(0);
+ self.conn.send_msg(&DatNetMessage::Have(hm), 0)?;
+
+ // UnHave: still nothing
+ let mut uhm = Unhave::new();
+ uhm.set_start(0);
+ self.conn.send_msg(&DatNetMessage::Unhave(uhm), 0)?;
+
+ // Want: just the first element
+ let mut wm = Want::new();
+ wm.set_start(0);
+ wm.set_length(1);
+ self.conn.send_msg(&DatNetMessage::Want(wm), 0)?;
+
+ // listen for Have
+ loop {
+ let (msg, feed_index) = self.conn.recv_msg()?;
+ if feed_index == 1 {
+ continue;
+ }
+ if let DatNetMessage::Have(_) = msg {
+ break;
+ } else {
+ info!("Expected Have message, got: {:?}", &msg);
+ continue;
+ }
+ }
+
+ // Request
+ let mut rm = Request::new();
+ rm.set_index(0);
+ self.conn.send_msg(&DatNetMessage::Request(rm), 0)?;
+
+ loop {
+ let (msg, feed_index) = self.conn.recv_msg()?;
+ if feed_index == 1 {
+ info!("Expected other message channel");
+ continue;
+ }
+ if let DatNetMessage::Data(dm) = msg {
+ info!("Got metadata: {}", dm.get_index());
+ if dm.get_index() == 0 {
+ let index_msg = parse_from_bytes::<Index>(&mut dm.get_value())?;
+ if index_msg.get_field_type() == "hyperdrive" {
+ let data_key = index_msg.get_content();
+ if data_key.len() != 32 {
+ bail!("Received data key had wrong length: {}", data_key.len());
+ }
+ // TODO: ok_or(), but what?
+ return Ok(Key::from_slice(&data_key[0..32]).unwrap());
+ } else {
+ bail!("non-hyperdrive Index type: {}", index_msg.get_field_type());
+ }
+ }
+ } else {
+ info!("Expected Data message, got: {:?}", &msg);
+ continue;
+ }
+ }
+ }