Skip to content

Commit

Permalink
feat: sync TarsProtocol/servant and TarsProtocol/tup dir
Browse files Browse the repository at this point in the history
  • Loading branch information
lbbniu committed Jun 19, 2023
1 parent 88e9920 commit aebfc12
Show file tree
Hide file tree
Showing 10 changed files with 2,581 additions and 12 deletions.
139 changes: 139 additions & 0 deletions tars/protocol/res/AuthF.tars
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
module authf
{

/*
* local auth
*/
struct BasicAuthInfo
{
1 optional string sObjName;
2 optional string sAccessKey; // AK
3 optional string sSecretKey; // SK plainText
4 optional string sHashSecretKey2; // or SK with sha 2 times, ascii format
};

/*
* The auth message client send
*/
struct BasicAuthPackage
{
1 require string sObjName;
2 require string sAccessKey; // AK
3 require long iTime; // timestamp
4 optional string sHashMethod = "sha1";

// how to use sign
// 1. tmpKey = md5sum(secret2 | timestamp); all know this 16bytes
// 2. client use tmpKey to enc secret1, ie, the client knows secret
// 3. server use tmpKey to dec secret1, then sha1(secret1) to check if ok
5 optional string sSignature;
};

// 认证状态:
enum AUTH_STATE
{
AUTH_INIT = -127,
AUTH_SUCC = 0,

AUTH_PROTO_ERR = -100,
AUTH_WRONG_OBJ = -101,
AUTH_WRONG_AK = -102,
AUTH_WRONG_TIME = -103, // wrong timestamp
AUTH_NOT_SUPPORT_ENC = -104,
AUTH_DEC_FAIL = -105, // may be wrong secret key
AUTH_ERROR = -106,
// other positive : user defined intermediate states
// other negative : user defined failed states
};

enum AUTH_TYPE
{
AUTH_TYPENONE = 0, // no auth
AUTH_TYPELOCAL = 1, // local auth
};

/*
* token唯一标识
*/
struct TokenKey
{
1 require string sApplication; // client's app
2 require string sServer; // client's server
3 require string sObjName; // call this obj, name是全局唯一的
};


/*
* 鉴权请求,从client到业务server到AUTH
*/
struct AuthRequest
{
1 require TokenKey sKey;
2 require string sToken;
};

/*鉴权结果是int, state的值*/

/*
* 账号请求,从web到AUTH
*/
struct TokenRequest
{
1 require vector<string> vObjName; // objname是全局唯一的
};

/*
* 账号库,从AUTH到web
*/
struct TokenResponse
{
1 require string sObjName; // objname是全局唯一的
2 require map<string, string> mTokens; // key = 主调方app.server, value = token
};
/*
* req 申请token,从web到AUTH, web ip需要认证,最好是白名单
*/
struct ApplyTokenRequest
{
1 require TokenKey sKey;
};

/*
* rsp
*/
struct ApplyTokenResponse
{
1 require TokenKey sKey;
2 require string sToken;
};

/*
* req 删除token,从web到AUTH, web ip需要认证,最好是白名单
*/
struct DeleteTokenRequest
{
1 require TokenKey sKey;
};


interface Auth
{
/**
* 请求远程鉴权,被调服务向authserver发送token,authserver返回状态
**/
int authProcess(AuthRequest request);
/**
* 请求token账号库
**/
vector<TokenResponse> getTokens(TokenRequest request);
/**
* 创建token
**/
ApplyTokenResponse applyToken(ApplyTokenRequest request);
/**
* del token from web
**/
int deleteToken(DeleteTokenRequest request);
};

};
12 changes: 6 additions & 6 deletions tars/protocol/res/BaseF.tars
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ module basef
////////////////////////////////////////////////////////////////
// 定义协议的版本号

const short TARSVERSION = 0x01;
const short TUPVERSION = 0x03;
const short XMLVERSION = 0x04;
const short JSONVERSION = 0x05;
const short TARSVERSION = 0x01;
const short TUPVERSION = 0x03;
const short XMLVERSION = 0x04;
const short JSONVERSION = 0x05;

////////////////////////////////////////////////////////////////
// 定义消息的类型
Expand All @@ -32,7 +32,7 @@ module basef

// 单向调用
const byte TARSONEWAY = 0x01;

////////////////////////////////////////////////////////////////
// TARS定义的返回码

Expand Down Expand Up @@ -65,6 +65,6 @@ module basef
//const int TARSMESSAGETYPELOADED = 0x20; //按负载值调用程序
//const int TARSMESSAGETYPESETED = 0x40; //按set规则调用类型,此字段后面将不使用
const int TARSMESSAGETYPESETNAME = 0x80; //按setname规则调用类型
const int TARSMESSAGETYPETRACE = 0x100; //trace调用链消息
const int TARSMESSAGETYPETRACE = 0x100; //track调用链消息
/////////////////////////////////////////////////////////////////
};
10 changes: 5 additions & 5 deletions tars/protocol/res/EndpointF.tars
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

Expand All @@ -33,7 +33,7 @@ module endpointf
9 optional int bakFlag;
11 optional int weight;
12 optional int weightType;
13 optional int authType;
13 optional int authType;
};
key[EndpointF, host, port, timeout, istcp, grid, qos, weight, weightType, authType];
};
Expand Down
15 changes: 14 additions & 1 deletion tars/protocol/res/NodeF.tars
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,24 @@ module nodef
*/
int keepAlive(ServerInfo serverInfo);

/**
* 向node定时上报serverInfo(Activing状态)
* @param serverInfo 服务状态
* @return int
*/
int keepActiving(ServerInfo serverInfo);

/**
* 向node上报TARS版本信息
* @param string 版本信息
* @return int
*/
int reportVersion(string app,string serverName,string version);

/**
* 获取最近keepalive的时间戳
* @return 最后一次keepalive的时间戳
*/
unsigned int getLatestKeepAliveTime();
};
};
};
1 change: 1 addition & 0 deletions tars/protocol/res/NotifyF.tars
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct ReportInfo
6 require string sMessage;
7 optional string sThreadId;
8 optional NOTIFYLEVEL eLevel;
9 optional string sNodeName;

};

Expand Down
18 changes: 18 additions & 0 deletions tars/protocol/res/RequestF.tars
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
/**
* Tencent is pleased to support the open source community by making Tars available.
*
* Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

module requestf
{
//请求包体
struct RequestPacket
{
1 require short iVersion;
Expand All @@ -14,6 +31,7 @@ module requestf
10 require map<string, string> status;
};

//响应包体
struct ResponsePacket
{
1 require short iVersion;
Expand Down
Loading

0 comments on commit aebfc12

Please sign in to comment.