feat: call individual RPC methods without the JSON hack in test script

This commit is contained in:
Aravinth Manivannan 2023-12-27 22:57:14 +05:30
parent 3ad3d280d9
commit 67051bc187
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
4 changed files with 286 additions and 93 deletions

View File

@ -14,7 +14,7 @@ _sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0c\x64\x63\x61\x63he.proto\x12\x06\x64\x63\x61\x63he\"?\n\x05Level\x12\x1a\n\x11visitor_threshold\x18\xad\x02 \x01(\r\x12\x1a\n\x11\x64ifficulty_factor\x18\xae\x02 \x01(\r\")\n\x07\x44\x65\x66\x65nse\x12\x1e\n\x06levels\x18\x91\x03 \x03(\x0b\x32\r.dcache.Level\"\\\n\x08MCaptcha\x12\x1a\n\x11visitor_threshold\x18\xf5\x03 \x01(\r\x12\x11\n\x08\x64uration\x18\xf6\x03 \x01(\x04\x12!\n\x07\x64\x65\x66\x65nse\x18\xf7\x03 \x01(\x0b\x32\x0f.dcache.Defense\">\n\nAddCaptcha\x12\x0b\n\x02id\x18\xd9\x04 \x01(\t\x12#\n\x08mcaptcha\x18\xda\x04 \x01(\x0b\x32\x10.dcache.MCaptcha\"2\n\rRenameCaptcha\x12\r\n\x04name\x18\xbd\x05 \x01(\t\x12\x12\n\trename_to\x18\xbe\x05 \x01(\t\"X\n\x08\x43\x61\x63hePoW\x12\x0f\n\x06string\x18\xa1\x06 \x01(\t\x12\x1a\n\x11\x64ifficulty_factor\x18\xa2\x06 \x01(\r\x12\x11\n\x08\x64uration\x18\xa3\x06 \x01(\x04\x12\x0c\n\x03key\x18\xa4\x06 \x01(\t\">\n\x0b\x43\x61\x63heResult\x12\x0e\n\x05token\x18\xb1\x06 \x01(\t\x12\x0c\n\x03key\x18\xb2\x06 \x01(\t\x12\x11\n\x08\x64uration\x18\xb3\x06 \x01(\x04\"%\n\x13\x44\x65leteCaptchaResult\x12\x0e\n\x05token\x18\xb5\x06 \x01(\t\"\xd4\x02\n\rDcacheRequest\x12\x14\n\nAddVisitor\x18\x01 \x01(\tH\x00\x12)\n\x0b\x61\x64\x64_captcha\x18\x02 \x01(\x0b\x32\x12.dcache.AddCaptchaH\x00\x12/\n\x0erename_captcha\x18\x03 \x01(\x0b\x32\x15.dcache.RenameCaptchaH\x00\x12\x18\n\x0eremove_captcha\x18\x04 \x01(\tH\x00\x12%\n\tcache_pow\x18\x05 \x01(\x0b\x32\x10.dcache.CachePoWH\x00\x12\x14\n\ndelete_pow\x18\x06 \x01(\tH\x00\x12+\n\x0c\x63\x61\x63he_result\x18\x07 \x01(\x0b\x32\x13.dcache.CacheResultH\x00\x12<\n\x15\x64\x65lete_captcha_result\x18\x08 \x01(\x0b\x32\x1b.dcache.DeleteCaptchaResultH\x00\x42\x0f\n\rDcacheRequest\"A\n\x10\x41\x64\x64VisitorResult\x12\x11\n\x08\x64uration\x18\x85\x07 \x01(\x04\x12\x1a\n\x11\x64ifficulty_factor\x18\x86\x07 \x01(\r\"S\n\x16OptionAddVisitorResult\x12.\n\x06result\x18\x8f\x07 \x01(\x0b\x32\x18.dcache.AddVisitorResultH\x00\x88\x01\x01\x42\t\n\x07_result\"x\n\x0e\x44\x63\x61\x63heResponse\x12\x43\n\x19option_add_visitor_result\x18\x01 \x01(\x0b\x32\x1e.dcache.OptionAddVisitorResultH\x00\x12\x0f\n\x05\x65mpty\x18\x02 \x01(\rH\x00\x42\x10\n\x0e\x44\x63\x61\x63heResponse\"\x1b\n\x0bRaftRequest\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\t\"(\n\tRaftReply\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\t\x12\r\n\x05\x65rror\x18\x02 \x01(\t\"#\n\x07Learner\x12\n\n\x02id\x18\x01 \x01(\x04\x12\x0c\n\x04\x61\x64\x64r\x18\x02 \x01(\t2\xcf\x02\n\rDcacheService\x12\x32\n\nAddLearner\x12\x0f.dcache.Learner\x1a\x11.dcache.RaftReply\"\x00\x12\x31\n\x05Write\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReply\"\x00\x12\x33\n\x07\x46orward\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReply\"\x00\x12\x37\n\rAppendEntries\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReply\x12\x39\n\x0fInstallSnapshot\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReply\x12.\n\x04vote\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReplyb\x06proto3')
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0c\x64\x63\x61\x63he.proto\x12\x06\x64\x63\x61\x63he\"?\n\x05Level\x12\x1a\n\x11visitor_threshold\x18\xad\x02 \x01(\r\x12\x1a\n\x11\x64ifficulty_factor\x18\xae\x02 \x01(\r\")\n\x07\x44\x65\x66\x65nse\x12\x1e\n\x06levels\x18\x91\x03 \x03(\x0b\x32\r.dcache.Level\"@\n\x08MCaptcha\x12\x11\n\x08\x64uration\x18\xf6\x03 \x01(\x04\x12!\n\x07\x64\x65\x66\x65nse\x18\xf7\x03 \x01(\x0b\x32\x0f.dcache.Defense\"E\n\x11\x41\x64\x64\x43\x61ptchaRequest\x12\x0b\n\x02id\x18\xd9\x04 \x01(\t\x12#\n\x08mcaptcha\x18\xda\x04 \x01(\x0b\x32\x10.dcache.MCaptcha\"9\n\x14RenameCaptchaRequest\x12\r\n\x04name\x18\xbd\x05 \x01(\t\x12\x12\n\trename_to\x18\xbe\x05 \x01(\t\"_\n\x0f\x43\x61\x63hePowRequest\x12\x0f\n\x06string\x18\xa1\x06 \x01(\t\x12\x1a\n\x11\x64ifficulty_factor\x18\xa2\x06 \x01(\r\x12\x11\n\x08\x64uration\x18\xa3\x06 \x01(\x04\x12\x0c\n\x03key\x18\xa4\x06 \x01(\t\"E\n\x12\x43\x61\x63heResultRequest\x12\x0e\n\x05token\x18\xb1\x06 \x01(\t\x12\x0c\n\x03key\x18\xb2\x06 \x01(\t\x12\x11\n\x08\x64uration\x18\xb3\x06 \x01(\x04\",\n\x1a\x44\x65leteCaptchaResultRequest\x12\x0e\n\x05token\x18\xb5\x06 \x01(\t\"\x17\n\tCaptchaID\x12\n\n\x02id\x18\x01 \x01(\t\"\x12\n\x04PoID\x12\n\n\x02id\x18\x01 \x01(\t\"A\n\x10\x41\x64\x64VisitorResult\x12\x11\n\x08\x64uration\x18\x85\x07 \x01(\x04\x12\x1a\n\x11\x64ifficulty_factor\x18\x86\x07 \x01(\r\"S\n\x16OptionAddVisitorResult\x12.\n\x06result\x18\x8f\x07 \x01(\x0b\x32\x18.dcache.AddVisitorResultH\x00\x88\x01\x01\x42\t\n\x07_result\"\x1b\n\x0bRaftRequest\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\t\"(\n\tRaftReply\x12\x0c\n\x04\x64\x61ta\x18\x01 \x01(\t\x12\r\n\x05\x65rror\x18\x02 \x01(\t\"#\n\x07Learner\x12\n\n\x02id\x18\x01 \x01(\x04\x12\x0c\n\x04\x61\x64\x64r\x18\x02 \x01(\t2\xc7\x05\n\rDcacheService\x12<\n\nAddCaptcha\x12\x19.dcache.AddCaptchaRequest\x1a\x11.dcache.RaftReply\"\x00\x12\x41\n\nAddVisitor\x12\x11.dcache.CaptchaID\x1a\x1e.dcache.OptionAddVisitorResult\"\x00\x12\x42\n\rRenameCaptcha\x12\x1c.dcache.RenameCaptchaRequest\x1a\x11.dcache.RaftReply\"\x00\x12\x37\n\rRemoveCaptcha\x12\x11.dcache.CaptchaID\x1a\x11.dcache.RaftReply\"\x00\x12\x38\n\x08\x43\x61\x63hePow\x12\x17.dcache.CachePowRequest\x1a\x11.dcache.RaftReply\"\x00\x12>\n\x0b\x43\x61\x63heResult\x12\x1a.dcache.CacheResultRequest\x1a\x11.dcache.RaftReply\"\x00\x12\x32\n\nAddLearner\x12\x0f.dcache.Learner\x1a\x11.dcache.RaftReply\"\x00\x12\x31\n\x05Write\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReply\"\x00\x12\x33\n\x07\x46orward\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReply\"\x00\x12\x37\n\rAppendEntries\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReply\x12\x39\n\x0fInstallSnapshot\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReply\x12.\n\x04vote\x12\x13.dcache.RaftRequest\x1a\x11.dcache.RaftReplyb\x06proto3')
_globals = globals()
_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals)
@ -26,31 +26,31 @@ if _descriptor._USE_C_DESCRIPTORS == False:
_globals['_DEFENSE']._serialized_start=89
_globals['_DEFENSE']._serialized_end=130
_globals['_MCAPTCHA']._serialized_start=132
_globals['_MCAPTCHA']._serialized_end=224
_globals['_ADDCAPTCHA']._serialized_start=226
_globals['_ADDCAPTCHA']._serialized_end=288
_globals['_RENAMECAPTCHA']._serialized_start=290
_globals['_RENAMECAPTCHA']._serialized_end=340
_globals['_CACHEPOW']._serialized_start=342
_globals['_CACHEPOW']._serialized_end=430
_globals['_CACHERESULT']._serialized_start=432
_globals['_CACHERESULT']._serialized_end=494
_globals['_DELETECAPTCHARESULT']._serialized_start=496
_globals['_DELETECAPTCHARESULT']._serialized_end=533
_globals['_DCACHEREQUEST']._serialized_start=536
_globals['_DCACHEREQUEST']._serialized_end=876
_globals['_ADDVISITORRESULT']._serialized_start=878
_globals['_ADDVISITORRESULT']._serialized_end=943
_globals['_OPTIONADDVISITORRESULT']._serialized_start=945
_globals['_OPTIONADDVISITORRESULT']._serialized_end=1028
_globals['_DCACHERESPONSE']._serialized_start=1030
_globals['_DCACHERESPONSE']._serialized_end=1150
_globals['_RAFTREQUEST']._serialized_start=1152
_globals['_RAFTREQUEST']._serialized_end=1179
_globals['_RAFTREPLY']._serialized_start=1181
_globals['_RAFTREPLY']._serialized_end=1221
_globals['_LEARNER']._serialized_start=1223
_globals['_LEARNER']._serialized_end=1258
_globals['_DCACHESERVICE']._serialized_start=1261
_globals['_DCACHESERVICE']._serialized_end=1596
_globals['_MCAPTCHA']._serialized_end=196
_globals['_ADDCAPTCHAREQUEST']._serialized_start=198
_globals['_ADDCAPTCHAREQUEST']._serialized_end=267
_globals['_RENAMECAPTCHAREQUEST']._serialized_start=269
_globals['_RENAMECAPTCHAREQUEST']._serialized_end=326
_globals['_CACHEPOWREQUEST']._serialized_start=328
_globals['_CACHEPOWREQUEST']._serialized_end=423
_globals['_CACHERESULTREQUEST']._serialized_start=425
_globals['_CACHERESULTREQUEST']._serialized_end=494
_globals['_DELETECAPTCHARESULTREQUEST']._serialized_start=496
_globals['_DELETECAPTCHARESULTREQUEST']._serialized_end=540
_globals['_CAPTCHAID']._serialized_start=542
_globals['_CAPTCHAID']._serialized_end=565
_globals['_POID']._serialized_start=567
_globals['_POID']._serialized_end=585
_globals['_ADDVISITORRESULT']._serialized_start=587
_globals['_ADDVISITORRESULT']._serialized_end=652
_globals['_OPTIONADDVISITORRESULT']._serialized_start=654
_globals['_OPTIONADDVISITORRESULT']._serialized_end=737
_globals['_RAFTREQUEST']._serialized_start=739
_globals['_RAFTREQUEST']._serialized_end=766
_globals['_RAFTREPLY']._serialized_start=768
_globals['_RAFTREPLY']._serialized_end=808
_globals['_LEARNER']._serialized_start=810
_globals['_LEARNER']._serialized_end=845
_globals['_DCACHESERVICE']._serialized_start=848
_globals['_DCACHESERVICE']._serialized_end=1559
# @@protoc_insertion_point(module_scope)

