aboutsummaryrefslogtreecommitdiffstats
path: root/src/protocol.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-01-22 01:12:07 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-01-22 01:12:09 -0800
commite547fa64ce684211f8eb76738f133adfad296eaa (patch)
tree93a116b8e91ebb7b9f4555869614c66df2e7b6ff /src/protocol.rs
parent375836cf6322bc31828c5e2be47e5f0aa5f99099 (diff)
downloadgeniza-e547fa64ce684211f8eb76738f133adfad296eaa.tar.gz
geniza-e547fa64ce684211f8eb76738f133adfad296eaa.zip
WIP refactoring DatPeer
- use Key in some more spots (instead of [u8]) - threaded Peer implementation, with chan for communication
Diffstat (limited to 'src/protocol.rs')
-rw-r--r--src/protocol.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/protocol.rs b/src/protocol.rs
index ee72b4d..84a5793 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -176,8 +176,26 @@ impl Write for DatConnection {
}
}
+impl Clone for DatConnection {
+ fn clone(&self) -> DatConnection {
+ DatConnection {
+ id: self.id.clone(),
+ remote_id: self.remote_id.clone(),
+ tcp: self.tcp.try_clone().unwrap(),
+ live: self.live,
+ key: self.key.clone(),
+ discovery_key: self.discovery_key.clone(),
+ tx_nonce: self.tx_nonce.clone(),
+ tx_offset: self.tx_offset,
+ rx_nonce: self.rx_nonce.clone(),
+ rx_offset: self.rx_offset,
+
+ }
+ }
+}
+
impl DatConnection {
- pub fn connect<A: ToSocketAddrs + Display>(addr: A, key: &[u8], live: bool) -> Result<DatConnection> {
+ pub fn connect<A: ToSocketAddrs + Display>(addr: A, key: &Key, live: bool) -> Result<DatConnection> {
// Connect to server
info!("Connecting to {}", addr);
@@ -188,7 +206,7 @@ impl DatConnection {
}
// It's sort of a hack, but this should be usable from an accept() as well as a connect()
- pub fn from_tcp(tcp: TcpStream, key: &[u8], live: bool) -> Result<DatConnection> {
+ pub fn from_tcp(tcp: TcpStream, key: &Key, live: bool) -> Result<DatConnection> {
let tx_nonce = gen_nonce();
let mut local_id = [0; 32];
@@ -196,7 +214,7 @@ impl DatConnection {
rng.fill_bytes(&mut local_id);
let mut dk = [0; 32];
- dk.copy_from_slice(&make_discovery_key(key)[0..32]);
+ dk.copy_from_slice(&make_discovery_key(&key[0..32])[0..32]);
let timeout = Duration::new(7, 0);
tcp.set_write_timeout(Some(timeout))?;
@@ -206,7 +224,7 @@ impl DatConnection {
tcp,
live,
remote_id: [0; 32],
- key: Key::from_slice(key).unwrap(), // TODO:
+ key: key.clone(),
discovery_key: dk,
tx_nonce: tx_nonce,
tx_offset: 0,