Made code compile + moved address to provider client constructor

This commit is contained in:
Jedrzej Stuczynski
2019-12-18 10:22:24 +00:00
parent c81f2e860c
commit 5915e45961
2 changed files with 21 additions and 11 deletions
+8 -2
View File
@@ -130,14 +130,14 @@ impl NymClient {
}
async fn start_provider_polling(provider_address: SocketAddrV4) {
let provider_client = ProviderClient::new();
let provider_client = ProviderClient::new(provider_address);
loop {
println!("[FETCH MSG] - Polling provider...");
let delay_duration = Duration::from_secs_f64(FETCH_MESSAGES_DELAY);
tokio::time::delay_for(delay_duration).await;
provider_client
.retrieve_messages(provider_address)
.retrieve_messages()
.await
.unwrap();
}
@@ -146,6 +146,12 @@ impl NymClient {
pub fn start(self, socket_address: SocketAddr) -> Result<(), Box<dyn std::error::Error>> {
println!("starting nym client");
// TODO: registration here
return Ok(());
// don't start anything, just register
let (mix_tx, mix_rx) = mpsc::unbounded();
let mut rt = Runtime::new()?;
let topology = get_topology(self.is_local);
+13 -9
View File
@@ -1,29 +1,33 @@
use sfw_provider_requests::requests::{ProviderRequest, PullRequest};
use sfw_provider_requests::responses::{ProviderResponse, PullResponse};
use std::net::Shutdown;
use std::net::{Shutdown, SocketAddr};
use std::net::SocketAddrV4;
use tokio::prelude::*;
use tokio::time::Duration;
use std::time::Duration;
pub struct ProviderClient {}
pub struct ProviderClient {
address: SocketAddrV4,
}
impl ProviderClient {
pub fn new() -> Self {
ProviderClient {}
pub fn new(address: SocketAddrV4) -> Self {
ProviderClient {
address
}
}
pub async fn retrieve_messages(
&self,
provider: SocketAddrV4,
) -> Result<(), Box<dyn std::error::Error>> {
let address = [42; 32];
let pull_request = PullRequest::new(address);
let destination_address = [42u8; 32];
let dummy_auth_token_to_make_it_compile = [0u8; 32];
let pull_request = PullRequest::new(destination_address, dummy_auth_token_to_make_it_compile);
let bytes = pull_request.to_bytes();
// DH temporary: the provider's client port is not in the topology, but we can't change that
// right now without messing up the existing Go mixnet. So I'm going to hardcode this
// for the moment until the Go mixnet goes away.
let provider_socket = SocketAddrV4::new(*provider.ip(), 9000);
let provider_socket = SocketAddrV4::new(*self.address.ip(), 9000);
println!("Provider: {:?}", provider_socket);
let mut socket = tokio::net::TcpStream::connect(provider_socket).await?;