55
66 "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm"
77 "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/rawhostcall"
8+ "github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm/types"
89)
910
1011type HostEmulator interface {
@@ -15,6 +16,10 @@ type HostEmulator interface {
1516 IsDispatchCalled (contextID uint32 ) bool
1617 PutCalloutResponse (contextID uint32 , headers , trailers [][2 ]string , body []byte )
1718
19+ GetLogs (level types.LogLevel ) []string
20+ GetTickPeriod () uint32
21+ GetQueueSize (queueID uint32 ) int
22+
1823 NetworkFilterInitConnection () (contextID uint32 )
1924 NetworkFilterPutUpstreamData (contextID uint32 , data []byte )
2025 NetworkFilterPutDownstreamData (contextID uint32 , data []byte )
3641func NewHostEmulator (pluginConfiguration , vmConfiguration []byte ) HostEmulator {
3742 root := newRootHostEmulator (pluginConfiguration , vmConfiguration )
3843 network := newNetworkHostEmulator ()
44+ http := newHttpHostEmulator ()
3945 emulator := & hostEmulator {
4046 root ,
4147 network ,
48+ http ,
4249 }
4350
4451 hostMux .Lock () // acquire the lock of host emulation
@@ -57,75 +64,27 @@ func getNextContextID() (ret uint32) {
5764type hostEmulator struct {
5865 * rootHostEmulator
5966 * networkHostEmulator
67+ * httpHostEmulator
6068}
6169
6270func (* hostEmulator ) Done () {
6371 hostMux .Unlock ()
6472 proxywasm .VMStateReset ()
6573}
6674
67- /*
68-
69- func (n *networkHostEmulator) ProxyGetBufferBytes(bt types.BufferType, start int, maxSize int,
75+ func (h * hostEmulator ) ProxyGetBufferBytes (bt types.BufferType , start int , maxSize int ,
7076 returnBufferData * * byte , returnBufferSize * int ) types.Status {
71- stream := n.streams[n.currentContextID]
72- var buf []byte
7377 switch bt {
74- case types.BufferTypeUpstreamData:
75- buf = stream.upstream
76- case types.BufferTypeDownstreamData:
77- buf = stream.downstream
78+ case types .BufferTypePluginConfiguration , types .BufferTypeVMConfiguration :
79+ return h .rootHostEmulatorProxyGetBufferBytes (bt , start , maxSize , returnBufferData , returnBufferSize )
80+ case types .BufferTypeDownstreamData , types .BufferTypeUpstreamData :
81+ return h .networkHostEmulatorProxyGetBufferBytes (bt , start , maxSize , returnBufferData , returnBufferSize )
82+ case types .BufferTypeHttpRequestBody , types .BufferTypeHttpResponseBody :
83+ return h .httpHostEmulatorProxyGetBufferBytes (bt , start , maxSize , returnBufferData , returnBufferSize )
7884 default :
79- // delegate to baseHost
80- return n.getBuffer(bt, start, maxSize, returnBufferData, returnBufferSize)
81- }
82-
83- if start >= len(buf) {
84- log.Printf("start index out of range: %d (start) >= %d ", start, len(buf))
85- return types.StatusBadArgument
86- }
87-
88- *returnBufferData = &buf[start]
89- if maxSize > len(buf)-start {
90- *returnBufferSize = len(buf) - start
91- } else {
92- *returnBufferSize = maxSize
85+ panic ("unreachable: maybe a bug in host emulation" )
9386 }
94- return types.StatusOK
9587}
96- */
97-
98- /*
99-
100-
101- func (r *rootHostEmulator) ProxyGetBufferBytes(bt types.BufferType, start int, maxSize int,
102- returnBufferData **byte, returnBufferSize *int) types.Status {
103- var buf []byte
104- switch bt {
105- case types.BufferTypePluginConfiguration:
106- buf = r.pluginConfiguration
107- case types.BufferTypeVMConfiguration:
108- buf = r.vmConfiguration
109- default:
110- // delegate to baseHost
111- return r.getBuffer(bt, start, maxSize, returnBufferData, returnBufferSize)
112- }
113-
114- if start >= len(buf) {
115- log.Printf("start index out of range: %d (start) >= %d ", start, len(buf))
116- return types.StatusBadArgument
117- }
118-
119- *returnBufferData = &buf[start]
120- if maxSize > len(buf)-start {
121- *returnBufferSize = len(buf) - start
122- } else {
123- *returnBufferSize = maxSize
124- }
125- return types.StatusOK
126- }
127-
128- */
12988
13089/*
13190
0 commit comments