View File

@ -20,16 +20,14 @@ class Defense(_message.Message):
def __init__(self, levels: _Optional[_Iterable[_Union[Level, _Mapping]]] = ...) -> None: ...
class MCaptcha(_message.Message):
__slots__ = ("visitor_threshold", "duration", "defense")
VISITOR_THRESHOLD_FIELD_NUMBER: _ClassVar[int]
__slots__ = ("duration", "defense")
DURATION_FIELD_NUMBER: _ClassVar[int]
DEFENSE_FIELD_NUMBER: _ClassVar[int]
visitor_threshold: int
duration: int
defense: Defense
def __init__(self, visitor_threshold: _Optional[int] = ..., duration: _Optional[int] = ..., defense: _Optional[_Union[Defense, _Mapping]] = ...) -> None: ...
def __init__(self, duration: _Optional[int] = ..., defense: _Optional[_Union[Defense, _Mapping]] = ...) -> None: ...
class AddCaptcha(_message.Message):
class AddCaptchaRequest(_message.Message):
__slots__ = ("id", "mcaptcha")
ID_FIELD_NUMBER: _ClassVar[int]
MCAPTCHA_FIELD_NUMBER: _ClassVar[int]
@ -37,7 +35,7 @@ class AddCaptcha(_message.Message):
mcaptcha: MCaptcha
def __init__(self, id: _Optional[str] = ..., mcaptcha: _Optional[_Union[MCaptcha, _Mapping]] = ...) -> None: ...
class RenameCaptcha(_message.Message):
class RenameCaptchaRequest(_message.Message):
__slots__ = ("name", "rename_to")
NAME_FIELD_NUMBER: _ClassVar[int]
RENAME_TO_FIELD_NUMBER: _ClassVar[int]
@ -45,7 +43,7 @@ class RenameCaptcha(_message.Message):
rename_to: str
def __init__(self, name: _Optional[str] = ..., rename_to: _Optional[str] = ...) -> None: ...
class CachePoW(_message.Message):
class CachePowRequest(_message.Message):
__slots__ = ("string", "difficulty_factor", "duration", "key")
STRING_FIELD_NUMBER: _ClassVar[int]
DIFFICULTY_FACTOR_FIELD_NUMBER: _ClassVar[int]
@ -57,7 +55,7 @@ class CachePoW(_message.Message):
key: str
def __init__(self, string: _Optional[str] = ..., difficulty_factor: _Optional[int] = ..., duration: _Optional[int] = ..., key: _Optional[str] = ...) -> None: ...
class CacheResult(_message.Message):
class CacheResultRequest(_message.Message):
__slots__ = ("token", "key", "duration")
TOKEN_FIELD_NUMBER: _ClassVar[int]
KEY_FIELD_NUMBER: _ClassVar[int]
@ -67,31 +65,23 @@ class CacheResult(_message.Message):
duration: int
def __init__(self, token: _Optional[str] = ..., key: _Optional[str] = ..., duration: _Optional[int] = ...) -> None: ...
class DeleteCaptchaResult(_message.Message):
class DeleteCaptchaResultRequest(_message.Message):
__slots__ = ("token",)
TOKEN_FIELD_NUMBER: _ClassVar[int]
token: str
def __init__(self, token: _Optional[str] = ...) -> None: ...
class DcacheRequest(_message.Message):
__slots__ = ("AddVisitor", "add_captcha", "rename_captcha", "remove_captcha", "cache_pow", "delete_pow", "cache_result", "delete_captcha_result")
ADDVISITOR_FIELD_NUMBER: _ClassVar[int]
ADD_CAPTCHA_FIELD_NUMBER: _ClassVar[int]
RENAME_CAPTCHA_FIELD_NUMBER: _ClassVar[int]
REMOVE_CAPTCHA_FIELD_NUMBER: _ClassVar[int]
CACHE_POW_FIELD_NUMBER: _ClassVar[int]
DELETE_POW_FIELD_NUMBER: _ClassVar[int]
CACHE_RESULT_FIELD_NUMBER: _ClassVar[int]
DELETE_CAPTCHA_RESULT_FIELD_NUMBER: _ClassVar[int]
AddVisitor: str
add_captcha: AddCaptcha
rename_captcha: RenameCaptcha
remove_captcha: str
cache_pow: CachePoW
delete_pow: str
cache_result: CacheResult
delete_captcha_result: DeleteCaptchaResult
def __init__(self, AddVisitor: _Optional[str] = ..., add_captcha: _Optional[_Union[AddCaptcha, _Mapping]] = ..., rename_captcha: _Optional[_Union[RenameCaptcha, _Mapping]] = ..., remove_captcha: _Optional[str] = ..., cache_pow: _Optional[_Union[CachePoW, _Mapping]] = ..., delete_pow: _Optional[str] = ..., cache_result: _Optional[_Union[CacheResult, _Mapping]] = ..., delete_captcha_result: _Optional[_Union[DeleteCaptchaResult, _Mapping]] = ...) -> None: ...
class CaptchaID(_message.Message):
__slots__ = ("id",)
ID_FIELD_NUMBER: _ClassVar[int]
id: str
def __init__(self, id: _Optional[str] = ...) -> None: ...
class PoID(_message.Message):
__slots__ = ("id",)
ID_FIELD_NUMBER: _ClassVar[int]
id: str
def __init__(self, id: _Optional[str] = ...) -> None: ...
class AddVisitorResult(_message.Message):
__slots__ = ("duration", "difficulty_factor")
@ -107,14 +97,6 @@ class OptionAddVisitorResult(_message.Message):
result: AddVisitorResult
def __init__(self, result: _Optional[_Union[AddVisitorResult, _Mapping]] = ...) -> None: ...
class DcacheResponse(_message.Message):
__slots__ = ("option_add_visitor_result", "empty")
OPTION_ADD_VISITOR_RESULT_FIELD_NUMBER: _ClassVar[int]
EMPTY_FIELD_NUMBER: _ClassVar[int]
option_add_visitor_result: OptionAddVisitorResult
empty: int
def __init__(self, option_add_visitor_result: _Optional[_Union[OptionAddVisitorResult, _Mapping]] = ..., empty: _Optional[int] = ...) -> None: ...
class RaftRequest(_message.Message):
__slots__ = ("data",)
DATA_FIELD_NUMBER: _ClassVar[int]

