Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File permission transfer #155

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cmake_minimum_required(VERSION 3.2)
# There is no C per se in WDT but if you use CXX only here many checks fail
# Version is Major.Minor.YYMMDDX for up to 10 releases per day (X from 0 to 9)
# Minor currently is also the protocol version - has to match with Protocol.cpp
project("WDT" LANGUAGES C CXX VERSION 1.27.1702060)
project("WDT" LANGUAGES C CXX VERSION 1.30.1703270)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will probably have to change the version to 31, as I am using 30 for an encryption fix.


# On MacOS this requires the latest (master) CMake (and/or CMake 3.1.1/3.2)
# WDT itself works fine with C++11 (gcc 4.8 for instance) but more recent folly
Expand Down
13 changes: 9 additions & 4 deletions Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const int Protocol::ENCRYPTION_V1_VERSION = 23;
const int Protocol::INCREMENTAL_TAG_VERIFICATION_VERSION = 25;
const int Protocol::DELETE_CMD_VERSION = 26;
const int Protocol::VARINT_CHANGE = 27;
const int Protocol::KEEP_PERMISSION = 30;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PRESERVE_PERMISSION


/* All methods of Protocol class are static (functions) */

Expand Down Expand Up @@ -148,8 +149,10 @@ bool Protocol::encodeHeader(int senderProtocolVersion, char *dest, int64_t &off,
encodeVarI64C(dest, umax, off, blockDetails.seqId) &&
encodeVarI64C(dest, umax, off, blockDetails.dataSize) &&
encodeVarI64C(dest, umax, off, blockDetails.offset) &&
encodeVarI64C(dest, umax, off, blockDetails.fileSize) &&
encodeVarI64C(dest, umax, off, blockDetails.permission);
encodeVarI64C(dest, umax, off, blockDetails.fileSize);
if (ok && senderProtocolVersion >= KEEP_PERMISSION) {
ok = encodeVarI64C(dest, umax, off, blockDetails.permission);
}
if (ok && senderProtocolVersion >= HEADER_FLAG_AND_PREV_SEQ_ID_VERSION) {
uint8_t flags = blockDetails.allocationStatus;
if (off >= max) {
Expand Down Expand Up @@ -179,8 +182,10 @@ bool Protocol::decodeHeader(int receiverProtocolVersion, char *src,
decodeInt64C(br, blockDetails.seqId) &&
decodeInt64C(br, blockDetails.dataSize) &&
decodeInt64C(br, blockDetails.offset) &&
decodeInt64C(br, blockDetails.fileSize) &&
decodeInt64C(br, blockDetails.permission);
decodeInt64C(br, blockDetails.fileSize);
if (ok && receiverProtocolVersion >= KEEP_PERMISSION) {
ok = decodeInt64C(br, blockDetails.permission);
}
if (ok && receiverProtocolVersion >= HEADER_FLAG_AND_PREV_SEQ_ID_VERSION) {
if (br.empty()) {
WLOG(ERROR) << "Invalid (too short) input len " << max << " at offset "
Expand Down
2 changes: 2 additions & 0 deletions Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ class Protocol {
static const int DELETE_CMD_VERSION;
/// version from which we switched varint to better one
static const int VARINT_CHANGE;
/// version from which file permission is kept during transfer
static const int KEEP_PERMISSION;

/// Both version, magic number and command byte
enum CMD_MAGIC {
Expand Down
6 changes: 3 additions & 3 deletions WdtConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <fcntl.h>

#define WDT_VERSION_MAJOR 1
#define WDT_VERSION_MINOR 27
#define WDT_VERSION_BUILD 1702060
#define WDT_VERSION_MINOR 30
#define WDT_VERSION_BUILD 1703270
// Add -fbcode to version str
#define WDT_VERSION_STR "1.27.1702060-fbcode"
#define WDT_VERSION_STR "1.30.1703270-fbcode"
// Tie minor and proto version
#define WDT_PROTOCOL_VERSION WDT_VERSION_MINOR

Expand Down
19 changes: 9 additions & 10 deletions test/ProtocolTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void testHeader() {

char buf[128];
int64_t off = 0;
Protocol::encodeHeader(Protocol::HEADER_FLAG_AND_PREV_SEQ_ID_VERSION, buf,
Protocol::encodeHeader(Protocol::KEEP_PERMISSION, buf,
off, sizeof(buf), bd);
EXPECT_EQ(off,
bd.fileName.size() + 1 + 1 + 1 + 1 + 1 + 1 +
Expand All @@ -39,8 +39,8 @@ void testHeader() {
BlockDetails nbd;
int64_t noff = 0;
bool success =
Protocol::decodeHeader(Protocol::HEADER_FLAG_AND_PREV_SEQ_ID_VERSION, buf,
noff, sizeof(buf), nbd);
Protocol::decodeHeader(Protocol::KEEP_PERMISSION, buf, noff, sizeof(buf),
nbd);
EXPECT_TRUE(success);
EXPECT_EQ(noff, off);
EXPECT_EQ(nbd.fileName, bd.fileName);
Expand All @@ -53,14 +53,14 @@ void testHeader() {
noff = 0;
// exact size:
success = Protocol::decodeHeader(
Protocol::HEADER_FLAG_AND_PREV_SEQ_ID_VERSION, buf, noff, off, nbd);
Protocol::KEEP_PERMISSION, buf, noff, off, nbd);
EXPECT_TRUE(success);

WLOG(INFO) << "error tests, expect errors";
// too short
noff = 0;
success = Protocol::decodeHeader(
Protocol::HEADER_FLAG_AND_PREV_SEQ_ID_VERSION, buf, noff, off - 1, nbd);
Protocol::KEEP_PERMISSION, buf, noff, off - 1, nbd);
EXPECT_FALSE(success);

// Long size:
Expand All @@ -74,15 +74,14 @@ void testHeader() {
bd.prevSeqId = 10;

off = 0;
Protocol::encodeHeader(Protocol::HEADER_FLAG_AND_PREV_SEQ_ID_VERSION, buf,
off, sizeof(buf), bd);
Protocol::encodeHeader(Protocol::KEEP_PERMISSION, buf, off, sizeof(buf), bd);
EXPECT_EQ(off,
bd.fileName.size() + 1 + 1 + 6 + 1 + 2 + 1 + 1 +
2); // 1 byte variant for id len and size
noff = 0;
success =
Protocol::decodeHeader(Protocol::HEADER_FLAG_AND_PREV_SEQ_ID_VERSION, buf,
noff, sizeof(buf), nbd);
Protocol::decodeHeader(Protocol::KEEP_PERMISSION, buf, noff, sizeof(buf),
nbd);
EXPECT_TRUE(success);
EXPECT_EQ(noff, off);
EXPECT_EQ(nbd.fileName, bd.fileName);
Expand All @@ -97,7 +96,7 @@ void testHeader() {
// too short for size encoding:
noff = 0;
success = Protocol::decodeHeader(
Protocol::HEADER_FLAG_AND_PREV_SEQ_ID_VERSION, buf, noff, off - 2, nbd);
Protocol::KEEP_PERMISSION, buf, noff, off - 2, nbd);
EXPECT_FALSE(success);
}

Expand Down