From 817535614cce928fbecf249b31f378b3e8f501ed Mon Sep 17 00:00:00 2001 From: yangsijie Date: Thu, 1 Aug 2019 12:07:18 +0800 Subject: [PATCH] Update comments --- README.md | 2 +- bfe_balance/backend/health_check.go | 2 +- bfe_balance/bal_slb/bal_rr.go | 4 ++-- bfe_balance/bal_table.go | 2 +- bfe_basic/error_code.go | 2 +- bfe_config/bfe_conf/conf_https_basic.go | 2 +- bfe_config/bfe_conf/conf_session_cache.go | 4 ++-- bfe_http/request.go | 14 +++++--------- bfe_module/bfe_module.go | 2 +- bfe_modules/mod_header/mod_header.go | 4 ++-- bfe_modules/mod_redirect/action_url.go | 2 +- bfe_net/textproto/header.go | 2 +- bfe_net/textproto/reader.go | 2 +- bfe_server/bfe_server.go | 4 ++-- bfe_server/bfe_server_init.go | 2 +- bfe_server/http_conn.go | 2 +- bfe_server/protocol_handler.go | 2 +- bfe_server/register_modules.go | 2 +- bfe_server/response.go | 2 +- bfe_server/reverseproxy.go | 2 +- bfe_server/tls_server_rule.go | 2 +- bfe_server/tls_session_cache.go | 2 +- bfe_server/web_server.go | 2 +- bfe_tls/handshake_client_test.go | 4 ++-- bfe_tls/handshake_server.go | 2 +- bfe_util/logid.go | 2 +- go.mod | 2 +- go.sum | 2 ++ 28 files changed, 38 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index a4060f598..f27418a30 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ BFE is an open-source layer 7 load balancer derived from proprietary Baidu Front - [Plugin](docs/en_us/modules.md) ## Contributing -- Please create an issue in [issue list] (http://github.com/baidu/bfe/issues). +- Please create an issue in [issue list](http://github.com/baidu/bfe/issues). - Contact Committers/Owners for further discussion if needed. - Following the golang coding standards. - See the [CONTRIBUTING](CONTRIBUTING.md) file for details diff --git a/bfe_balance/backend/health_check.go b/bfe_balance/backend/health_check.go index 089ca1240..3479692d4 100644 --- a/bfe_balance/backend/health_check.go +++ b/bfe_balance/backend/health_check.go @@ -34,7 +34,7 @@ import ( ) func UpdateStatus(backend *BfeBackend, cluster string) bool { - // get conf of health check, which is seperately stored for each cluster + // get conf of health check, which is separately stored for each cluster checkConf := getCheckConf(cluster) if checkConf == nil { // just ingore if not found health check conf diff --git a/bfe_balance/bal_slb/bal_rr.go b/bfe_balance/bal_slb/bal_rr.go index e542dace4..f6a84a57f 100644 --- a/bfe_balance/bal_slb/bal_rr.go +++ b/bfe_balance/bal_slb/bal_rr.go @@ -14,7 +14,7 @@ // weighted round robin balance // -// Alogrithm: +// Algorithm: // smooth Weighted Round Robin algorithm is as follows: on each backend selection, // 1. increase CurrentWeight of each eligible backend by its weight, // 2. select backend with greatest CurrentWeight and reduce its CurrentWeight @@ -54,7 +54,7 @@ import ( "github.com/baidu/bfe/bfe_debug" ) -// implementation versions of weighted round robin alogrithm +// implementation versions of weighted round robin algorithm const ( WrrSimple = 0 WrrSmooth = 1 diff --git a/bfe_balance/bal_table.go b/bfe_balance/bal_table.go index 2e02b993d..f58d0bd93 100644 --- a/bfe_balance/bal_table.go +++ b/bfe_balance/bal_table.go @@ -146,7 +146,7 @@ func (t *BalTable) backendInit(backendConfs cluster_table_conf.ClusterTableConf) continue } - // initalize + // initialize err := bal.BackendInit(backendConf) if err != nil { log.Logger.Error("ClusterTable.backendInit():err[%s] in cluster.BackendInit() for %s", diff --git a/bfe_basic/error_code.go b/bfe_basic/error_code.go index 1f12fbe57..1ad82bcde 100644 --- a/bfe_basic/error_code.go +++ b/bfe_basic/error_code.go @@ -40,7 +40,7 @@ var ( ErrBkNoBackend = errors.New("BK_NO_BACKEND") // no backend found ErrBkRequestBackend = errors.New("BK_REQUEST_BACKEND") // forward request to backend error ErrBkConnectBackend = errors.New("BK_CONNECT_BACKEND") // connect backend error - ErrBkWriteRequest = errors.New("BK_WRITE_REQUEST") // write request error (casued by bk or client) + ErrBkWriteRequest = errors.New("BK_WRITE_REQUEST") // write request error (caused by bk or client) ErrBkReadRespHeader = errors.New("BK_READ_RESP_HEADER") // read response error ErrBkRespHeaderTimeout = errors.New("BK_RESP_HEADER_TIMEOUT") // read response timeout ErrBkTransportBroken = errors.New("BK_TRANSPORT_BROKEN") // conn broken diff --git a/bfe_config/bfe_conf/conf_https_basic.go b/bfe_config/bfe_conf/conf_https_basic.go index c412ffd82..4c20a8585 100644 --- a/bfe_config/bfe_conf/conf_https_basic.go +++ b/bfe_config/bfe_conf/conf_https_basic.go @@ -70,7 +70,7 @@ type ConfigHttpsBasic struct { TlsRuleConf string // config for server tls rule CipherSuites []string // supported cipher suites - CurvePreferences []string // curve perference + CurvePreferences []string // curve preference MaxTlsVersion string // max tls version supported MinTlsVersion string // min tls version supported diff --git a/bfe_config/bfe_conf/conf_session_cache.go b/bfe_config/bfe_conf/conf_session_cache.go index cee342a1e..8841c15d5 100644 --- a/bfe_config/bfe_conf/conf_session_cache.go +++ b/bfe_config/bfe_conf/conf_session_cache.go @@ -23,8 +23,8 @@ type ConfigSessionCache struct { // disable tls session cache or not SessionCacheDisabled bool - // tcp address for redis servers - Servers string // one server or multiply servers(seperated by ',') + // address for redis servers + Servers string // perfix for cache key KeyPrefix string diff --git a/bfe_http/request.go b/bfe_http/request.go index 93c2d3cf0..7bc59fcc2 100644 --- a/bfe_http/request.go +++ b/bfe_http/request.go @@ -124,7 +124,7 @@ type Request struct { // following a hyphen uppercase and the rest lowercase. Header Header - // a headerKeys represents keys of header in orginal order + // a headerKeys represents keys of header in original order HeaderKeys textproto.MIMEKeys // Body is the request's body. @@ -213,7 +213,7 @@ type Request struct { TLS *bfe_tls.ConnectionState // State allows HTTP server and other software to record - // infomation about the request. This filed may be not filled. + // information about the request. This filed may be not filled. State *RequestState } @@ -394,7 +394,7 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header) err ruri = host } else { // use req.RequestUri instead of req.URL.RequestURI() (decoded/encoded) - // to be compatiable with non-standard web server ONLY WHEN URL not changed since + // to be compatible with non-standard web server ONLY WHEN URL not changed since // ReadRequest() rawurl, err := url.ParseRequestURI(req.RequestURI) if err == nil && rawurl.RequestURI() == ruri { @@ -454,7 +454,7 @@ func (req *Request) write(w io.Writer, usingProxy bool, extraHeaders Header) err // flush req header immediately if w if a buffered writer. // in case that the backend read timeout setting is too short, - // and body receiving from client is too slow, so until backend timeout the buffer is not fufilled + // and body receiving from client is too slow, so until backend timeout the buffer is not fulfilled // and the backend may close the connection if rbw, ok := w.(Flusher); ok { err = rbw.Flush() @@ -937,11 +937,7 @@ func (r *Request) WantsHttp10KeepAlive() bool { return false } - // change http 1.0 keepalive to ignore header Connection, keep consistent with c-bfe - // just for simplify comparasion in the process of replace bfe - // TODO: after replacement finish, change back - //return HasToken(r.Header.GetDirect("Connection"), "keep-alive") - return false + return HasToken(r.Header.GetDirect("Connection"), "keep-alive") } func (r *Request) WantsClose() bool { diff --git a/bfe_module/bfe_module.go b/bfe_module/bfe_module.go index 183bc2c94..4d1ee955c 100644 --- a/bfe_module/bfe_module.go +++ b/bfe_module/bfe_module.go @@ -135,7 +135,7 @@ func ModConfDir(confRoot string, modName string) string { return confDir } -// ModuleStatusGetJson get modules Availabe and modules Enabled. +// ModuleStatusGetJson get modules Available and modules Enabled. func ModuleStatusGetJson() ([]byte, error) { status := make(map[string][]string) status["available"] = modulesAll diff --git a/bfe_modules/mod_header/mod_header.go b/bfe_modules/mod_header/mod_header.go index e3159bc09..d42817d1c 100644 --- a/bfe_modules/mod_header/mod_header.go +++ b/bfe_modules/mod_header/mod_header.go @@ -141,7 +141,7 @@ func (m *ModuleHeader) reqHeaderHandler(request *bfe_basic.Request) (int, *bfe_h // apply global rule first m.applyProductRule(request, ReqHeader, GlobalProduct) - // product specific rule will overwirte global rule for HEADER_SET action + // product specific rule will overwrite global rule for HEADER_SET action m.applyProductRule(request, ReqHeader, request.Route.Product) return bfe_module.BFE_HANDLER_GOON, nil @@ -151,7 +151,7 @@ func (m *ModuleHeader) rspHeaderHandler(request *bfe_basic.Request, res *bfe_htt // apply global rule first m.applyProductRule(request, RspHeader, GlobalProduct) - // product specific rule will overwirte global rule for HEADER_SET action + // product specific rule will overwrite global rule for HEADER_SET action m.applyProductRule(request, RspHeader, request.Route.Product) return bfe_module.BFE_HANDLER_GOON diff --git a/bfe_modules/mod_redirect/action_url.go b/bfe_modules/mod_redirect/action_url.go index 67ec1ceff..3e931c4db 100644 --- a/bfe_modules/mod_redirect/action_url.go +++ b/bfe_modules/mod_redirect/action_url.go @@ -33,7 +33,7 @@ func ReqUrlFromQuery(req *bfe_basic.Request, key string) { req.Redirect.Url = req.Query.Get(key) } -// ReqUrlPrefixAdd specify redirect url by adding prefix to orginal uri(path+query) +// ReqUrlPrefixAdd specify redirect url by adding prefix to original uri(path+query) // e.g., url "/(.*)" => "link$1", func ReqUrlPrefixAdd(req *bfe_basic.Request, prefix string) { rawUrl := req.HttpRequest.URL diff --git a/bfe_net/textproto/header.go b/bfe_net/textproto/header.go index e57ae2988..591f3197b 100644 --- a/bfe_net/textproto/header.go +++ b/bfe_net/textproto/header.go @@ -22,7 +22,7 @@ package textproto // keys to sets of values. type MIMEHeader map[string][]string -// A MIMEKyes represents keys of header in orginal order +// A MIMEKyes represents keys of header in original order type MIMEKeys []string // Add adds the key, value pair to the header. diff --git a/bfe_net/textproto/reader.go b/bfe_net/textproto/reader.go index b0b3e46e6..0ff88ec72 100644 --- a/bfe_net/textproto/reader.go +++ b/bfe_net/textproto/reader.go @@ -531,7 +531,7 @@ func (r *Reader) ReadMIMEHeaderAndKeys() (MIMEHeader, MIMEKeys, error) { m[key] = append(vv, value) } - // append key in orginal order + // append key in original order mkeys = append(mkeys, key) if err != nil { diff --git a/bfe_server/bfe_server.go b/bfe_server/bfe_server.go index 62028e1e2..ef00a3afd 100644 --- a/bfe_server/bfe_server.go +++ b/bfe_server/bfe_server.go @@ -207,7 +207,7 @@ func (srv *BfeServer) initTLSConfig() (err error) { // enable Sslv2 ClientHello for compatible with ancient TLS-capable clients srv.TLSConfig.EnableSslv2ClientHello = httpsConf.EnableSslv2ClientHello - // initialize ciphersuites perference + // initialize ciphersuites preference srv.TLSConfig.PreferServerCipherSuites = true cipherSuites, cipherSuitesPriority, err := bfe_conf.GetCipherSuites(httpsConf.CipherSuites) if err != nil { @@ -219,7 +219,7 @@ func (srv *BfeServer) initTLSConfig() (err error) { // set Ssl3PoodleProofed true make server free of poodle attach srv.TLSConfig.Ssl3PoodleProofed = true - // initialize elliptic curves perference + // initialize elliptic curves preference srv.TLSConfig.CurvePreferences, err = bfe_conf.GetCurvePreferences(httpsConf.CurvePreferences) if err != nil { return fmt.Errorf("in ServerCertConfLoad() :%s", err.Error()) diff --git a/bfe_server/bfe_server_init.go b/bfe_server/bfe_server_init.go index b0fd3efb3..e9d1276e2 100644 --- a/bfe_server/bfe_server_init.go +++ b/bfe_server/bfe_server_init.go @@ -96,7 +96,7 @@ func StartUp(cfg bfe_conf.BfeConfig, version string, confRoot string) error { } log.Logger.Info("StartUp(): bfeServer.InitDataLoad() OK") - // start embeded web server + // start embedded web server bfeServer.Monitor.Start() serveChan := make(chan error) diff --git a/bfe_server/http_conn.go b/bfe_server/http_conn.go index 28f50c8f1..ace68b5f1 100644 --- a/bfe_server/http_conn.go +++ b/bfe_server/http_conn.go @@ -55,7 +55,7 @@ const ( // Close the connection after send response to client. closeAfterReply // Close the connection directly, do not send any data, - // it usally means some attacks may happened. + // it usually means some attacks may happened. closeDirectly ) diff --git a/bfe_server/protocol_handler.go b/bfe_server/protocol_handler.go index 97630bc24..e9f104c6a 100644 --- a/bfe_server/protocol_handler.go +++ b/bfe_server/protocol_handler.go @@ -51,7 +51,7 @@ func NewProtocolHandler(conn *conn, proto string) *ProtocolHandler { // ServeHTTP processes http request and send http response. // // Params: -// - w : a reponse writer +// - w : a response writer // - r : a http request func (p *ProtocolHandler) ServeHTTP(rw bfe_http.ResponseWriter, request *bfe_http.Request) { log.Logger.Debug("ProtocolHandler(%s): start process request", p.proto) diff --git a/bfe_server/register_modules.go b/bfe_server/register_modules.go index 5d4ab1965..ade28a037 100644 --- a/bfe_server/register_modules.go +++ b/bfe_server/register_modules.go @@ -24,7 +24,7 @@ import ( "github.com/baidu/go-lib/log" ) -// RegisterModule registeres bfe work module. +// RegisterModule registers bfe work module. func (srv *BfeServer) RegisterModules(modules []string) error { if modules == nil { return nil diff --git a/bfe_server/response.go b/bfe_server/response.go index 71903c718..19e83427a 100644 --- a/bfe_server/response.go +++ b/bfe_server/response.go @@ -161,7 +161,7 @@ func srcIsRegularFile(src io.Reader) (isRegular bool, err error) { } } -// set signature calculater for response +// set signature calculator for response func (w *response) SetSigner(signer bfe_http.SignCalculater) { w.cw.Signer = signer } diff --git a/bfe_server/reverseproxy.go b/bfe_server/reverseproxy.go index 739b07e14..21895be43 100644 --- a/bfe_server/reverseproxy.go +++ b/bfe_server/reverseproxy.go @@ -504,7 +504,7 @@ func (p *ReverseProxy) ServeHTTP(rw bfe_http.ResponseWriter, basicReq *bfe_basic // get instance of BfeServer srv := p.server - // set clientip of orginal user for request + // set clientip of original user for request setClientAddr(basicReq) // Callback for HANDLE_BEFORE_LOCATION diff --git a/bfe_server/tls_server_rule.go b/bfe_server/tls_server_rule.go index a0c0e7a56..efa30650e 100644 --- a/bfe_server/tls_server_rule.go +++ b/bfe_server/tls_server_rule.go @@ -48,7 +48,7 @@ type TLSServerRuleMap struct { vipRuleMap map[string]*ServerRule // tls server rule for specified conn sniRuleMap map[string]*ServerRule // tls server rule for specified host (optional) - nextProtosDef *NextProtosConf // defualt next protos conf + nextProtosDef *NextProtosConf // default next protos conf enableHttp2 bool // enable http2 globally or not enableSpdy bool // enable spdy globally or not chacha20Def bool // default chacha20 conf diff --git a/bfe_server/tls_session_cache.go b/bfe_server/tls_session_cache.go index 75cd71e1a..e2a0882b9 100644 --- a/bfe_server/tls_session_cache.go +++ b/bfe_server/tls_session_cache.go @@ -45,7 +45,7 @@ type ServerSessionCache struct { KeyPrefix string // prefix for cache key SessionExpire int // expire time for tls session state (s) - MaxIdle int // max idle conenctions in pool + MaxIdle int // max idle connections in pool pool *redis.Pool // connection pool to redis server poolLock sync.RWMutex // lock for pool diff --git a/bfe_server/web_server.go b/bfe_server/web_server.go index d79f6d574..6605b3fc2 100644 --- a/bfe_server/web_server.go +++ b/bfe_server/web_server.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// embeded web server in bfe +// embedded web server in bfe package bfe_server diff --git a/bfe_tls/handshake_client_test.go b/bfe_tls/handshake_client_test.go index e4b7c3286..d39463696 100644 --- a/bfe_tls/handshake_client_test.go +++ b/bfe_tls/handshake_client_test.go @@ -277,7 +277,7 @@ func runClientTestTLS12(t *testing.T, template *clientTest) { func prepareClientConfig() *Config { config := testConfig.Clone() - // Note: for avoid modify exsiting data file under testdata dir, + // Note: for avoid modify existing data file under testdata dir, // client should only use required ciphersuites. config.CipherSuites = []uint16{ TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, @@ -348,7 +348,7 @@ func TestHandshakeClientECDHEECDSAAESGCM(t *testing.T) { } func prepareClientConfigForChacha20() *Config { - // Note: for avoid modify exsiting data file under testdata dir, + // Note: for avoid modify existing data file under testdata dir, // client should only use required ciphersuites. ciphers := []uint16{ TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, diff --git a/bfe_tls/handshake_server.go b/bfe_tls/handshake_server.go index 9389afa81..0369cbff7 100644 --- a/bfe_tls/handshake_server.go +++ b/bfe_tls/handshake_server.go @@ -256,7 +256,7 @@ Curves: } } else { // Although sending an NPN extension without h2 is reasonable, some client - // has a bug aroud this. Best to send NPN without h2. + // has a bug around this. Best to send NPN without h2. nextProtos = checkAndRemoveH2(nextProtos) // Although sending an empty NPN extension is reasonable, Firefox has diff --git a/bfe_util/logid.go b/bfe_util/logid.go index df18106a2..d14de1b40 100644 --- a/bfe_util/logid.go +++ b/bfe_util/logid.go @@ -170,7 +170,7 @@ uint64_t calculate_log_id(char *network, char* client_addr, char* local_addr, return log_id; } */ -import "C" // this line must be seperated +import "C" // this line must be separated import ( "net" diff --git a/go.mod b/go.mod index 66347caff..bac11492b 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed - golang.org/x/tools v0.0.0-20190730215328-ed3277de2799 // indirect + golang.org/x/tools v0.0.0-20190731214159-1e85ed8060aa // indirect gopkg.in/gcfg.v1 v1.2.3 gopkg.in/warnings.v0 v0.1.2 // indirect ) diff --git a/go.sum b/go.sum index 68fede315..fd44ec3db 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,8 @@ golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20190730215328-ed3277de2799 h1:rvNf5qrBjmtxebJHK+blZSkGIv+Yg6UlDnl2ApkB6m4= golang.org/x/tools v0.0.0-20190730215328-ed3277de2799/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= +golang.org/x/tools v0.0.0-20190731214159-1e85ed8060aa h1:kwa/4M1dbmhZqOIqYiTtbA6JrvPwo1+jqlub2qDXX90= +golang.org/x/tools v0.0.0-20190731214159-1e85ed8060aa/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= gopkg.in/gcfg.v1 v1.2.3 h1:m8OOJ4ccYHnx2f4gQwpno8nAX5OGOh7RLaaz0pj3Ogs= gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=