Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

separate hostcalls from context #22

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gotest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
go-version: 1.14

- name: build examples
run: find ./ -type f -name "main.go" | xargs -Ip tinygo build -o p.wasm -target=wasm -wasm-abi=generic p
run: find ./examples -type f -name "main.go" | xargs -Ip tinygo build -o p.wasm -target=wasm -wasm-abi=generic p

test:
name: test
Expand Down
4 changes: 2 additions & 2 deletions examples/helloworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ func newHelloWorld(contextID uint32) runtime.RootContext {
// override
func (ctx *helloWorld) OnVMStart(_ int) bool {
runtime.LogInfo("proxy_on_vm_start from Go!")
if err := ctx.SetTickPeriod(1000); err != nil {
if err := runtime.HostCallSetTickPeriodMilliSeconds(1000); err != nil {
runtime.LogCritical("failed to set tick period: " + err.Error())
}
return true
}

// override
func (ctx *helloWorld) OnTick() {
t := ctx.GetCurrentTime()
t := runtime.HostCallGetCurrentTime()
msg := "OnTick on " + strconv.FormatUint(uint64(ctx.contextID), 10)
msg += ", it's " + strconv.FormatInt(t, 10)
runtime.LogInfo(msg)
Expand Down
14 changes: 7 additions & 7 deletions examples/http_auth_random/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func newContext(contextID uint32) runtime.HttpContext {

// override default
func (ctx *httpHeaders) OnHttpRequestHeaders(_ int, _ bool) types.Action {
hs, err := ctx.GetHttpRequestHeaders()
hs, err := runtime.HostCallGetHttpRequestHeaders()
if err != nil {
runtime.LogCritical("failed to get request headers: " + err.Error())
return types.ActionContinue
Expand All @@ -33,7 +33,7 @@ func (ctx *httpHeaders) OnHttpRequestHeaders(_ int, _ bool) types.Action {
runtime.LogInfo("request header: " + h[0] + ": " + h[1])
}

if _, err := ctx.DispatchHttpCall(
if _, err := runtime.HostCallDispatchHttpCall(
"httpbin", hs, "", [][2]string{}, 50000); err != nil {
runtime.LogCritical("dipatch httpcall failed: " + err.Error())
}
Expand All @@ -42,29 +42,29 @@ func (ctx *httpHeaders) OnHttpRequestHeaders(_ int, _ bool) types.Action {

// override default
func (ctx *httpHeaders) OnHttpCallResponse(_ uint32, _ int, bodySize int, _ int) {
b, err := ctx.GetHttpCallResponseBody(0, bodySize)
b, err := runtime.HostCallGetHttpCallResponseBody(0, bodySize)
if err != nil {
runtime.LogCritical("failed to get response body: " + err.Error())
ctx.ResumeHttpRequest()
runtime.HostCallResumeHttpRequest()
return
}

s := fnv.New32a()
if _, err := s.Write(b); err != nil {
runtime.LogCritical("failed to calculate hash: " + err.Error())
ctx.ResumeHttpRequest()
runtime.HostCallResumeHttpRequest()
return
}

if s.Sum32()%2 == 0 {
runtime.LogInfo("access granted")
ctx.ResumeHttpRequest()
runtime.HostCallResumeHttpRequest()
return
}

msg := "access forbidden"
runtime.LogInfo(msg)
ctx.SendHttpResponse(403, [][2]string{
runtime.HostCallSendHttpResponse(403, [][2]string{
{"powered-by", "proxy-wasm-go!!"},
}, msg)
}
Expand Down
4 changes: 2 additions & 2 deletions examples/http_headers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func newContext(contextID uint32) runtime.HttpContext {

// override
func (ctx *httpHeaders) OnHttpRequestHeaders(_ int, _ bool) types.Action {
hs, err := ctx.GetHttpRequestHeaders()
hs, err := runtime.HostCallGetHttpRequestHeaders()
if err != nil {
runtime.LogCritical("failed to get request headers: " + err.Error())
}
Expand All @@ -36,7 +36,7 @@ func (ctx *httpHeaders) OnHttpRequestHeaders(_ int, _ bool) types.Action {

// override
func (ctx *httpHeaders) OnHttpResponseHeaders(_ int, _ bool) types.Action {
hs, err := ctx.GetHttpResponseHeaders()
hs, err := runtime.HostCallGetHttpResponseHeaders()
if err != nil {
runtime.LogCritical("failed to get request headers: " + err.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/abi_l7.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ func proxyOnHttpCallResponse(_, calloutID uint32, numHeaders, bodySize, numTrail

if ctx, ok := currentState.streamContexts[ctxID]; ok {
currentState.setActiveContextID(ctxID)
setEffectiveContext(ctxID)
HostCallSetEffectiveContext(ctxID)
ctx.OnHttpCallResponse(calloutID, numHeaders, bodySize, numTrailers)
} else if ctx, ok := currentState.httpContexts[ctxID]; ok {
currentState.setActiveContextID(ctxID)
setEffectiveContext(ctxID)
HostCallSetEffectiveContext(ctxID)
ctx.OnHttpCallResponse(calloutID, numHeaders, bodySize, numTrailers)
} else if ctx, ok := currentState.rootContexts[ctxID]; ok {
currentState.activeContextID = ctxID
setEffectiveContext(ctxID)
HostCallSetEffectiveContext(ctxID)
ctx.OnHttpCallResponse(calloutID, numHeaders, bodySize, numTrailers)
} else {
panic("invalid context on proxy_on_http_call_response")
Expand Down
File renamed without changes.
Loading