Using i64 for filesize
This commit is contained in:
parent
b363fe5585
commit
2602a97892
@ -1,12 +1,11 @@
|
|||||||
extern crate a03;
|
extern crate a03;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
use a03::*;
|
use a03::*;
|
||||||
use std::net::{TcpStream, Shutdown};
|
use std::net::{TcpStream, Shutdown};
|
||||||
use std::io::{Write, Read};
|
use std::io::Write;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
@ -19,9 +18,9 @@ fn main() {
|
|||||||
packet_type = PacketType::RequestWrite;
|
packet_type = PacketType::RequestWrite;
|
||||||
let file = fs::read(&args.filename).unwrap();
|
let file = fs::read(&args.filename).unwrap();
|
||||||
let size = file.len();
|
let size = file.len();
|
||||||
println!("Requesting Write of {}", args.filepath);
|
println!("Sending file of size {}", size);
|
||||||
json = Some(serde_json::to_string(
|
json = Some(serde_json::to_string(
|
||||||
&AddFile { name: args.filepath.clone(), size: size as u32 }).unwrap())
|
&AddFile { name: args.filepath.clone(), size: size as u64 }).unwrap())
|
||||||
} else {
|
} else {
|
||||||
packet_type = PacketType::RequestRead;
|
packet_type = PacketType::RequestRead;
|
||||||
println!("Requesting Read of {}", args.filepath);
|
println!("Requesting Read of {}", args.filepath);
|
||||||
@ -68,7 +67,8 @@ fn send_file_to_data_nodes(
|
|||||||
index: node.chunk_index,
|
index: node.chunk_index,
|
||||||
filename: filename.clone(),
|
filename: filename.clone(),
|
||||||
};
|
};
|
||||||
let packet = serde_json::to_writer(
|
println!("Sending");
|
||||||
|
serde_json::to_writer(
|
||||||
&mut stream,
|
&mut stream,
|
||||||
&Packet {
|
&Packet {
|
||||||
p_type: PacketType::PutFile,
|
p_type: PacketType::PutFile,
|
||||||
@ -76,9 +76,9 @@ fn send_file_to_data_nodes(
|
|||||||
data: Some(chunks[node.chunk_index as usize].to_vec()),
|
data: Some(chunks[node.chunk_index as usize].to_vec()),
|
||||||
// data: None,
|
// data: None,
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
stream.flush().unwrap();
|
|
||||||
stream.shutdown(Shutdown::Write).unwrap();
|
|
||||||
}
|
}
|
||||||
|
// stream.flush().unwrap();
|
||||||
|
// stream.shutdown(Shutdown::Write).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_file_from_data_nodes(
|
fn get_file_from_data_nodes(
|
||||||
@ -95,7 +95,7 @@ fn get_file_from_data_nodes(
|
|||||||
};
|
};
|
||||||
let endpoint = format!("{}:{}", node.ip, node.port);
|
let endpoint = format!("{}:{}", node.ip, node.port);
|
||||||
let mut stream = TcpStream::connect(endpoint).unwrap();
|
let mut stream = TcpStream::connect(endpoint).unwrap();
|
||||||
let packet = serde_json::to_writer(
|
serde_json::to_writer(
|
||||||
&stream,
|
&stream,
|
||||||
&Packet {
|
&Packet {
|
||||||
p_type: PacketType::GetFile,
|
p_type: PacketType::GetFile,
|
||||||
@ -135,7 +135,7 @@ pub struct CliArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_cli_args() -> CliArgs {
|
pub fn get_cli_args() -> CliArgs {
|
||||||
let mut args: Vec<String> = std::env::args().skip(1).collect();
|
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||||
if args.len() < 2 {
|
if args.len() < 2 {
|
||||||
panic!("Requires 2 arguments; IP:PORT:FILEPATH and a Local filename/filepath")
|
panic!("Requires 2 arguments; IP:PORT:FILEPATH and a Local filename/filepath")
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ fn request_read(stream: &mut TcpStream, conn: &Connection, message: &str) {
|
|||||||
|
|
||||||
fn request_write(stream: &mut TcpStream, conn: &Connection, message: &str) {
|
fn request_write(stream: &mut TcpStream, conn: &Connection, message: &str) {
|
||||||
let file: AddFile = serde_json::from_str(message).unwrap();
|
let file: AddFile = serde_json::from_str(message).unwrap();
|
||||||
let file_already_exists = add_file(&conn, &file.name, file.size as i32);
|
let file_already_exists = add_file(&conn, &file.name, file.size as i64);
|
||||||
if file_already_exists {
|
if file_already_exists {
|
||||||
match serde_json::to_writer(
|
match serde_json::to_writer(
|
||||||
stream,
|
stream,
|
||||||
@ -90,8 +90,6 @@ fn request_write(stream: &mut TcpStream, conn: &Connection, message: &str) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let file_info = get_file_info(&conn, &file.name).unwrap();
|
let file_info = get_file_info(&conn, &file.name).unwrap();
|
||||||
// let file_info = INode { id: 1, name: file.name, size: file.size };
|
|
||||||
// println!("{:?}", file_info);
|
|
||||||
let mut blocks: Vec<Block> = Vec::new();
|
let mut blocks: Vec<Block> = Vec::new();
|
||||||
let mut nodes: Vec<AvailableNodes> = Vec::new();
|
let mut nodes: Vec<AvailableNodes> = Vec::new();
|
||||||
let dnodes = get_data_nodes(&conn);
|
let dnodes = get_data_nodes(&conn);
|
||||||
@ -201,7 +199,7 @@ fn get_data_nodes(conn: &Connection) -> Vec<DataNode> {
|
|||||||
nodes
|
nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_file(conn: &Connection, fname: &String, fsize: i32) -> bool {
|
fn add_file(conn: &Connection, fname: &String, fsize: i64) -> bool {
|
||||||
let file_exists = conn.query_row(
|
let file_exists = conn.query_row(
|
||||||
"SELECT fid FROM inode WHERE fname = ?1",
|
"SELECT fid FROM inode WHERE fname = ?1",
|
||||||
&[&fname as &ToSql],
|
&[&fname as &ToSql],
|
||||||
|
@ -46,7 +46,7 @@ pub struct NodeRegistration {
|
|||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct AddFile {
|
pub struct AddFile {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub size: u32
|
pub size: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user