aboutsummaryrefslogtreecommitdiffstats
path: root/src/peer.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-01-22 01:30:50 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-01-22 01:30:50 -0800
commitef8ea37d26716869cd4572152ffedc047700f747 (patch)
tree07ab323d523775e98ada04078c72c5b4f8d4a108 /src/peer.rs
parente547fa64ce684211f8eb76738f133adfad296eaa (diff)
downloadgeniza-ef8ea37d26716869cd4572152ffedc047700f747.tar.gz
geniza-ef8ea37d26716869cd4572152ffedc047700f747.zip
allow passing local_id to datconnect (and peer)
Diffstat (limited to 'src/peer.rs')
-rw-r--r--src/peer.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/peer.rs b/src/peer.rs
index 3310a13..c6f8c6d 100644
--- a/src/peer.rs
+++ b/src/peer.rs
@@ -85,14 +85,30 @@ fn worker_thread(mut dc: DatConnection, handle: u64, outbound_chan: chan::Receiv
impl DatPeerThread {
- pub fn connect<A: ToSocketAddrs + Display>(addr: A, feed_key: Key, handle: u64, is_live: bool, unified_chan: chan::Sender<Result<PeerMsg>>) -> Result<DatPeerThread> {
+ pub fn connect<A: ToSocketAddrs + Display>(addr: A, feed_key: Key, handle: u64, is_live: bool, local_id: Option<&[u8]>, unified_chan: chan::Sender<Result<PeerMsg>>) -> Result<DatPeerThread> {
let addr = addr.to_socket_addrs().unwrap().nth(0).unwrap();
let (outbound_chan, tx_chan) = chan::async();
let feed_key2 = feed_key.clone();
+
+ // Do an ugly little dance to copy local_id across thread barrier
+ let mut id_buf = [0; 32];
+ let local_id = match local_id {
+ None => None,
+ Some(val) => {
+ id_buf.copy_from_slice(val);
+ Some(id_buf)
+ },
+ };
thread::spawn(move || {
- let dc = match DatConnection::connect(addr, &feed_key, is_live) {
+ let local_id = match local_id {
+ None => None,
+ Some(val) => {
+ Some(&id_buf[..])
+ },
+ };
+ let dc = match DatConnection::connect(addr, &feed_key, is_live, local_id) {
Ok(c) => c,
Err(e) => {
// TODO: error chain!