Skip to content

JMHOO/ADC

Repository files navigation

Applied Distributed Computing - Project

Protocol

EVERY package contains a header and a JSON payload. The header was composed by 4 variables: version, type, length and reserve. The header.Length = len(Header itself) + len(JSON payload).

4 bytes 4 bytes 4 bytes 4 bytes
version type length reserve JSON payload

For example:

{"jsonkv":"1.0","operate":"put","key":"tomato","value":"999","id":"1"}

The length of JSON itself is 65, and the Header's size is an constant which always be 16. In this case, the bytes stream of this package looks like this:

Version Type Length Reserve JSON payload
0 0 81 0 {"jsonkv":"1.0","operate":"put","key":"1","value":"999","id":"1"}

JSON format request

<-- {"jsonkv": version, "operate": operations, "key": key, "value": value, "id": operation id}

           
version1.0
operateput / get / delete
keystring value
valuestring value
idoperation id -- generated by client

Example: {"jsonkv":"1.0","operate":"put","key":"1","value":"999","id":"1"}

JSON format response

--> {"jsonkv": version, "result": {"value": value, "code": code, "message": message}, "id": operation id}

           
version1.0
result
result - valueonly 'get' operation will return value
otherwise value = 0 or empty
result - code success : code == 0
errors: code > 0
result - messagesuccess : message is empty
errors: server will explain
idoperation id -- generated by client

Example: {"jsonkv": "1.0", "result": {"value": "0", "code": "1000", "message": "key does not exist.“, "id": ”1“}

batch operations

[  

{"jsonkv":"1.0","operate":"put","key":"1","value":"999","id":"1"},

{"jsonkv":"1.0","operate":"get","key":"2“,"value":"","id":"2"}

]

batch operations response

[

{"jsonkv": "1.0", "result": {"value":"0", "code":"0", "message": "put operation success"}, "id": "1"},

 

{"jsonkv": "1.0", "result": {"value":"999", "code":"0", "message": "get operation success"}, "id": "2"}

]

Discovery JSON format request

<-- {"jsonagent": version, "operate": operations, "address": server address, "port": TCP server port}

                             
Register
version1.0
operateregister
addressserver address( internet ip or domain name )
tcpportTCP server port
rpcportRPC server port
Unregister
version1.0
operateunregister
GetServerList
version1.0
operategetserverlist
protocoltcp or rpc

Example:
{"jsonagent":"1.0","operate":"register","address":"uw.umx.io","tcpport":"15001","rpcport":"15003"}
{"jsonagent":"1.0","operate":"unregister"}
{"jsonagent":"1.0","operate":"getserverlist","protocol":"tcp"}

Discovery JSON format response

--> {"jsonagent": version, "result": {"value": [{"address":"uw.umx.io","port",15003},], "code": code, "message": message}}

           
version1.0
result
result - valuejson array contains server list
if request is register, value=global server id
result - code success : code == 0
errors: code > 0
result - messagesuccess : message is empty
errors: server will explain

Example:
{"jsonagent":"1.0","result":{"value":"2","code":"0","message":"register success"}}
{"jsonagent":"1.0","result":{"code":"0","message":"unregister success"}}
{"jsonagent":"1.0","result":{"value":[{"address":"uw.umx.io","port":15003}], "code":"0","message":"get tcp/rpc server list success"}}

UDP

Server will check every UDP package, if the package is larger or less than expected, the package will be dropped.

Client should check every response package. If the received package does not match the original length or there is no response under appropriate timeout, client have the responsibility to resend this request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •