#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “dfslib-shared-p1.h”
#include “proto-src/dfs-service.grpc.pb.h”
#include “dfslib-clientnode-p1.h”
using grpc::Channel;
using grpc::Status;
using grpc::StatusCode;
using grpc::ClientWriter;
using grpc::ClientContext;
using grpc::ClientReader;
// STUDENT INSTRUCTION:
// You may want to add aliases to your namespaced service methods here.
// All of the methods will be under the `dfs_service` namespace.
// For example, if you have a method named MyMethod, add
// the following:
// using dfs_service::MyMethod
DFSClientNodeP1::DFSClientNodeP1() : DFSClientNode() {}
DFSClientNodeP1::~DFSClientNodeP1() noexcept {}
StatusCode DFSClientNodeP1::Store(const std::string &filename) {
// STUDENT INSTRUCTION:
// Add your request to store a file here. This method should
// connect to your gRPC service implementation method
// that can accept and store a file.
// When working with files in gRPC you’ll need to stream
// the file contents, so consider the use of gRPC’s ClientWriter.
// The StatusCode response should be:
// StatusCode::OK – if all went well
// StatusCode::DEADLINE_EXCEEDED – if the deadline timeout occurs
// StatusCode::NOT_FOUND – if the file cannot be found on the client
// StatusCode::CANCELLED otherwise
StatusCode DFSClientNodeP1::Fetch(const std::string &filename) {
// STUDENT INSTRUCTION:
// Add your request to fetch a file here. This method should
// connect to your gRPC service implementation method
// that can accept a file request and return the contents
// of a file from the service.
// As with the store function, you’ll need to stream the
// contents, so consider the use of gRPC’s ClientReader.
// The StatusCode response should be:
// StatusCode::OK – if all went well
// StatusCode::DEADLINE_EXCEEDED – if the deadline timeout occurs
// StatusCode::NOT_FOUND – if the file cannot be found on the server
// StatusCode::CANCELLED otherwise
StatusCode DFSClientNodeP1::Delete(const std::string& filename) {
// STUDENT INSTRUCTION:
// Add your request to delete a file here. Refer to the Part 1
// student instruction for details on the basics.
// The StatusCode response should be:
// StatusCode::OK – if all went well
// StatusCode::DEADLINE_EXCEEDED – if the deadline timeout occurs
// StatusCode::NOT_FOUND – if the file cannot be found on the server
// StatusCode::CANCELLED otherwise
StatusCode DFSClientNodeP1::Stat(const std::string &filename, void* file_status) {
// STUDENT INSTRUCTION:
// Add your request to get the status of a file here. This method should
// retrieve the status of a file on the server. Note that you won’t be
// tested on this method, but you will most likely find that you need
// a way to get the status of a file in order to synchronize later.
// The status might include data such as name, size, mtime, crc, etc.
// The file_status is left as a void* so that you can use it to pass
// a message type that you defined. For instance, may want to use that message
// type after calling Stat from another method.
// The StatusCode response should be:
// StatusCode::OK – if all went well
// StatusCode::DEADLINE_EXCEEDED – if the deadline timeout occurs
// StatusCode::NOT_FOUND – if the file cannot be found on the server
// StatusCode::CANCELLED otherwise
StatusCode DFSClientNodeP1::List(std::map
// STUDENT INSTRUCTION:
// Add your request to list all files here. This method
// should connect to your service’s list method and return
// a list of files using the message type you created.
// The file_map parameter is a simple map of files. You should fill
// the file_map with the list of files you receive with keys as the
// file name and values as the modified time (mtime) of the file
// received from the server.
// The StatusCode response should be:
// StatusCode::OK – if all went well
// StatusCode::DEADLINE_EXCEEDED – if the deadline timeout occurs
// StatusCode::CANCELLED otherwise
// STUDENT INSTRUCTION:
// Add your additional code here, including
// implementations of your client methods