-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkInterface.h
80 lines (73 loc) · 3.21 KB
/
NetworkInterface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*************************************************************************
> File Name: NetworkInterface.h
> Author: Weidong, ZHANG
> Mail: [email protected]
> Created Time: Sun 07 Dec 2014 04:16:58 AM PST
************************************************************************/
#ifndef NETWORK_INTERFACE_H
#define NETWORK_INTERFACE_H
#include "Cluster.h"
#include "ClusterHandler.h"
#include "pdfs.h"
namespace pdfs{
class NetworkInterface
{
protected:
Cluster _cluster;
ThreadPool* _workerPool;
public:
/////////////////////MetaData Operation////////////////////////////
// Step 1: Send push/pull metadata request by sockfd
virtual ssize_t sendPushMetadataRequest(int sockfd,
Metadata &metadata) = 0;
virtual ssize_t sendPullMetadataRequest(int sockfd,
Metadata &metadata) = 0;
// Step 2: Send/receive metadata to/from a socket by sockfd
// Invoked by pdfs
virtual ssize_t putMetadata(int sockfd, Metadata &metadata) = 0;
virtual ssize_t getMetadata(int sockfd, Metadata &metadata) = 0;
// Get/Put file metadata:pair<filename, destIP> from/to somewhere
virtual ssize_t pushMetadata(Metadata &metadata, std::string dest) = 0;
virtual ssize_t pullMetadata(Metadata &metadata) = 0;
////////////////////////////////////////////////////////////////////
/////////////////////File Operation/////////////////////////////////
// Step 1: Send push/pull file request by sockfd
// Invoked by pdfs, filename without any path info
virtual ssize_t sendPushFileRequest(int sockfd, Metadata &metadata,
unsigned int headerFlag = 0) = 0;
virtual ssize_t sendPullFileRequest(int sockfd,
std::string filename) = 0;
// Step 2: Send/receive a file to/from a socket
// Invoked by pdfs
virtual ssize_t putFile(int sockfd, std::string filename) = 0;
virtual ssize_t getFile(int sockfd, std::string filename,
size_t file_size) = 0;
// Step 3: 1 + 2 => Push/Pull a file to/from somewhere
// Invoked by pdfsc(as clients)
virtual ssize_t pushFile(std::string filename) = 0;
virtual ssize_t pullFile(std::string filename) = 0;
////////////////////////////////////////////////////////////////////
////////////////////// Backup file ////////////////////////////////
virtual ssize_t pushFile(Metadata &metadata, std::string dest) = 0;
////////////////////////////////////////////////////////////////////
// Verify the transmission
//virtual ssize_t putFileMDCheck() = 0;
//virtual ssize_t getFileMDCheck() = 0;
// Connect for client to connect
ssize_t connect();
// Constructor and Reconstructor
NetworkInterface();
NetworkInterface(Cluster &cluster);
virtual ~NetworkInterface(){
if (nullptr != _workerPool)
{
_workerPool->destroyPool(2);
}
}
Cluster& getCluster()
{
return _cluster;
}
};// end of class NetworkInterface
} // end of namespace pdfs
#endif