Skip to content

Commit

Permalink
rename package & remove some obsolete lines.
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 4, 2024
1 parent ef6405e commit 5293c67
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 45 deletions.
5 changes: 0 additions & 5 deletions bfe_config/bfe_conf/conf_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ type ConfigBasic struct {
DebugBfeRoute bool // whether open bferoute debug log
DebugBal bool // whether open bal debug log
DebugHealthCheck bool // whether open health check debug log

// wasm plugin path
BfeWasmPath string //root path of wasm plugins
}

func (cfg *ConfigBasic) SetDefaultConf() {
Expand Down Expand Up @@ -102,8 +99,6 @@ func (cfg *ConfigBasic) SetDefaultConf() {
cfg.NameConf = "server_data_conf/name_conf.data"

cfg.MonitorInterval = 20

cfg.BfeWasmPath = "plugin"
}

func (cfg *ConfigBasic) Check(confRoot string) error {
Expand Down
4 changes: 2 additions & 2 deletions bfe_modules/bfe_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import (
"github.com/bfenetworks/bfe/bfe_modules/mod_trust_clientip"
"github.com/bfenetworks/bfe/bfe_modules/mod_userid"
"github.com/bfenetworks/bfe/bfe_modules/mod_waf"
"github.com/bfenetworks/bfe/bfe_modules/mod_wasmplug"
"github.com/bfenetworks/bfe/bfe_modules/mod_wasmplugin"
)

// list of all modules, the order is very important
Expand Down Expand Up @@ -134,7 +134,7 @@ var moduleList = []bfe_module.BfeModule{
mod_access.NewModuleAccess(),

// mod_wasm
mod_wasmplug.NewModuleWasm(),
mod_wasmplugin.NewModuleWasm(),
}

// init modules list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package mod_wasmplug
package mod_wasmplugin

import (
"fmt"
Expand All @@ -24,7 +24,7 @@ import (
"github.com/bfenetworks/bfe/bfe_basic/condition"
"github.com/bfenetworks/bfe/bfe_util"
"github.com/bfenetworks/bfe/bfe_util/json"
"github.com/bfenetworks/bfe/bfe_wasmplug"
"github.com/bfenetworks/bfe/bfe_wasmplugin"
gcfg "gopkg.in/gcfg.v1"
)

Expand Down Expand Up @@ -78,7 +78,7 @@ func (cfg *ConfModWasm) Check(confRoot string) error {
type PluginConfFile struct {
Version *string // version of the config
BeforeLocationRules *[]FilterRuleFile // rule list for BeforeLocation
ProductRules *map[string][]FilterRuleFile // product --> rule list
FoundProductRules *map[string][]FilterRuleFile // product --> rule list for FoundProduct
PluginMap *map[string]PluginMeta
}

Expand All @@ -98,15 +98,15 @@ type PluginMeta struct {

type FilterRule struct {
Cond condition.Condition // condition for plugin
PluginList []bfe_wasmplug.WasmPlugin
PluginList []bfe_wasmplugin.WasmPlugin
}

type RuleList []FilterRule
type ProductRules map[string]RuleList // product => list of filter rules

func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) error {
if conf.Version != nil && *conf.Version != t.GetVersion() {
pluginMapNew := make(map[string]bfe_wasmplug.WasmPlugin)
pluginMapNew := make(map[string]bfe_wasmplugin.WasmPlugin)
var beforeLocationRulesNew RuleList
productRulesNew := make(ProductRules)

Expand Down Expand Up @@ -135,15 +135,15 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er
}
}
// if changed, construct a new plugin.
wasmconf := bfe_wasmplug.WasmPluginConfig {
wasmconf := bfe_wasmplugin.WasmPluginConfig {
PluginName: pn,
WasmVersion: p.WasmVersion,
ConfigVersion: p.ConfVersion,
InstanceNum: p.InstanceNum,
Path: path.Join(pluginPath, pn),
// Md5: p.Md5,
}
plug, err := bfe_wasmplug.NewWasmPlugin(wasmconf)
plug, err := bfe_wasmplugin.NewWasmPlugin(wasmconf)
if err != nil {
// build plugin error
return err
Expand Down Expand Up @@ -175,8 +175,8 @@ func updatePluginConf(t *PluginTable, conf PluginConfFile, pluginPath string) er
}
}

if conf.ProductRules != nil {
for product, rules := range *conf.ProductRules {
if conf.FoundProductRules != nil {
for product, rules := range *conf.FoundProductRules {
var rulelist RuleList
for _, r := range rules {
rule := FilterRule{}
Expand Down Expand Up @@ -218,17 +218,17 @@ type PluginTable struct {
version string
beforeLocationRules RuleList
productRules ProductRules
pluginMap map[string]bfe_wasmplug.WasmPlugin
pluginMap map[string]bfe_wasmplugin.WasmPlugin
}

func NewPluginTable() *PluginTable {
t := new(PluginTable)
t.productRules = make(ProductRules)
t.pluginMap = make(map[string]bfe_wasmplug.WasmPlugin)
t.pluginMap = make(map[string]bfe_wasmplugin.WasmPlugin)
return t
}

func (t *PluginTable) Update(version string, beforeLocationRules RuleList, productRules ProductRules, pluginMap map[string]bfe_wasmplug.WasmPlugin) {
func (t *PluginTable) Update(version string, beforeLocationRules RuleList, productRules ProductRules, pluginMap map[string]bfe_wasmplugin.WasmPlugin) {
t.lock.Lock()

t.version = version
Expand All @@ -245,7 +245,7 @@ func (t *PluginTable) GetVersion() string {
return t.version
}

func (t *PluginTable) GetPluginMap() map[string]bfe_wasmplug.WasmPlugin {
func (t *PluginTable) GetPluginMap() map[string]bfe_wasmplugin.WasmPlugin {
defer t.lock.RUnlock()
t.lock.RLock()
return t.pluginMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package mod_wasmplug
package mod_wasmplugin

import (
"fmt"
Expand All @@ -23,7 +23,7 @@ import (
"github.com/bfenetworks/bfe/bfe_basic"
"github.com/bfenetworks/bfe/bfe_http"
"github.com/bfenetworks/bfe/bfe_module"
"github.com/bfenetworks/bfe/bfe_wasmplug"
"github.com/bfenetworks/bfe/bfe_wasmplugin"
)

const (
Expand Down Expand Up @@ -127,7 +127,7 @@ func (m *ModuleWasm) init(cfg *ConfModWasm, cbs *bfe_module.BfeCallbacks,

//
func (m *ModuleWasm) wasmBeforeLocationHandler(request *bfe_basic.Request) (int, *bfe_http.Response) {
var pl []bfe_wasmplug.WasmPlugin
var pl []bfe_wasmplugin.WasmPlugin
rl := m.pluginTable.GetBeforeLocationRules()
for _, rule := range rl {
if rule.Cond.Match(request) {
Expand All @@ -141,9 +141,9 @@ func (m *ModuleWasm) wasmBeforeLocationHandler(request *bfe_basic.Request) (int,
if pl != nil {
// do the pluginlist
retCode := bfe_module.BfeHandlerGoOn
var fl []*bfe_wasmplug.Filter
var fl []*bfe_wasmplugin.Filter
for _, plug := range pl {
filter := bfe_wasmplug.NewFilter(plug, request)
filter := bfe_wasmplugin.NewFilter(plug, request)
var ret int
ret, resp = filter.RequestHandler(request)
fl = append(fl, filter)
Expand All @@ -162,7 +162,7 @@ func (m *ModuleWasm) wasmBeforeLocationHandler(request *bfe_basic.Request) (int,

//
func (m *ModuleWasm) wasmRequestHandler(request *bfe_basic.Request) (int, *bfe_http.Response) {
var pl []bfe_wasmplug.WasmPlugin
var pl []bfe_wasmplugin.WasmPlugin
rl, _ := m.pluginTable.Search(request.Route.Product)
for _, rule := range rl {
if rule.Cond.Match(request) {
Expand All @@ -176,9 +176,9 @@ func (m *ModuleWasm) wasmRequestHandler(request *bfe_basic.Request) (int, *bfe_h
if pl != nil {
// do the pluginlist
retCode := bfe_module.BfeHandlerGoOn
var fl []*bfe_wasmplug.Filter
var fl []*bfe_wasmplugin.Filter
for _, plug := range pl {
filter := bfe_wasmplug.NewFilter(plug, request)
filter := bfe_wasmplugin.NewFilter(plug, request)
var ret int
ret, resp = filter.RequestHandler(request)
fl = append(fl, filter)
Expand All @@ -188,10 +188,10 @@ func (m *ModuleWasm) wasmRequestHandler(request *bfe_basic.Request) (int, *bfe_h
}
}

var fl0 []*bfe_wasmplug.Filter
var fl0 []*bfe_wasmplugin.Filter
val, ok := request.Context[ModWasmBeforeLocationKey]
if ok {
fl0 = val.([]*bfe_wasmplug.Filter)
fl0 = val.([]*bfe_wasmplugin.Filter)
}

fl0 = append(fl0, fl...)
Expand All @@ -207,7 +207,7 @@ func (m *ModuleWasm) wasmResponseHandler(request *bfe_basic.Request, res *bfe_ht
val, ok := request.Context[ModWasmBeforeLocationKey]

if ok {
fl, matched := val.([]*bfe_wasmplug.Filter)
fl, matched := val.([]*bfe_wasmplugin.Filter)
if !matched {
// error
return bfe_module.BfeHandlerGoOn
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"io/ioutil"

// http "github.com/bfenetworks/bfe/bfe_http"
"net/http"
"net/url"
"sync/atomic"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package abi

import (
"github.com/baidu/go-lib/log"
"github.com/bfenetworks/bfe/bfe_wasmplug/abi/proxywasm010"
"github.com/bfenetworks/bfe/bfe_wasmplugin/abi/proxywasm010"
"github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common"
proxywasm "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1"
)
Expand Down
9 changes: 2 additions & 7 deletions bfe_wasmplug/adapter.go → bfe_wasmplugin/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package bfe_wasmplug
package bfe_wasmplugin

import (
"bytes"
"io/ioutil"

"github.com/bfenetworks/bfe/bfe_http"
"github.com/bfenetworks/bfe/bfe_wasmplug/abi/proxywasm010"
"github.com/bfenetworks/bfe/bfe_wasmplugin/abi/proxywasm010"
"github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common"
v1Host "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1"
)

// v1 Imports
type v1Imports struct {
proxywasm010.DefaultImportsHandler
//factory *FilterConfigFactory
plugin WasmPlugin
filter *Filter
}
Expand All @@ -37,13 +36,11 @@ func (v1 *v1Imports) GetRootContextID() int32 {
}

func (v1 *v1Imports) GetVmConfig() common.IoBuffer {
//return v1.factory.GetVmConfig()
return common.NewIoBufferBytes([]byte{})
}

func (v1 *v1Imports) GetPluginConfig() common.IoBuffer {
return common.NewIoBufferBytes(v1.plugin.GetPluginConfig())
//return common.NewIoBufferBytes([]byte{})
}

func (v1 *v1Imports) GetHttpRequestHeader() common.HeaderMap {
Expand All @@ -60,7 +57,6 @@ func (v1 *v1Imports) GetHttpRequestBody() common.IoBuffer {
}

return nil
// return &proxywasm010.IoBufferWrapper{IoBuffer: v1.filter.receiverFilterHandler.GetRequestData()}
}

func (v1 *v1Imports) GetHttpRequestTrailer() common.HeaderMap {
Expand All @@ -85,7 +81,6 @@ func (v1 *v1Imports) GetHttpResponseBody() common.IoBuffer {
}

return nil
//return &proxywasm010.IoBufferWrapper{IoBuffer: v1.filter.senderFilterHandler.GetResponseData()}
}

func (v1 *v1Imports) GetHttpResponseTrailer() common.HeaderMap {
Expand Down
2 changes: 1 addition & 1 deletion bfe_wasmplug/engine.go → bfe_wasmplugin/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package bfe_wasmplug
package bfe_wasmplugin

import (
"github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common"
Expand Down
4 changes: 2 additions & 2 deletions bfe_wasmplug/filter.go → bfe_wasmplugin/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package bfe_wasmplug
package bfe_wasmplugin

import (
"sync"
Expand All @@ -23,7 +23,7 @@ import (
"github.com/bfenetworks/bfe/bfe_module"

"github.com/baidu/go-lib/log"
wasmABI "github.com/bfenetworks/bfe/bfe_wasmplug/abi"
wasmABI "github.com/bfenetworks/bfe/bfe_wasmplugin/abi"
"github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common"
v1Host "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1"
)
Expand Down
4 changes: 2 additions & 2 deletions bfe_wasmplug/plugin.go → bfe_wasmplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package bfe_wasmplug
package bfe_wasmplugin

import (
"crypto/md5"
Expand All @@ -26,7 +26,7 @@ import (
"sync/atomic"

"github.com/baidu/go-lib/log"
wasmABI "github.com/bfenetworks/bfe/bfe_wasmplug/abi"
wasmABI "github.com/bfenetworks/bfe/bfe_wasmplugin/abi"
"github.com/bfenetworks/proxy-wasm-go-host/proxywasm/common"
v1Host "github.com/bfenetworks/proxy-wasm-go-host/proxywasm/v1"
)
Expand Down

0 comments on commit 5293c67

Please sign in to comment.