Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
2a8056e6
Commit
2a8056e6
authored
Dec 06, 2017
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polish code related to redis-auth
parent
035cce37
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
30 deletions
+33
-30
controller.h
src/brpc/controller.h
+1
-1
controller_private_accessor.h
src/brpc/details/controller_private_accessor.h
+2
-4
redis_authenticator.h
src/brpc/policy/redis_authenticator.h
+10
-10
redis_protocol.cpp
src/brpc/policy/redis_protocol.cpp
+1
-3
socket.cpp
src/brpc/socket.cpp
+10
-8
socket.h
src/brpc/socket.h
+8
-3
brpc_redis_unittest.cpp
test/brpc_redis_unittest.cpp
+1
-1
No files found.
src/brpc/controller.h
View file @
2a8056e6
...
@@ -116,7 +116,7 @@ friend void policy::ProcessMongoRequest(InputMessageBase*);
...
@@ -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_PB_BYTES_TO_BASE64
=
(
1
<<
11
);
static
const
uint32_t
FLAGS_ALLOW_DONE_TO_RUN_IN_PLACE
=
(
1
<<
12
);
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_USED_BY_RPC
=
(
1
<<
13
);
static
const
uint32_t
FLAGS_REQUEST_WITH_AUTH
=
(
1
<<
1
4
);
static
const
uint32_t
FLAGS_REQUEST_WITH_AUTH
=
(
1
<<
1
5
);
public
:
public
:
Controller
();
Controller
();
...
...
src/brpc/details/controller_private_accessor.h
View file @
2a8056e6
...
@@ -125,11 +125,9 @@ public:
...
@@ -125,11 +125,9 @@ public:
void
set_readable_progressive_attachment
(
ReadableProgressiveAttachment
*
s
)
void
set_readable_progressive_attachment
(
ReadableProgressiveAttachment
*
s
)
{
_cntl
->
_rpa
.
reset
(
s
);
}
{
_cntl
->
_rpa
.
reset
(
s
);
}
ControllerPrivateAccessor
&
set_with_auth
(
bool
with_auth
)
{
void
add_with_auth
()
{
_cntl
->
set_flag
(
Controller
::
FLAGS_REQUEST_WITH_AUTH
,
with_auth
);
_cntl
->
add_flag
(
Controller
::
FLAGS_REQUEST_WITH_AUTH
);
return
*
this
;
}
}
bool
with_auth
()
const
{
return
_cntl
->
has_flag
(
Controller
::
FLAGS_REQUEST_WITH_AUTH
);
}
private
:
private
:
Controller
*
_cntl
;
Controller
*
_cntl
;
};
};
...
...
src/brpc/policy/redis_authenticator.h
View file @
2a8056e6
...
@@ -24,19 +24,19 @@ namespace policy {
...
@@ -24,19 +24,19 @@ namespace policy {
// Request to redis for authentication.
// Request to redis for authentication.
class
RedisAuthenticator
:
public
Authenticator
{
class
RedisAuthenticator
:
public
Authenticator
{
public
:
public
:
RedisAuthenticator
(
const
std
::
string
&
passwd
)
RedisAuthenticator
(
const
std
::
string
&
passwd
)
:
passwd_
(
passwd
)
{}
:
passwd_
(
passwd
)
{}
int
GenerateCredential
(
std
::
string
*
auth_str
)
const
;
int
GenerateCredential
(
std
::
string
*
auth_str
)
const
;
int
VerifyCredential
(
const
std
::
string
&
,
const
butil
::
EndPoint
&
,
int
VerifyCredential
(
const
std
::
string
&
,
const
butil
::
EndPoint
&
,
brpc
::
AuthContext
*
)
const
{
brpc
::
AuthContext
*
)
const
{
return
0
;
return
0
;
}
}
private
:
private
:
const
std
::
string
passwd_
;
const
std
::
string
passwd_
;
};
};
}
// namespace policy
}
// namespace policy
...
...
src/brpc/policy/redis_protocol.cpp
View file @
2a8056e6
...
@@ -188,9 +188,7 @@ void PackRedisRequest(butil::IOBuf* buf,
...
@@ -188,9 +188,7 @@ void PackRedisRequest(butil::IOBuf* buf,
return
cntl
->
SetFailed
(
EREQUEST
,
"Fail to generate credential"
);
return
cntl
->
SetFailed
(
EREQUEST
,
"Fail to generate credential"
);
}
}
buf
->
append
(
auth_str
);
buf
->
append
(
auth_str
);
ControllerPrivateAccessor
(
cntl
).
set_with_auth
(
true
);
ControllerPrivateAccessor
(
cntl
).
add_with_auth
();
}
else
{
ControllerPrivateAccessor
(
cntl
).
set_with_auth
(
false
);
}
}
buf
->
append
(
request
);
buf
->
append
(
request
);
...
...
src/brpc/socket.cpp
View file @
2a8056e6
...
@@ -86,7 +86,6 @@ BRPC_VALIDATE_GFLAG(connect_timeout_as_unreachable,
...
@@ -86,7 +86,6 @@ BRPC_VALIDATE_GFLAG(connect_timeout_as_unreachable,
validate_connect_timeout_as_unreachable
);
validate_connect_timeout_as_unreachable
);
const
int
WAIT_EPOLLOUT_TIMEOUT_MS
=
50
;
const
int
WAIT_EPOLLOUT_TIMEOUT_MS
=
50
;
static
const
uint32_t
REDIS_AUTH_FLAG
=
(
1ul
<<
15
);
#ifdef BAIDU_INTERNAL
#ifdef BAIDU_INTERNAL
#define BRPC_AUXTHREAD_ATTR \
#define BRPC_AUXTHREAD_ATTR \
...
@@ -305,9 +304,12 @@ struct BAIDU_CACHELINE_ALIGNMENT Socket::WriteRequest {
...
@@ -305,9 +304,12 @@ struct BAIDU_CACHELINE_ALIGNMENT Socket::WriteRequest {
Socket
*
socket
;
Socket
*
socket
;
uint32_t
pipelined_count
()
const
{
uint32_t
pipelined_count
()
const
{
return
(
_pc_and_udmsg
>>
48
)
&
0x
F
FFF
;
return
(
_pc_and_udmsg
>>
48
)
&
0x
7
FFF
;
}
}
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
;
_pc_and_udmsg
&=
0xFFFFFFFFFFFFULL
;
}
}
SocketMessage
*
user_message
()
const
{
SocketMessage
*
user_message
()
const
{
...
@@ -318,8 +320,8 @@ struct BAIDU_CACHELINE_ALIGNMENT Socket::WriteRequest {
...
@@ -318,8 +320,8 @@ struct BAIDU_CACHELINE_ALIGNMENT Socket::WriteRequest {
}
}
void
set_pipelined_count_and_user_message
(
void
set_pipelined_count_and_user_message
(
uint32_t
pc
,
SocketMessage
*
msg
,
bool
with_auth
)
{
uint32_t
pc
,
SocketMessage
*
msg
,
bool
with_auth
)
{
if
(
pc
!=
0
&&
with_auth
)
{
if
(
with_auth
)
{
pc
|=
REDIS_AUTH_FLAG
;
pc
|=
(
1
<<
15
)
;
}
}
_pc_and_udmsg
=
((
uint64_t
)
pc
<<
48
)
|
(
uint64_t
)(
uintptr_t
)
msg
;
_pc_and_udmsg
=
((
uint64_t
)
pc
<<
48
)
|
(
uint64_t
)(
uintptr_t
)
msg
;
}
}
...
@@ -371,10 +373,10 @@ void Socket::WriteRequest::Setup(Socket* s) {
...
@@ -371,10 +373,10 @@ void Socket::WriteRequest::Setup(Socket* s) {
// which is common in cache servers: memcache, redis...
// which is common in cache servers: memcache, redis...
// The struct will be popped when reading a message from the socket.
// The struct will be popped when reading a message from the socket.
PipelinedInfo
pi
;
PipelinedInfo
pi
;
pi
.
count
=
pc
&
(
~
REDIS_AUTH_FLAG
)
;
pi
.
count
=
pc
;
pi
.
with_auth
=
pc
&
REDIS_AUTH_FLAG
;
pi
.
with_auth
=
is_with_auth
()
;
pi
.
id_wait
=
id_wait
;
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
);
s
->
PushPipelinedInfo
(
pi
);
}
}
}
}
...
...
src/brpc/socket.h
View file @
2a8056e6
...
@@ -214,16 +214,21 @@ public:
...
@@ -214,16 +214,21 @@ public:
// Will be queued to implement positional correspondence with responses
// Will be queued to implement positional correspondence with responses
// Default: 0
// Default: 0
uint32_t
pipelined_count
;
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
// Do not return EOVERCROWDED
// Default: false
// Default: false
bool
ignore_eovercrowded
;
bool
ignore_eovercrowded
;
bool
with_auth
;
WriteOptions
()
WriteOptions
()
:
id_wait
(
INVALID_BTHREAD_ID
),
abstime
(
NULL
)
:
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
);
int
Write
(
butil
::
IOBuf
*
msg
,
const
WriteOptions
*
options
=
NULL
);
...
...
test/brpc_redis_unittest.cpp
View file @
2a8056e6
// Copyright (c) 2014 Baidu, Inc.
// Copyright (c) 2014 Baidu, Inc.
// Date: Thu Jun 11 14:30:07 CST 2015
// Date: Thu Jun 11 14:30:07 CST 2015
#if
def BAIDU_INTERNAL
#if
defined(BAIDU_INTERNAL)
#include <iostream>
#include <iostream>
#include "butil/time.h"
#include "butil/time.h"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment