Skip to content

Commit

Permalink
refine codes
Browse files Browse the repository at this point in the history
  • Loading branch information
xuleiming committed Dec 3, 2024
1 parent 6df3456 commit f229ef0
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 68 deletions.
1 change: 0 additions & 1 deletion bfe_modules/mod_wasmplug/conf_mod_wasmplug.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er
// ensure instance num
actual := (*plugOld).EnsureInstanceNum(p.InstanceNum)
if actual != p.InstanceNum {
// log.DefaultLogger.Errorf("[wasm][plugin] NewWasmPlugin fail to ensure instance num, want: %v got 0", instanceNum)
return fmt.Errorf("can not EnsureInstanceNum, plugin:%s, num:%d", pn, p.InstanceNum)
}

Expand Down
4 changes: 0 additions & 4 deletions bfe_modules/mod_wasmplug/mod_wasmplug.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ func (m *ModuleWasm) wasmRequestHandler(request *bfe_basic.Request) (int, *bfe_h

//
func (m *ModuleWasm) wasmResponseHandler(request *bfe_basic.Request, res *bfe_http.Response) int {
// for p := range pluginList {
// call p
// }
val, ok := request.Context[ModWasmBeforeLocationKey]

if ok {
Expand All @@ -204,7 +201,6 @@ func (m *ModuleWasm) wasmResponseHandler(request *bfe_basic.Request, res *bfe_ht

n := len(fl)
for i := n-1; i >= 0; i-- {
// call pl[i]
fl[i].ResponseHandler(request)
fl[i].OnDestroy()
}
Expand Down
7 changes: 0 additions & 7 deletions bfe_wasmplug/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ import (
)

type Filter struct {
//ctx context.Context

//factory *FilterConfigFactory

//pluginName string
plugin WasmPlugin
instance common.WasmInstance
abi v1Host.ContextHandler
Expand All @@ -45,8 +40,6 @@ type Filter struct {
rootContextID int32
contextID int32

//receiverFilterHandler api.StreamReceiverFilterHandler
//senderFilterHandler api.StreamSenderFilterHandler
request *bfe_basic.Request

destroyOnce sync.Once
Expand Down
12 changes: 0 additions & 12 deletions bfe_wasmplug/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func NewWasmPlugin(wasmConfig WasmPluginConfig) (WasmPlugin, error) {
// get wasm engine
vm := GetWasmEngine()
if vm == nil {
// log.DefaultLogger.Errorf("[wasm][plugin] NewWasmPlugin fail to get wasm engine: %v", wasmConfig.VmConfig.Engine)
return nil, ErrEngineNotFound
}

Expand Down Expand Up @@ -149,22 +148,18 @@ func NewWasmPlugin(wasmConfig WasmPluginConfig) (WasmPlugin, error) {
md5str := strings.TrimSpace(string(md5File))

if len(wasmBytes) == 0 {
// log.DefaultLogger.Errorf("[wasm][plugin] NewWasmPlugin fail to load wasm bytes, config: %v", wasmConfig)
return nil, ErrWasmBytesLoad
}

md5Bytes := md5.Sum(wasmBytes)
newMd5 := hex.EncodeToString(md5Bytes[:])
if newMd5 != md5str {
// log.DefaultLogger.Errorf("[wasm][plugin] NewWasmPlugin the hash(MD5) of wasm bytes is incorrect, config: %v, real hash: %s",
// wasmConfig, newMd5)
return nil, ErrWasmBytesIncorrect
}

// create wasm module
module := vm.NewModule(wasmBytes)
if module == nil {
// log.DefaultLogger.Errorf("[wasm][plugin] NewWasmPlugin fail to create module, config: %v", wasmConfig)
return nil, ErrModuleCreate
}

Expand All @@ -177,13 +172,9 @@ func NewWasmPlugin(wasmConfig WasmPluginConfig) (WasmPlugin, error) {
rootContextID: newContextID(0),
}

// plugin.SetCpuLimit(wasmConfig.VmConfig.Cpu)
// plugin.SetMemLimit(wasmConfig.VmConfig.Mem)

// ensure instance num
actual := plugin.EnsureInstanceNum(wasmConfig.InstanceNum)
if actual == 0 {
// log.DefaultLogger.Errorf("[wasm][plugin] NewWasmPlugin fail to ensure instance num, want: %v got 0", instanceNum)
return nil, ErrInstanceCreate
}

Expand Down Expand Up @@ -220,8 +211,6 @@ func (w *wasmPluginImpl) EnsureInstanceNum(num int) int {
continue
}

//instance.abiList = wasmABI.GetABIList(instance)

// Instantiate any ABI needed by the guest.
for _, abi := range wasmABI.GetABIList(instance) {
//abi.OnInstanceCreate(instance)
Expand Down Expand Up @@ -302,7 +291,6 @@ func (w *wasmPluginImpl) GetInstance() common.WasmInstance {
atomic.AddInt32(&w.occupy, 1)
return instance
}
// log.DefaultLogger.Errorf("[wasm][plugin] GetInstance fail to get available instance, instance num: %v", len(w.instances))

return nil
}
Expand Down
18 changes: 3 additions & 15 deletions conf/mod_wasm/mod_wasm.data
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
{
"Version": "1",
"Version": "5",
"BeforeLocationRules": [{
"Cond": "req_path_prefix_in(\"/headers\", false)",
"PluginList": [ "headers" ]
}],
"ProductRules": {
"local_product": [{
"Cond": "default_t()",
"PluginList": [ "auth" ]
"PluginList": []
}]
},
"PluginMap": {
"http": {
"Name": "http",
"WasmVersion": "1",
"ConfVersion": "2",
"InstanceNum": 1
},
"headers": {
"Name": "headers",
"WasmVersion": "3",
"ConfVersion": "6",
"InstanceNum": 3
},
"auth": {
"Name": "auth",
"WasmVersion": "2",
"ConfVersion": "4",
"InstanceNum": 3
"InstanceNum": 20
}
}
}
29 changes: 0 additions & 29 deletions conf/mod_wasm/mod_wasm.data.bak

This file was deleted.

4 changes: 4 additions & 0 deletions conf/wasm_plugin/headers/headers.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"header": "Wasm-Header-1",
"value": "Hello WasmPlugin!"
}
1 change: 1 addition & 0 deletions conf/wasm_plugin/headers/headers.md5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
82f14b56c9114d420f4624443bd76ac0
Binary file added conf/wasm_plugin/headers/headers.wasm
Binary file not shown.

0 comments on commit f229ef0

Please sign in to comment.