Skip to content

Commit

Permalink
remove redundant codes
Browse files Browse the repository at this point in the history
Signed-off-by: xuleiming <xuleiming@yf-networks.com>
  • Loading branch information
xuleiming committed Dec 3, 2024
1 parent d31fdd9 commit 6e04f65
Show file tree
Hide file tree
Showing 27 changed files with 35 additions and 452 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ coverage.txt
.vscode/*
bfe
dist/*
conf/wasm_plugin

.DS_Store
47 changes: 3 additions & 44 deletions bfe_wasmplug/abi/proxywasm010/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,13 @@
package proxywasm010

import (
"github.com/bfenetworks/bfe/bfe_wasmplug/abi"
"github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common"
proxywasm "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1"
)

func init() {
abi.RegisterABI(proxywasm.ProxyWasmABI_0_1_0, ABIContextFactory)
}

func ABIContextFactory(instance common.WasmInstance) abi.ABI {
return &ABIContext{
proxywasm.ABIContext{
func ABIContextFactory(instance common.WasmInstance) proxywasm.ContextHandler {
return &proxywasm.ABIContext{
Imports: &DefaultImportsHandler{Instance: instance},
Instance: instance,
},
}
}

// ABIContext is a wrapper for proxywasm-go-host/proxywasm.ABIContext
// implement types.ABI
type ABIContext struct {
proxywasm.ABIContext
}

// implement types.ABI
func (ctx *ABIContext) GetABIImports() interface{} {
return ctx.ABIContext.GetImports()
}

func (ctx *ABIContext) SetABIImports(imports interface{}) {
if v, ok := imports.(proxywasm.ImportsHandler); ok {
ctx.ABIContext.SetImports(v)
}
}
}

func (ctx *ABIContext) GetABIExports() interface{} {
return ctx.ABIContext.GetExports()
}

/*
// implement types.ABIHandler
func (ctx *ABIContext) OnInstanceCreate(instance common.WasmInstance) {
if err := instance.RegisterImports(ctx.Name()); err != nil {
panic(err)
}
}
func (ctx *ABIContext) OnInstanceStart(instance common.WasmInstance) {}
func (ctx *ABIContext) OnInstanceDestroy(instance common.WasmInstance) {}
*/
4 changes: 2 additions & 2 deletions bfe_wasmplug/abi/proxywasm010/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type httpCallout struct {
id int32
d *DefaultImportsHandler
instance common.WasmInstance
abiContext *ABIContext
abiContext *proxywasm.ABIContext

urlString string
client *http.Client
Expand All @@ -101,7 +101,7 @@ func (d *DefaultImportsHandler) HttpCall(reqURL string, header common.HeaderMap,
id: calloutID,
d: d,
instance: d.Instance,
abiContext: d.Instance.GetData().(*ABIContext),
abiContext: d.Instance.GetData().(*proxywasm.ABIContext),
urlString: reqURL,
}

Expand Down
17 changes: 0 additions & 17 deletions bfe_wasmplug/abi/proxywasm010/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,3 @@ func (h HeaderMapWrapper) ByteSize() uint64 {
func (h HeaderMapWrapper) Clone() common.HeaderMap {
return &HeaderMapWrapper{h.Header}
}

/*
// HeaderMapWrapperBack wraps proxy-wasm-go-host/common.HeaderMap into api.HeaderMap
type HeaderMapWrapperBack struct {
common.HeaderMap
}
func (h HeaderMapWrapperBack) Clone() api.HeaderMap {
return nil
}
// IoBufferWrapper wraps buffer.IoBuffer into proxy-wasm-go-host/common.IoBuffer
// implement common.IoBuffer
type IoBufferWrapper struct {
buffer.IoBuffer
}
*/
52 changes: 4 additions & 48 deletions bfe_wasmplug/abi/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,23 @@
package abi

import (
"sync"

"github.com/baidu/go-lib/log"
"github.com/bfenetworks/bfe/bfe_wasmplug/abi/proxywasm010"
"github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common"
proxywasm "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1"
)

// Factory is the ABI factory func.
type Factory func(instance common.WasmInstance) ABI

// string -> Factory.
var abiMap = sync.Map{}

// RegisterABI registers an abi factory.
func RegisterABI(name string, factory Factory) {
abiMap.Store(name, factory)
}

func GetABI(instance common.WasmInstance, name string) ABI {
if instance == nil || name == "" {
log.Logger.Error("[abi][registry] GetABI invalid param, name: %v, instance: %v", name, instance)
return nil
}

v, ok := abiMap.Load(name)
if !ok {
log.Logger.Error("[abi][registry] GetABI not found in registry, name: %v", name)
return nil
}

abiNameList := instance.GetModule().GetABINameList()
for _, abi := range abiNameList {
if name == abi {
factory := v.(Factory)
return factory(instance)
}
}

log.Logger.Error("[abi][register] GetABI not found in wasm instance, name: %v", name)

return nil
}

func GetABIList(instance common.WasmInstance) []ABI {
func GetABIList(instance common.WasmInstance) []proxywasm.ContextHandler {
if instance == nil {
log.Logger.Error("[abi][registry] GetABIList nil instance: %v", instance)
return nil
}

res := make([]ABI, 0)
res := make([]proxywasm.ContextHandler, 0)

abiNameList := instance.GetModule().GetABINameList()
if len(abiNameList) > 0 {
v, ok := abiMap.Load(proxywasm.ProxyWasmABI_0_1_0)
if !ok {
log.Logger.Warn("[abi][registry] GetABIList abi not registered, name: %v", proxywasm.ProxyWasmABI_0_1_0)
return res
}

factory := v.(Factory)
res = append(res, factory(instance))
res = append(res, proxywasm010.ABIContextFactory(instance))
}

return res
Expand Down
56 changes: 0 additions & 56 deletions bfe_wasmplug/abi/wasm.go

This file was deleted.

87 changes: 0 additions & 87 deletions bfe_wasmplug/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ import (
"bytes"
"io/ioutil"

"github.com/baidu/go-lib/log"
"github.com/bfenetworks/bfe/bfe_http"
"github.com/bfenetworks/bfe/bfe_module"
"github.com/bfenetworks/bfe/bfe_wasmplug/abi/proxywasm010"
"github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common"
v1Host "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1"
Expand Down Expand Up @@ -117,88 +115,3 @@ func (v1 *v1Imports) SendHttpResp(respCode int32, respCodeDetail common.IoBuffer
v1.filter.request.HttpResponse = resp
return v1Host.WasmResultOk
}

// exports
type exportAdapter struct {
v1 v1Host.Exports
}

func (e *exportAdapter) ProxyOnContextCreate(contextID int32, parentContextID int32) error {
return e.v1.ProxyOnContextCreate(contextID, parentContextID)
}

func (e *exportAdapter) ProxyOnVmStart(rootContextID int32, vmConfigurationSize int32) (int32, error) {
return e.v1.ProxyOnVmStart(rootContextID, vmConfigurationSize)
}

func (e *exportAdapter) ProxyOnConfigure(rootContextID int32, pluginConfigurationSize int32) (int32, error) {
return e.v1.ProxyOnConfigure(rootContextID, pluginConfigurationSize)
}

func (e *exportAdapter) ProxyOnDone(contextID int32) (int32, error) {
return e.v1.ProxyOnDone(contextID)
}

func (e *exportAdapter) ProxyOnDelete(contextID int32) error {
return e.v1.ProxyOnDelete(contextID)
}

func (e *exportAdapter) ProxyOnRequestHeaders(contextID int32, headers int32, endOfStream int32) int {
action, err := e.v1.ProxyOnRequestHeaders(contextID, headers, endOfStream)
if err != nil || action != v1Host.ActionContinue {
log.Logger.Error("[proxywasm][filter][v1] ProxyOnRequestHeaders action: %v, err: %v", action, err)
return bfe_module.BfeHandlerResponse
}

return bfe_module.BfeHandlerGoOn
}

func (e *exportAdapter) ProxyOnRequestBody(contextID int32, bodyBufferLength int32, endOfStream int32) int {
action, err := e.v1.ProxyOnRequestBody(contextID, bodyBufferLength, endOfStream)
if err != nil || action != v1Host.ActionContinue {
log.Logger.Error("[proxywasm][filter][v1] ProxyOnRequestBody action: %v, err: %v", action, err)
return bfe_module.BfeHandlerResponse
}

return bfe_module.BfeHandlerGoOn
}

func (e *exportAdapter) ProxyOnRequestTrailers(contextID int32, trailers int32, endOfStream int32) int {
action, err := e.v1.ProxyOnRequestTrailers(contextID, trailers)
if err != nil || action != v1Host.ActionContinue {
log.Logger.Error("[proxywasm][filter][v1] ProxyOnRequestTrailers action: %v, err: %v", action, err)
return bfe_module.BfeHandlerResponse
}

return bfe_module.BfeHandlerGoOn
}

func (e *exportAdapter) ProxyOnResponseHeaders(contextID int32, headers int32, endOfStream int32) int {
action, err := e.v1.ProxyOnResponseHeaders(contextID, headers, endOfStream)
if err != nil || action != v1Host.ActionContinue {
log.Logger.Error("[proxywasm][filter][v1] ProxyOnResponseHeaders action: %v, err: %v", action, err)
return bfe_module.BfeHandlerResponse
}

return bfe_module.BfeHandlerGoOn
}

func (e *exportAdapter) ProxyOnResponseBody(contextID int32, bodyBufferLength int32, endOfStream int32) int {
action, err := e.v1.ProxyOnResponseBody(contextID, bodyBufferLength, endOfStream)
if err != nil || action != v1Host.ActionContinue {
log.Logger.Error("[proxywasm][filter][v1] ProxyOnRequestBody action: %v, err: %v", action, err)
return bfe_module.BfeHandlerResponse
}

return bfe_module.BfeHandlerGoOn
}

func (e *exportAdapter) ProxyOnResponseTrailers(contextID int32, trailers int32, endOfStream int32) int {
action, err := e.v1.ProxyOnResponseTrailers(contextID, trailers)
if err != nil || action != v1Host.ActionContinue {
log.Logger.Error("[proxywasm][filter][v1] ProxyOnResponseTrailers action: %v, err: %v", action, err)
return bfe_module.BfeHandlerResponse
}

return bfe_module.BfeHandlerGoOn
}
Loading

0 comments on commit 6e04f65

Please sign in to comment.