/
dubborpc_if_tracing.go
159 lines (140 loc) · 3.68 KB
/
dubborpc_if_tracing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
package dubbo
import (
"fmt"
"github.com/AlexStocks/dubbogo/codec/hessian"
)
func init() {
serviceNameFunc = dubboGetServiceName
methodNameFunc = dubboGetMethodName
}
func getSerializeId(flag byte) int {
return int(flag & 0x1f)
}
func getEventPing(flag byte) bool {
return (flag & (1 << 5)) != 0
}
func isReqFrame(flag byte) bool {
return (flag & (1 << 7)) != 0
}
type dubboAttr struct {
serviceName string
methodName string
}
func unSerialize(serializeId int, data []byte) *dubboAttr {
if serializeId != 2 {
// not hessian, do not support
fmt.Printf("unSerialize: id=%d is not hessian\n", serializeId)
return nil
}
attr := &dubboAttr{}
decoder := hessian.NewDecoder(data[:])
var field interface{}
var err error
var ok bool
var str string
// dubbo version + path + version + method
field, err = decoder.Decode()
if err != nil {
fmt.Printf("unSerialize: Decode dubbo_version fail, err=%v\n", err)
return nil
}
str, ok = field.(string)
if !ok {
fmt.Printf("unSerialize: Decode dubbo_version fail, illegal type\n")
return nil
}
field, err = decoder.Decode()
if err != nil {
fmt.Printf("unSerialize: Decode path fail, err=%v\n", err)
return nil
}
str, ok = field.(string)
if !ok {
fmt.Printf("unSerialize: Decode path fail, illegal type\n")
return nil
}
attr.serviceName = str
field, err = decoder.Decode()
if err != nil {
fmt.Printf("unSerialize: Decode version fail, err=%v\n", err)
return nil
}
str, ok = field.(string)
if !ok {
fmt.Printf("unSerialize: Decode version fail, illegal type\n")
return nil
}
field, err = decoder.Decode()
if err != nil {
fmt.Printf("unSerialize: Decode method fail, err=%v\n", err)
return nil
}
str, ok = field.(string)
if !ok {
fmt.Printf("unSerialize: Decode method fail, illegal type\n")
return nil
}
attr.methodName = str
return attr
}
func dubboGetServiceName(data []byte) string {
rslt, bodyLen := isValidDubboData(data)
if rslt == false || bodyLen <= 0 {
return ""
}
flag := data[DUBBO_FLAG_IDX]
if getEventPing(flag) {
// heart-beat frame, there is not service-name
return ""
}
if isReqFrame(flag) != true {
// response frame, there is not service-name
return ""
}
serializeId := getSerializeId(flag)
ret := unSerialize(serializeId, data[DUBBO_HEADER_LEN:])
serviceName := ""
if ret != nil {
serviceName = ret.serviceName
}
return serviceName
}
func dubboGetMethodName(data []byte) string {
//return "dubboMethod"
rslt, bodyLen := isValidDubboData(data)
if rslt == false || bodyLen <= 0 {
return ""
}
flag := data[DUBBO_FLAG_IDX]
if getEventPing(flag) {
// heart-beat frame, there is not method-name
return ""
}
if isReqFrame(flag) != true {
// response frame, there is not method-name
return ""
}
serializeId := getSerializeId(flag)
ret := unSerialize(serializeId, data[DUBBO_HEADER_LEN:])
methodName := ""
if ret != nil {
methodName = ret.methodName
}
return methodName
}