View File

@ -14,6 +14,36 @@ class DcacheServiceStub(object):
Args:
channel: A grpc.Channel.
"""
self.AddCaptcha = channel.unary_unary(
'/dcache.DcacheService/AddCaptcha',
request_serializer=dcache__pb2.AddCaptchaRequest.SerializeToString,
response_deserializer=dcache__pb2.RaftReply.FromString,
)
self.AddVisitor = channel.unary_unary(
'/dcache.DcacheService/AddVisitor',
request_serializer=dcache__pb2.CaptchaID.SerializeToString,
response_deserializer=dcache__pb2.OptionAddVisitorResult.FromString,
)
self.RenameCaptcha = channel.unary_unary(
'/dcache.DcacheService/RenameCaptcha',
request_serializer=dcache__pb2.RenameCaptchaRequest.SerializeToString,
response_deserializer=dcache__pb2.RaftReply.FromString,
)
self.RemoveCaptcha = channel.unary_unary(
'/dcache.DcacheService/RemoveCaptcha',
request_serializer=dcache__pb2.CaptchaID.SerializeToString,
response_deserializer=dcache__pb2.RaftReply.FromString,
)
self.CachePow = channel.unary_unary(
'/dcache.DcacheService/CachePow',
request_serializer=dcache__pb2.CachePowRequest.SerializeToString,
response_deserializer=dcache__pb2.RaftReply.FromString,
)
self.CacheResult = channel.unary_unary(
'/dcache.DcacheService/CacheResult',
request_serializer=dcache__pb2.CacheResultRequest.SerializeToString,
response_deserializer=dcache__pb2.RaftReply.FromString,
)
self.AddLearner = channel.unary_unary(
'/dcache.DcacheService/AddLearner',
request_serializer=dcache__pb2.Learner.SerializeToString,
@ -49,6 +79,42 @@ class DcacheServiceStub(object):
class DcacheServiceServicer(object):
"""Missing associated documentation comment in .proto file."""
def AddCaptcha(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def AddVisitor(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def RenameCaptcha(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def RemoveCaptcha(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def CachePow(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def CacheResult(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def AddLearner(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@ -91,6 +157,36 @@ class DcacheServiceServicer(object):
def add_DcacheServiceServicer_to_server(servicer, server):
rpc_method_handlers = {
'AddCaptcha': grpc.unary_unary_rpc_method_handler(
servicer.AddCaptcha,
request_deserializer=dcache__pb2.AddCaptchaRequest.FromString,
response_serializer=dcache__pb2.RaftReply.SerializeToString,
),
'AddVisitor': grpc.unary_unary_rpc_method_handler(
servicer.AddVisitor,
request_deserializer=dcache__pb2.CaptchaID.FromString,
response_serializer=dcache__pb2.OptionAddVisitorResult.SerializeToString,
),
'RenameCaptcha': grpc.unary_unary_rpc_method_handler(
servicer.RenameCaptcha,
request_deserializer=dcache__pb2.RenameCaptchaRequest.FromString,
response_serializer=dcache__pb2.RaftReply.SerializeToString,
),
'RemoveCaptcha': grpc.unary_unary_rpc_method_handler(
servicer.RemoveCaptcha,
request_deserializer=dcache__pb2.CaptchaID.FromString,
response_serializer=dcache__pb2.RaftReply.SerializeToString,
),
'CachePow': grpc.unary_unary_rpc_method_handler(
servicer.CachePow,
request_deserializer=dcache__pb2.CachePowRequest.FromString,
response_serializer=dcache__pb2.RaftReply.SerializeToString,
),
'CacheResult': grpc.unary_unary_rpc_method_handler(
servicer.CacheResult,
request_deserializer=dcache__pb2.CacheResultRequest.FromString,
response_serializer=dcache__pb2.RaftReply.SerializeToString,
),
'AddLearner': grpc.unary_unary_rpc_method_handler(
servicer.AddLearner,
request_deserializer=dcache__pb2.Learner.FromString,
@ -131,6 +227,108 @@ def add_DcacheServiceServicer_to_server(servicer, server):
class DcacheService(object):
"""Missing associated documentation comment in .proto file."""
@staticmethod
def AddCaptcha(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/dcache.DcacheService/AddCaptcha',
dcache__pb2.AddCaptchaRequest.SerializeToString,
dcache__pb2.RaftReply.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def AddVisitor(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/dcache.DcacheService/AddVisitor',
dcache__pb2.CaptchaID.SerializeToString,
dcache__pb2.OptionAddVisitorResult.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def RenameCaptcha(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/dcache.DcacheService/RenameCaptcha',
dcache__pb2.RenameCaptchaRequest.SerializeToString,
dcache__pb2.RaftReply.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def RemoveCaptcha(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/dcache.DcacheService/RemoveCaptcha',
dcache__pb2.CaptchaID.SerializeToString,
dcache__pb2.RaftReply.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def CachePow(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/dcache.DcacheService/CachePow',
dcache__pb2.CachePowRequest.SerializeToString,
dcache__pb2.RaftReply.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def CacheResult(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/dcache.DcacheService/CacheResult',
dcache__pb2.CacheResultRequest.SerializeToString,
dcache__pb2.RaftReply.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def AddLearner(request,
target,

71
test.py
View File

@ -20,9 +20,11 @@ import requests
import grpc
import json
from dcache_py.dcache_pb2 import RaftRequest
from dcache_py import dcache_pb2 as dcache
from dcache_py.dcache_pb2 import RaftRequest
from dcache_py.dcache_pb2_grpc import DcacheServiceStub
#import dcache_py.dcache_resources
# import dcache_py.dcache_resources
def init(host: str):
@ -88,12 +90,13 @@ host = "localhost:9001"
peers = [(2, "localhost:9002"), (3, "localhost:9003"), (4, "localhost:9004")]
captcha_id = "test_1"
def initialize_cluster():
init(host)
for peer_id, peer in peers:
add_host(host=host, id=peer_id, peer=peer)
switch_to_cluster(host, nodes=[1, 2,3,4])
switch_to_cluster(host, nodes=[1, 2, 3, 4])
add_captcha(host, captcha_id)
add_vote(host, captcha_id)
@ -101,43 +104,53 @@ def initialize_cluster():
add_vote(host, captcha_id)
def grpc_add_vote(stub: DcacheServiceStub, captcha_id: str):
msg = RaftRequest(data=json.dumps({"AddVisitor": captcha_id}))
resp = stub.Write(msg)
msg = dcache.CaptchaID(id=captcha_id)
# msg = RaftRequest(data=json.dumps({"AddVisitor": captcha_id}))
# resp = stub.Write(msg)
resp = stub.AddVisitor(msg)
pprint(resp)
def grpc_add_captcha(stub: DcacheServiceStub, captcha_id: str):
params = {
"AddCaptcha": {
"id": captcha_id,
"mcaptcha": {
"visitor_threshold": 0,
"defense": {
"levels": [
{"visitor_threshold": 50, "difficulty_factor": 500},
{"visitor_threshold": 5000, "difficulty_factor": 50000},
],
"current_visitor_threshold": 0,
},
"duration": 30,
},
}
}
msg = RaftRequest(data = json.dumps(params))
resp = stub.Write(msg)
msg = dcache.AddCaptchaRequest(
id=captcha_id,
mcaptcha=dcache.MCaptcha(
duration=30,
defense=dcache.Defense(
levels=[
dcache.Level(visitor_threshold=50, difficulty_factor=500),
dcache.Level(visitor_threshold=5000, difficulty_factor=50000),
]
),
),
)
# params = {
# "AddCaptcha": {
# "id": captcha_id,
# "mcaptcha": {
# "defense": {
# "levels": [
# {"visitor_threshold": 50, "difficulty_factor": 500},
# {"visitor_threshold": 5000, "difficulty_factor": 50000},
# ],
# "current_visitor_threshold": 0,
# },
# "duration": 30,
# },
# }
# }
# msg = RaftRequest(data = json.dumps(params))
resp = stub.AddCaptcha(msg)
pprint(f"Captcha added {captcha_id}: {resp}")
def grpc_run():
with grpc.insecure_channel(host) as channel:
stub = DcacheServiceStub(channel)
# grpc_add_captcha(stub, captcha_id)
grpc_add_captcha(stub, captcha_id)
grpc_add_vote(stub, captcha_id)
if __name__ == "__main__":
grpc_run()
#add_vote("localhost:9002", captcha_id)
# add_vote("localhost:9002", captcha_id)