DSFプライベートプロトコル符号化分析
8514 ワード
DSFメッセージのシーケンス化と逆シーケンス解析
DSFフレームワークメッセージのシーケンス化と逆シーケンス化ProtoBuffプロトコルは、NettyのByteBufを拡張することによって実現され、具体的な実装クラス名はcomである.huawei.csc.remoting.common.buf.impl.NettyBuffer
com.huawei.csc.usf.framework.bus.MsgCoderはcomを実現した.huawei.csc.remoting.common.encode.MessageEncoderとcom.huawei.csc.remoting.common.decode.MessageDecoder 2つのインタフェース、com.huawei.csc.usf.framework.bus.DSFMSgCoderはMsgCoderを継承してDSFプロトコルのコーデックを実現した.
プロトコルコーディング
オブジェクトコーディング方式
ID
Type
-1
null
1
string
2
protostaff bytes
3
USFCtxObject
4
byte[]
stringオブジェクトの符号化方法:
length | UTF8 bytes
byte[]オブジェクト符号化方法:
length | bytes
USFCTxObjectオブジェクト符号化方式
USFObjType | Obj
protostaff bytes符号化方式
length | bytes
Obj符号化方法:
id | obj
その他の汎用的な符号化方式:
map符号化方式
mapsize | Key(string) | Value(obj) | key2|value2...
array of obj[]
length |obj1 | obj2
UsfObjType: 0 LOCAL, 1 REMOTE, 2 LOCAL_MANUAL; |
読みやすいように分割子は使用されていません
プロトコルの符号化方式は典型的な変長符号化法である:すべてのオブジェクトの符号化方式はid|objの方式で符号化され、まずbufferにオブジェクトタイプを書き、それから書くオブジェクトをシーケンス化したbytesに続いて、中間の"|"は読みやすいためだけで、区切り記号ではない.string、byte[]はsting、byte[]およびUSFCTxObjectを除き、他のカスタムオブジェクトはprotostaffによるシーケンス化であり、stringbyte[]USFctxObject、Map、Arrayのシーケンス化方法は表を参照し、一般的にLenght|bytesの方法でシーケンス化される.
DSFプロトコル定義:
magic
msgType
msg encode(type val name -> )
4
bindrequest
int MsgLen byte 4 MsgMagic int seqid string payload string version
5
bindresponse,bindVersionV1
int MsgLen byte 5 MsgMagic int seqid string PayLoad
5
bindresponse,otherversion
int MsgLen byte 5 Msg Magic int SeqId Object PayLoad
0
request
int MsgLen byte 0 MsgMagic string ReqId int isAsync :0-> no 1->yes int 0 msgType: 0->request 1->reply string serviceName string operationName Long Long Int : 0L0L0d MsgSeprator Obj[] payload string group map attachement (with sendtime) Object reqobj Object null(0xffffffff) excption
0
reply
int MsgLen byte 0 Msg Magic string ReqId int isAsync int 1 msgType:0->request 1->reply string serviceName string operation Long 0L |Long 0L|int 0 MsgSeprator payload:null(-1,0xfffffffff) string group map attachement(with sendtime) Object rspObj Object exception
msgtype:0 request 1 respons isSync:0 no 1 yes len-4 javaintが32ビットで4つのbyteメッセージの0 xffffffffがnullを表すため
パッケージの分析から見ると、DSFプロトコルは親の設計に従っておらず、magic、servicegroup、src、desなどと書かれており、開発者がマスターの設計に従っていないと推定され、一部簡略化されている.また、自身のプロトコル設計も固定読み書き順序に基づいており、プロトコルの拡張性は高くない.プロトコルコンテンツではintタイプを大量に使用してデータを転送するため,プロトコル圧縮率をさらに向上させることができる.
DSFキャプチャ分析
--request bigend ? 0000008b00000000013100000000000000000000000853657276696365410000000873617948656c6c6f000000000000000000000000000000000000000000000001000000010000000568656c6c6f0000000764656661756c74000000010000000873656e6454696d650000000300000000000000010000000d31353031333739303237393037ffffffffffffffff
--request hex 0 1 2 3 4 5 6 6 8 9 a b c d e f
-----------------------------------------------
00000000 00 00 00 8b 00 00 00 00 01 31 00 00 00 00 00 00 ........ .1......
00000010 00 00 00 00 00 08 53 65 72 76 69 63 65 41 00 00 ......Se rviceA..
00000020 00 08 73 61 79 48 65 6c 6c 6f 00 00 00 00 00 00 ..sayHel lo......
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
00000040 00 01 00 00 00 01 00 00 00 05 68 65 6c 6c 6f 00 ........ ..hello.
00000050 00 00 07 64 65 66 61 75 6c 74 00 00 00 01 00 00 ...defau lt......
00000060 00 08 73 65 6e 64 54 69 6d 65 00 00 00 03 00 00 ..sendTi me......
00000070 00 00 00 00 00 01 00 00 00 0d 31 35 30 31 33 37 ........ ..150137
00000080 39 30 32 37 39 30 37 ff ff ff ff ff ff ff ff 9027907. .......
request解析
0 1 2 3 4 5 6 7 8 9 a b c d e f ascii msg
-----------------------------------------------
00000000 00 00 00 8b|00 00 00 00| 01|31|00 00 00 00|00 00 ........ .1......
package len 8b|msg type 0 |len|id| is async |msg
00000010 00 00|00 00 00 08|53 65 72 76 69 63 65 41|00 00 ......Se rviceA..
send 0 |string len8| S e r v i c e A|str len 8
|Servicename |
00000020 00 08|73 61 79 48 65 6c 6c 6f|00 00 00 00 00 00 ..sayHel lo......
| s a y H e l l o| OL
|operation name |OL 0L 0d seprator
00000030 00 00|00 00 00 00 00 00 00 00|00 00 00 00|00 00 ........ ........
| OL | Od |obj len 1
00000040 00 01|00 00 00 01|00 00 00 05|68 65 6c 6c 6f|00 ........ ..hello.
| obj type 1|string len 5| h e l l o|
|ref objtype|in param |
00000050 00 00 07|64 65 66 61 75 6c 74|00 00 00 01|00 00 ...defau lt......
str len 7| d e f a u l t|map size 1|
|group name |attachment map
00000060 00 08|73 65 6e 64 54 69 6d 65|00 00 00 03|00 00 ..sendTi me......
str len 8| s e n d T i m e| |
|key :sendTime |USFCtxObject|USFOBjType
00000070 00 00|00 00 00 01|00 00 00 0d|31 35 30 31 33 37 ........ ..150137
|string 1| | 1 5 0 1 3 7
|obj type |str len 10 |string content
00000080 39 30 32 37 39 30 37|ff ff ff ff |ff ff ff ff 9027907. .......
9 0 2 7 9 0 8|req obj |exception
--reply 0000008d00000000013100000000000000010000000853657276696365410000000873617948656c6c6f0000000000000000000000000000000000000000ffffffff0000000764656661756c74000000010000000873656e6454696d650000000300000000000000010000000d31353031333739303237393131000000010000000b68656c6c6f3a68656c6c6fffffffff
--reply hex
0 1 2 3 4 5 6 6 8 9 a b c d e f
00000000 00 00 00 8d|00 00 00 00| 01|31|00 00 00 00|00 00 ........ .1......
len 8d |type 0 |len|id|isAsync | msg
00000010 00 01|00 00 00 08|53 65 72 76 69 63 65 41|00 00 ......Se rviceA..
reply 01| str len |servicename |str len
00000020 00 08|73 61 79 48 65 6c 6c 6f|00 00 00 00 00 00 ..sayHel lo......
|operation name | 0L
00000030 00 00|00 00 00 00 00 00 00 00|00 00 00 00|ff ff ........ ........
| 0L | 0d |null -1 reply has in params
00000040 ff ff|00 00 00 07|64 65 66 61 75 6c 74|00 00 00 ......de fault...
| str len 7| d e f a u l t|
|groupname |attachement map size 1
00000050 01|00 00 00 08|73 65 6e 64 54 69 6d 65|00 00 00 .....sen dTime...
|str len | key |obj type usfctxobj 03
00000060 03 |00 00 00 00|00 00 00 01|00 00 00 0d|31 35 30 ........ .....150
| local |obj type string len 0d|
00000070 31 33 37 39 30 32 37 39 31 31|00 00 00 01|00 00 13790279 11......
rsptime |resp obj |
|obj type 1 |string len 0x0b
00000080 00 0b|68 65 6c 6c 6f 3a 68 65 6c 6c 6f|ff ff ff ..hello: hello...
| |Null exception
|response content |
00000090 ff .
以上の研究により、後期にクロス言語でdsfにアクセスでき、詳細なパッケージファイルはtcpを使用してください.port eq 50254、またgiteaにバグがある可能性があり、一部のテーブルを正常に表示できません.
Next:DSF zookeeperのNode組織
構造:DSFCTxObject--type:int(LOCAL,REMOTE,LOCAL_MANUAL)--Obj:protostaff bytes--length:int--ObjectCompressBytes:gziped bytes,protostaff.GraphIOUtil.writeToメソッドはObjectPackのbytesを生成し、gzip---ObjectPack--Object
DSFCTxObject復号方法:
0000008b00000000013100000000000000000000000853657276696365410000000873617948656c6c6f000000000000000000000000000000000000000000000001000000010000000568656c6c6f0000000764656661756c74000000010000000873656e6454696d650000000300000000000000010000000d31353031333739303237393037ffffffffffffffff
0 1 2 3 4 5 6 6 8 9 a b c d e f
-----------------------------------------------
00000000 00 00 00 8b 00 00 00 00 01 31 00 00 00 00 00 00 ........ .1......
00000010 00 00 00 00 00 08 53 65 72 76 69 63 65 41 00 00 ......Se rviceA..
00000020 00 08 73 61 79 48 65 6c 6c 6f 00 00 00 00 00 00 ..sayHel lo......
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
00000040 00 01 00 00 00 01 00 00 00 05 68 65 6c 6c 6f 00 ........ ..hello.
00000050 00 00 07 64 65 66 61 75 6c 74 00 00 00 01 00 00 ...defau lt......
00000060 00 08 73 65 6e 64 54 69 6d 65 00 00 00 03 00 00 ..sendTi me......
00000070 00 00 00 00 00 01 00 00 00 0d 31 35 30 31 33 37 ........ ..150137
00000080 39 30 32 37 39 30 37 ff ff ff ff ff ff ff ff 9027907. .......
0 1 2 3 4 5 6 7 8 9 a b c d e f ascii msg
-----------------------------------------------
00000000 00 00 00 8b|00 00 00 00| 01|31|00 00 00 00|00 00 ........ .1......
package len 8b|msg type 0 |len|id| is async |msg
00000010 00 00|00 00 00 08|53 65 72 76 69 63 65 41|00 00 ......Se rviceA..
send 0 |string len8| S e r v i c e A|str len 8
|Servicename |
00000020 00 08|73 61 79 48 65 6c 6c 6f|00 00 00 00 00 00 ..sayHel lo......
| s a y H e l l o| OL
|operation name |OL 0L 0d seprator
00000030 00 00|00 00 00 00 00 00 00 00|00 00 00 00|00 00 ........ ........
| OL | Od |obj len 1
00000040 00 01|00 00 00 01|00 00 00 05|68 65 6c 6c 6f|00 ........ ..hello.
| obj type 1|string len 5| h e l l o|
|ref objtype|in param |
00000050 00 00 07|64 65 66 61 75 6c 74|00 00 00 01|00 00 ...defau lt......
str len 7| d e f a u l t|map size 1|
|group name |attachment map
00000060 00 08|73 65 6e 64 54 69 6d 65|00 00 00 03|00 00 ..sendTi me......
str len 8| s e n d T i m e| |
|key :sendTime |USFCtxObject|USFOBjType
00000070 00 00|00 00 00 01|00 00 00 0d|31 35 30 31 33 37 ........ ..150137
|string 1| | 1 5 0 1 3 7
|obj type |str len 10 |string content
00000080 39 30 32 37 39 30 37|ff ff ff ff |ff ff ff ff 9027907. .......
9 0 2 7 9 0 8|req obj |exception
0000008d00000000013100000000000000010000000853657276696365410000000873617948656c6c6f0000000000000000000000000000000000000000ffffffff0000000764656661756c74000000010000000873656e6454696d650000000300000000000000010000000d31353031333739303237393131000000010000000b68656c6c6f3a68656c6c6fffffffff
0 1 2 3 4 5 6 6 8 9 a b c d e f
00000000 00 00 00 8d|00 00 00 00| 01|31|00 00 00 00|00 00 ........ .1......
len 8d |type 0 |len|id|isAsync | msg
00000010 00 01|00 00 00 08|53 65 72 76 69 63 65 41|00 00 ......Se rviceA..
reply 01| str len |servicename |str len
00000020 00 08|73 61 79 48 65 6c 6c 6f|00 00 00 00 00 00 ..sayHel lo......
|operation name | 0L
00000030 00 00|00 00 00 00 00 00 00 00|00 00 00 00|ff ff ........ ........
| 0L | 0d |null -1 reply has in params
00000040 ff ff|00 00 00 07|64 65 66 61 75 6c 74|00 00 00 ......de fault...
| str len 7| d e f a u l t|
|groupname |attachement map size 1
00000050 01|00 00 00 08|73 65 6e 64 54 69 6d 65|00 00 00 .....sen dTime...
|str len | key |obj type usfctxobj 03
00000060 03 |00 00 00 00|00 00 00 01|00 00 00 0d|31 35 30 ........ .....150
| local |obj type string len 0d|
00000070 31 33 37 39 30 32 37 39 31 31|00 00 00 01|00 00 13790279 11......
rsptime |resp obj |
|obj type 1 |string len 0x0b
00000080 00 0b|68 65 6c 6c 6f 3a 68 65 6c 6c 6f|ff ff ff ..hello: hello...
| |Null exception
|response content |
00000090 ff .
DSFCTxObject符号化方法:0.write byte 4 1.write DSFCtxObject.type 2.ObjectPack(DSFCtxObject.obj) 3.protostaff.GraphIOUtil.writeTo(objpack)は圧縮対象bytes 4を生成する.gzip compress 5.write length of compress bytes 6.write compressed bytes