Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit b5703e5

Browse files
committed
wip
Signed-off-by: mathetake <[email protected]>
1 parent 4fc6d67 commit b5703e5

File tree

10 files changed

+31
-90
lines changed

10 files changed

+31
-90
lines changed

proxytest/base.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ type baseHost struct {
4141
metricIDToType map[uint32]types.MetricType
4242
metricNameToID map[string]uint32
4343

44-
calloutCallbackCaller func(contextID uint32, numHeaders, bodySize, numTrailers int)
45-
calloutResponse map[uint32]struct {
44+
httpCalloutCallbackCaller func(contextID uint32, numHeaders, bodySize, numTrailers int)
45+
httpCalloutResponse map[uint32]struct {
4646
headers, trailers [][2]string
4747
body []byte
4848
}
49-
callouts map[uint32]struct{}
49+
httpCallouts map[uint32]struct{}
5050
}
5151

5252
type sharedData struct {
@@ -56,27 +56,25 @@ type sharedData struct {
5656

5757
func newBaseHost(f func(contextID uint32, numHeaders, bodySize, numTrailers int)) *baseHost {
5858
return &baseHost{
59-
queues: map[uint32][][]byte{},
60-
queueNameID: map[string]uint32{},
61-
sharedDataKVS: map[string]*sharedData{},
62-
metricIDToValue: map[uint32]uint64{},
63-
metricIDToType: map[uint32]types.MetricType{},
64-
metricNameToID: map[string]uint32{},
65-
calloutCallbackCaller: f,
66-
calloutResponse: map[uint32]struct {
59+
queues: map[uint32][][]byte{},
60+
queueNameID: map[string]uint32{},
61+
sharedDataKVS: map[string]*sharedData{},
62+
metricIDToValue: map[uint32]uint64{},
63+
metricIDToType: map[uint32]types.MetricType{},
64+
metricNameToID: map[string]uint32{},
65+
httpCalloutCallbackCaller: f,
66+
httpCalloutResponse: map[uint32]struct {
6767
headers, trailers [][2]string
6868
body []byte
6969
}{},
70-
callouts: map[uint32]struct{}{},
70+
httpCallouts: map[uint32]struct{}{},
7171
}
7272
}
7373

7474
func (b *baseHost) ProxyLog(logLevel types.LogLevel, messageData *byte, messageSize int) types.Status {
7575
str := proxywasm.RawBytePtrToString(messageData, messageSize)
7676

7777
log.Printf("proxy_log: %s", str)
78-
// TODO: exit if loglevel == fatal?
79-
8078
b.logs[logLevel] = append(b.logs[logLevel], str)
8179
return types.StatusOK
8280
}

proxytest/base_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

proxytest/http.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ func (h *HttpFilterHost) PutResponseBody(contextID uint32, body []byte) {
153153
cs.action = cs.context.OnHttpResponseBody(len(body), false) // TODO: allow for specifying end_of_stream
154154
}
155155

156+
func (h *HttpFilterHost) CompleteHttpStream(contextID uint32) {
157+
cs, ok := h.contexts[contextID]
158+
if !ok {
159+
log.Fatalf("invalid context id: %d", contextID)
160+
}
161+
cs.context.OnHttpStreamDone()
162+
}
163+
156164
func (h *HttpFilterHost) ProxyGetBufferBytes(bt types.BufferType, start int, maxSize int,
157165
returnBufferData **byte, returnBufferSize *int) types.Status {
158166
ctx := h.contexts[h.currentContextID]

proxytest/http_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

proxytest/network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (n *NetworkFilterHost) CloseDownstreamConnection(contextID uint32) {
117117
}
118118

119119
func (n *NetworkFilterHost) CompleteConnection(contextID uint32) {
120-
n.streams[contextID].context.OnDone()
120+
n.streams[contextID].context.OnStreamDone()
121121
delete(n.streams, contextID)
122122
}
123123

proxytest/network_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

proxytest/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewRootContextHostEmulator(ctx proxywasm.RootContext, pluginConfiguration,
4949
}
5050
}
5151

52-
func (n *RootContextHostEmulator) ConfigurePlugin() {
52+
func (n *RootContextHostEmulator) StartPlugin() {
5353
size := len(n.pluginConfiguration)
5454
n.context.OnPluginStart(size)
5555
}

proxytest/root_test.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

proxywasm/abi_lifecycle_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ func Test_proxyOnContextCreate(t *testing.T) {
1414

1515
var cnt int
1616
currentState = &state{
17-
rootContexts: map[uint32]*rootContextState{},
18-
httpStreams: map[uint32]HttpContext{},
19-
streams: map[uint32]StreamContext{},
17+
rootContexts: map[uint32]*rootContextState{},
18+
httpStreams: map[uint32]HttpContext{},
19+
streams: map[uint32]StreamContext{},
20+
contextIDToRooID: map[uint32]uint32{},
2021
}
2122

2223
SetNewRootContext(func(contextID uint32) RootContext {

proxywasm/vmstate_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func TestState_createStreamContext(t *testing.T) {
8787
rootContexts: map[uint32]*rootContextState{rid: nil},
8888
streams: map[uint32]StreamContext{},
8989
newStreamContext: func(contextID uint32) StreamContext { return &sc{} },
90+
contextIDToRooID: map[uint32]uint32{},
9091
}
9192

9293
s.createStreamContext(cid, rid)
@@ -104,9 +105,10 @@ func TestState_createHttpContext(t *testing.T) {
104105
rid uint32 = 10
105106
)
106107
s := &state{
107-
rootContexts: map[uint32]*rootContextState{rid: nil},
108-
httpStreams: map[uint32]HttpContext{},
109-
newHttpContext: func(contextID uint32) HttpContext { return &hc{} },
108+
rootContexts: map[uint32]*rootContextState{rid: nil},
109+
httpStreams: map[uint32]HttpContext{},
110+
newHttpContext: func(contextID uint32) HttpContext { return &hc{} },
111+
contextIDToRooID: map[uint32]uint32{},
110112
}
111113

112114
s.createHttpContext(cid, rid)

0 commit comments

Comments
 (0)