Commit 2a8056e6 authored by gejun's avatar gejun

polish code related to redis-auth

parent 035cce37
......@@ -116,7 +116,7 @@ friend void policy::ProcessMongoRequest(InputMessageBase*);
static const uint32_t FLAGS_PB_BYTES_TO_BASE64 = (1 << 11);
static const uint32_t FLAGS_ALLOW_DONE_TO_RUN_IN_PLACE = (1 << 12);
static const uint32_t FLAGS_USED_BY_RPC = (1 << 13);
static const uint32_t FLAGS_REQUEST_WITH_AUTH = (1 << 14);
static const uint32_t FLAGS_REQUEST_WITH_AUTH = (1 << 15);
public:
Controller();
......
......@@ -125,11 +125,9 @@ public:
void set_readable_progressive_attachment(ReadableProgressiveAttachment* s)
{ _cntl->_rpa.reset(s); }
ControllerPrivateAccessor &set_with_auth(bool with_auth) {
_cntl->set_flag(Controller::FLAGS_REQUEST_WITH_AUTH, with_auth);
return *this;
void add_with_auth() {
_cntl->add_flag(Controller::FLAGS_REQUEST_WITH_AUTH);
}
bool with_auth() const { return _cntl->has_flag(Controller::FLAGS_REQUEST_WITH_AUTH); }
private:
Controller* _cntl;
};
......
......@@ -24,7 +24,7 @@ namespace policy {
// Request to redis for authentication.
class RedisAuthenticator : public Authenticator {
public:
public:
RedisAuthenticator(const std::string& passwd)
: passwd_(passwd) {}
......@@ -35,7 +35,7 @@ class RedisAuthenticator : public Authenticator {
return 0;
}
private:
private:
const std::string passwd_;
};
......
......@@ -188,9 +188,7 @@ void PackRedisRequest(butil::IOBuf* buf,
return cntl->SetFailed(EREQUEST, "Fail to generate credential");
}
buf->append(auth_str);
ControllerPrivateAccessor(cntl).set_with_auth(true);
} else {
ControllerPrivateAccessor(cntl).set_with_auth(false);
ControllerPrivateAccessor(cntl).add_with_auth();
}
buf->append(request);
......
......@@ -86,7 +86,6 @@ BRPC_VALIDATE_GFLAG(connect_timeout_as_unreachable,
validate_connect_timeout_as_unreachable);
const int WAIT_EPOLLOUT_TIMEOUT_MS = 50;
static const uint32_t REDIS_AUTH_FLAG = (1ul << 15);
#ifdef BAIDU_INTERNAL
#define BRPC_AUXTHREAD_ATTR \
......@@ -305,9 +304,12 @@ struct BAIDU_CACHELINE_ALIGNMENT Socket::WriteRequest {
Socket* socket;
uint32_t pipelined_count() const {
return (_pc_and_udmsg >> 48) & 0xFFFF;
return (_pc_and_udmsg >> 48) & 0x7FFF;
}
void clear_pipelined_count() {
bool is_with_auth() const {
return _pc_and_udmsg & 0x8000000000000000ULL;
}
void clear_pipelined_count_and_with_auth() {
_pc_and_udmsg &= 0xFFFFFFFFFFFFULL;
}
SocketMessage* user_message() const {
......@@ -318,8 +320,8 @@ struct BAIDU_CACHELINE_ALIGNMENT Socket::WriteRequest {
}
void set_pipelined_count_and_user_message(
uint32_t pc, SocketMessage* msg, bool with_auth) {
if (pc != 0 && with_auth) {
pc |= REDIS_AUTH_FLAG;
if (with_auth) {
pc |= (1 << 15);
}
_pc_and_udmsg = ((uint64_t)pc << 48) | (uint64_t)(uintptr_t)msg;
}
......@@ -371,10 +373,10 @@ void Socket::WriteRequest::Setup(Socket* s) {
// which is common in cache servers: memcache, redis...
// The struct will be popped when reading a message from the socket.
PipelinedInfo pi;
pi.count = pc & (~REDIS_AUTH_FLAG);
pi.with_auth = pc & REDIS_AUTH_FLAG;
pi.count = pc;
pi.with_auth = is_with_auth();
pi.id_wait = id_wait;
clear_pipelined_count(); // avoid being pushed again
clear_pipelined_count_and_with_auth(); // avoid being pushed again
s->PushPipelinedInfo(pi);
}
}
......
......@@ -215,15 +215,20 @@ public:
// Default: 0
uint32_t pipelined_count;
// [Only effective when pipelined_count is non-zero]
// The request contains authenticating information which will be
// responded by the server and processed specially when dealing
// with the response.
bool with_auth;
// Do not return EOVERCROWDED
// Default: false
bool ignore_eovercrowded;
bool with_auth;
WriteOptions()
: id_wait(INVALID_BTHREAD_ID), abstime(NULL)
, pipelined_count(0), ignore_eovercrowded(false), with_auth(false) {}
, pipelined_count(0), with_auth(false)
, ignore_eovercrowded(false) {}
};
int Write(butil::IOBuf *msg, const WriteOptions* options = NULL);
......
// Copyright (c) 2014 Baidu, Inc.
// Date: Thu Jun 11 14:30:07 CST 2015
#ifdef BAIDU_INTERNAL
#if defined(BAIDU_INTERNAL)
#include <iostream>
#include "butil/time.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment