Skip to content

Commit 108cb33

Browse files
authored
Merge pull request #482 from TarsCloud/perf/code/style
feat: sync TarsProtocol/servant and TarsProtocol/tup dir
2 parents 88e9920 + aebfc12 commit 108cb33

File tree

10 files changed

+2581
-12
lines changed

10 files changed

+2581
-12
lines changed

tars/protocol/res/AuthF.tars

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
module authf
2+
{
3+
4+
/*
5+
* local auth
6+
*/
7+
struct BasicAuthInfo
8+
{
9+
1 optional string sObjName;
10+
2 optional string sAccessKey; // AK
11+
3 optional string sSecretKey; // SK plainText
12+
4 optional string sHashSecretKey2; // or SK with sha 2 times, ascii format
13+
};
14+
15+
/*
16+
* The auth message client send
17+
*/
18+
struct BasicAuthPackage
19+
{
20+
1 require string sObjName;
21+
2 require string sAccessKey; // AK
22+
3 require long iTime; // timestamp
23+
4 optional string sHashMethod = "sha1";
24+
25+
// how to use sign
26+
// 1. tmpKey = md5sum(secret2 | timestamp); all know this 16bytes
27+
// 2. client use tmpKey to enc secret1, ie, the client knows secret
28+
// 3. server use tmpKey to dec secret1, then sha1(secret1) to check if ok
29+
5 optional string sSignature;
30+
};
31+
32+
// 认证状态:
33+
enum AUTH_STATE
34+
{
35+
AUTH_INIT = -127,
36+
AUTH_SUCC = 0,
37+
38+
AUTH_PROTO_ERR = -100,
39+
AUTH_WRONG_OBJ = -101,
40+
AUTH_WRONG_AK = -102,
41+
AUTH_WRONG_TIME = -103, // wrong timestamp
42+
AUTH_NOT_SUPPORT_ENC = -104,
43+
AUTH_DEC_FAIL = -105, // may be wrong secret key
44+
AUTH_ERROR = -106,
45+
// other positive : user defined intermediate states
46+
// other negative : user defined failed states
47+
};
48+
49+
enum AUTH_TYPE
50+
{
51+
AUTH_TYPENONE = 0, // no auth
52+
AUTH_TYPELOCAL = 1, // local auth
53+
};
54+
55+
/*
56+
* token唯一标识
57+
*/
58+
struct TokenKey
59+
{
60+
1 require string sApplication; // client's app
61+
2 require string sServer; // client's server
62+
3 require string sObjName; // call this obj, name是全局唯一的
63+
};
64+
65+
66+
/*
67+
* 鉴权请求,从client到业务server到AUTH
68+
*/
69+
struct AuthRequest
70+
{
71+
1 require TokenKey sKey;
72+
2 require string sToken;
73+
};
74+
75+
/*鉴权结果是int, state的值*/
76+
77+
/*
78+
* 账号请求,从web到AUTH
79+
*/
80+
struct TokenRequest
81+
{
82+
1 require vector<string> vObjName; // objname是全局唯一的
83+
};
84+
85+
/*
86+
* 账号库,从AUTH到web
87+
*/
88+
struct TokenResponse
89+
{
90+
1 require string sObjName; // objname是全局唯一的
91+
2 require map<string, string> mTokens; // key = 主调方app.server, value = token
92+
};
93+
/*
94+
* req 申请token,从web到AUTH, web ip需要认证,最好是白名单
95+
*/
96+
struct ApplyTokenRequest
97+
{
98+
1 require TokenKey sKey;
99+
};
100+
101+
/*
102+
* rsp
103+
*/
104+
struct ApplyTokenResponse
105+
{
106+
1 require TokenKey sKey;
107+
2 require string sToken;
108+
};
109+
110+
/*
111+
* req 删除token,从web到AUTH, web ip需要认证,最好是白名单
112+
*/
113+
struct DeleteTokenRequest
114+
{
115+
1 require TokenKey sKey;
116+
};
117+
118+
119+
interface Auth
120+
{
121+
/**
122+
* 请求远程鉴权,被调服务向authserver发送token,authserver返回状态
123+
**/
124+
int authProcess(AuthRequest request);
125+
/**
126+
* 请求token账号库
127+
**/
128+
vector<TokenResponse> getTokens(TokenRequest request);
129+
/**
130+
* 创建token
131+
**/
132+
ApplyTokenResponse applyToken(ApplyTokenRequest request);
133+
/**
134+
* del token from web
135+
**/
136+
int deleteToken(DeleteTokenRequest request);
137+
};
138+
139+
};

tars/protocol/res/BaseF.tars

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ module basef
1919
////////////////////////////////////////////////////////////////
2020
// 定义协议的版本号
2121

22-
const short TARSVERSION = 0x01;
23-
const short TUPVERSION = 0x03;
24-
const short XMLVERSION = 0x04;
25-
const short JSONVERSION = 0x05;
22+
const short TARSVERSION = 0x01;
23+
const short TUPVERSION = 0x03;
24+
const short XMLVERSION = 0x04;
25+
const short JSONVERSION = 0x05;
2626

2727
////////////////////////////////////////////////////////////////
2828
// 定义消息的类型
@@ -32,7 +32,7 @@ module basef
3232

3333
// 单向调用
3434
const byte TARSONEWAY = 0x01;
35-
35+
3636
////////////////////////////////////////////////////////////////
3737
// TARS定义的返回码
3838

@@ -65,6 +65,6 @@ module basef
6565
//const int TARSMESSAGETYPELOADED = 0x20; //按负载值调用程序
6666
//const int TARSMESSAGETYPESETED = 0x40; //按set规则调用类型,此字段后面将不使用
6767
const int TARSMESSAGETYPESETNAME = 0x80; //按setname规则调用类型
68-
const int TARSMESSAGETYPETRACE = 0x100; //trace调用链消息
68+
const int TARSMESSAGETYPETRACE = 0x100; //track调用链消息
6969
/////////////////////////////////////////////////////////////////
7070
};

tars/protocol/res/EndpointF.tars

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
*
44
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
55
*
6-
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6+
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
77
* in compliance with the License. You may obtain a copy of the License at
88
*
99
* https://opensource.org/licenses/BSD-3-Clause
1010
*
11-
* Unless required by applicable law or agreed to in writing, software distributed
12-
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* Unless required by applicable law or agreed to in writing, software distributed
12+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
1414
* specific language governing permissions and limitations under the License.
1515
*/
1616

@@ -33,7 +33,7 @@ module endpointf
3333
9 optional int bakFlag;
3434
11 optional int weight;
3535
12 optional int weightType;
36-
13 optional int authType;
36+
13 optional int authType;
3737
};
3838
key[EndpointF, host, port, timeout, istcp, grid, qos, weight, weightType, authType];
3939
};

tars/protocol/res/NodeF.tars

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@ module nodef
3333
*/
3434
int keepAlive(ServerInfo serverInfo);
3535

36+
/**
37+
* 向node定时上报serverInfo(Activing状态)
38+
* @param serverInfo 服务状态
39+
* @return int
40+
*/
41+
int keepActiving(ServerInfo serverInfo);
42+
3643
/**
3744
* 向node上报TARS版本信息
3845
* @param string 版本信息
3946
* @return int
4047
*/
4148
int reportVersion(string app,string serverName,string version);
49+
50+
/**
51+
* 获取最近keepalive的时间戳
52+
* @return 最后一次keepalive的时间戳
53+
*/
54+
unsigned int getLatestKeepAliveTime();
4255
};
43-
};
56+
};

tars/protocol/res/NotifyF.tars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct ReportInfo
7979
6 require string sMessage;
8080
7 optional string sThreadId;
8181
8 optional NOTIFYLEVEL eLevel;
82+
9 optional string sNodeName;
8283

8384
};
8485

tars/protocol/res/RequestF.tars

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1+
/**
2+
* Tencent is pleased to support the open source community by making Tars available.
3+
*
4+
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
7+
* in compliance with the License. You may obtain a copy of the License at
8+
*
9+
* https://opensource.org/licenses/BSD-3-Clause
10+
*
11+
* Unless required by applicable law or agreed to in writing, software distributed
12+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
* specific language governing permissions and limitations under the License.
15+
*/
16+
117
module requestf
218
{
19+
//请求包体
320
struct RequestPacket
421
{
522
1 require short iVersion;
@@ -14,6 +31,7 @@ module requestf
1431
10 require map<string, string> status;
1532
};
1633

34+
//响应包体
1735
struct ResponsePacket
1836
{
1937
1 require short iVersion;

0 commit comments

Comments
 (0)