diff --git a/client_test.go b/client_test.go index cae58a84..72de1cac 100644 --- a/client_test.go +++ b/client_test.go @@ -256,7 +256,7 @@ func TestVersionVerify(t *testing.T) { conn := newConnection(hostAddress) err := conn.open(hostAddress, testPoolConfig.TimeOut, nil, false, nil, "INVALID_VERSION") if err != nil { - assert.Contains(t, err.Error(), "incompatible version between client and server") + assert.Contains(t, err.Error(), "incompatible handshakeKey between client and server") } defer conn.close() } diff --git a/configs.go b/configs.go index 2a4d60ef..f1104dc4 100644 --- a/configs.go +++ b/configs.go @@ -34,8 +34,8 @@ type PoolConfig struct { UseHTTP2 bool // HttpHeader is the http headers for the connection when using HTTP2 HttpHeader http.Header - // client version, make sure the client version is in the white list of NebulaGraph server 'client_white_list' - Version string + // client handshakeKey, make sure the client handshakeKey is in the white list of NebulaGraph server 'client_white_list' + HandshakeKey string } // validateConf validates config @@ -66,7 +66,7 @@ func GetDefaultConf() PoolConfig { MaxConnPoolSize: 10, MinConnPoolSize: 0, UseHTTP2: false, - Version: "", + HandshakeKey: "", } } @@ -141,8 +141,8 @@ type SessionPoolConf struct { useHTTP2 bool // httpHeader is the http headers for the connection httpHeader http.Header - // client version, make sure the client version is in the white list of NebulaGraph server 'client_white_list' - version string + // client handshakeKey, make sure the client handshakeKey is in the white list of NebulaGraph server 'client_white_list' + handshakeKey string } type SessionPoolConfOption func(*SessionPoolConf) @@ -219,9 +219,9 @@ func WithHttpHeader(header http.Header) SessionPoolConfOption { } } -func WithVersion(version string) SessionPoolConfOption { +func WithHandshakeKey(handshakeKey string) SessionPoolConfOption { return func(conf *SessionPoolConf) { - conf.version = version + conf.handshakeKey = handshakeKey } } diff --git a/connection.go b/connection.go index c6ee5bf2..8595d15a 100644 --- a/connection.go +++ b/connection.go @@ -30,7 +30,7 @@ type connection struct { sslConfig *tls.Config useHTTP2 bool httpHeader http.Header - version string + handshakeKey string graph *graph.GraphServiceClient } @@ -40,7 +40,7 @@ func newConnection(severAddress HostAddress) *connection { timeout: 0 * time.Millisecond, returnedAt: time.Now(), sslConfig: nil, - version: "", + handshakeKey: "", graph: nil, } } @@ -48,13 +48,13 @@ func newConnection(severAddress HostAddress) *connection { // open opens a transport for the connection // if sslConfig is not nil, an SSL transport will be created func (cn *connection) open(hostAddress HostAddress, timeout time.Duration, sslConfig *tls.Config, - useHTTP2 bool, httpHeader http.Header, version string) error { + useHTTP2 bool, httpHeader http.Header, handshakeKey string) error { ip := hostAddress.Host port := hostAddress.Port newAdd := net.JoinHostPort(ip, strconv.Itoa(port)) cn.timeout = timeout cn.useHTTP2 = useHTTP2 - cn.version = version + cn.handshakeKey = handshakeKey var ( err error @@ -136,16 +136,16 @@ func (cn *connection) open(hostAddress HostAddress, timeout time.Duration, sslCo func (cn *connection) verifyClientVersion() error { req := graph.NewVerifyClientVersionReq() - if cn.version != "" { - req.SetVersion([]byte(cn.version)) + if cn.handshakeKey != "" { + req.SetVersion([]byte(cn.handshakeKey)) } resp, err := cn.graph.VerifyClientVersion(req) if err != nil { cn.close() - return fmt.Errorf("failed to verify client version: %s", err.Error()) + return fmt.Errorf("failed to verify client handshakeKey: %s", err.Error()) } if resp.GetErrorCode() != nebula.ErrorCode_SUCCEEDED { - return fmt.Errorf("incompatible version between client and server: %s", string(resp.GetErrorMsg())) + return fmt.Errorf("incompatible handshakeKey between client and server: %s", string(resp.GetErrorMsg())) } return nil } @@ -156,7 +156,7 @@ func (cn *connection) verifyClientVersion() error { // When the timeout occurs, the connection will be reopened to avoid the impact of the message. func (cn *connection) reopen() error { cn.close() - return cn.open(cn.severAddress, cn.timeout, cn.sslConfig, cn.useHTTP2, cn.httpHeader, cn.version) + return cn.open(cn.severAddress, cn.timeout, cn.sslConfig, cn.useHTTP2, cn.httpHeader, cn.handshakeKey) } // Authenticate diff --git a/connection_pool.go b/connection_pool.go index 50bce81b..c41645ca 100644 --- a/connection_pool.go +++ b/connection_pool.go @@ -66,7 +66,7 @@ func NewSslConnectionPool(addresses []HostAddress, conf PoolConfig, sslConfig *t // initPool initializes the connection pool func (pool *ConnectionPool) initPool() error { if err := checkAddresses(pool.conf.TimeOut, pool.addresses, pool.sslConfig, - pool.conf.UseHTTP2, pool.conf.HttpHeader, pool.conf.Version); err != nil { + pool.conf.UseHTTP2, pool.conf.HttpHeader, pool.conf.HandshakeKey); err != nil { return fmt.Errorf("failed to open connection, error: %s ", err.Error()) } @@ -76,7 +76,7 @@ func (pool *ConnectionPool) initPool() error { // Open connection to host if err := newConn.open(newConn.severAddress, pool.conf.TimeOut, pool.sslConfig, - pool.conf.UseHTTP2, pool.conf.HttpHeader, pool.conf.Version); err != nil { + pool.conf.UseHTTP2, pool.conf.HttpHeader, pool.conf.HandshakeKey); err != nil { // If initialization failed, clean idle queue idleLen := pool.idleConnectionQueue.Len() for i := 0; i < idleLen; i++ { @@ -194,7 +194,7 @@ func (pool *ConnectionPool) releaseAndBack(conn *connection, pushBack bool) { // Ping checks availability of host func (pool *ConnectionPool) Ping(host HostAddress, timeout time.Duration) error { - return pingAddress(host, timeout, pool.sslConfig, pool.conf.UseHTTP2, pool.conf.HttpHeader, pool.conf.Version) + return pingAddress(host, timeout, pool.sslConfig, pool.conf.UseHTTP2, pool.conf.HttpHeader, pool.conf.HandshakeKey) } // Close closes all connection @@ -246,7 +246,7 @@ func (pool *ConnectionPool) newConnToHost() (*connection, error) { newConn := newConnection(host) // Open connection to host if err := newConn.open(newConn.severAddress, pool.conf.TimeOut, pool.sslConfig, - pool.conf.UseHTTP2, pool.conf.HttpHeader, pool.conf.Version); err != nil { + pool.conf.UseHTTP2, pool.conf.HttpHeader, pool.conf.HandshakeKey); err != nil { return nil, err } // Add connection to active queue @@ -354,13 +354,13 @@ func (pool *ConnectionPool) timeoutConnectionList() (closing []*connection) { // It opens a temporary connection to each address and closes it immediately. // If no error is returned, the addresses are available. func checkAddresses(confTimeout time.Duration, addresses []HostAddress, sslConfig *tls.Config, - useHTTP2 bool, httpHeader http.Header, version string) error { + useHTTP2 bool, httpHeader http.Header, handshakeKey string) error { var timeout = 3 * time.Second if confTimeout != 0 && confTimeout < timeout { timeout = confTimeout } for _, address := range addresses { - if err := pingAddress(address, timeout, sslConfig, useHTTP2, httpHeader, version); err != nil { + if err := pingAddress(address, timeout, sslConfig, useHTTP2, httpHeader, handshakeKey); err != nil { return err } } @@ -368,10 +368,10 @@ func checkAddresses(confTimeout time.Duration, addresses []HostAddress, sslConfi } func pingAddress(address HostAddress, timeout time.Duration, sslConfig *tls.Config, - useHTTP2 bool, httpHeader http.Header, version string) error { + useHTTP2 bool, httpHeader http.Header, handshakeKey string) error { newConn := newConnection(address) // Open connection to host - if err := newConn.open(newConn.severAddress, timeout, sslConfig, useHTTP2, httpHeader, version); err != nil { + if err := newConn.open(newConn.severAddress, timeout, sslConfig, useHTTP2, httpHeader, handshakeKey); err != nil { return err } defer newConn.close() diff --git a/examples/basic_example/graph_client_basic_example.go b/examples/basic_example/graph_client_basic_example.go index 3ecebbfd..5835028b 100644 --- a/examples/basic_example/graph_client_basic_example.go +++ b/examples/basic_example/graph_client_basic_example.go @@ -33,7 +33,7 @@ func main() { // Create configs for connection pool using default values testPoolConfig := nebula.GetDefaultConf() testPoolConfig.UseHTTP2 = useHTTP2 - testPoolConfig.Version = "3.0.0" + testPoolConfig.HandshakeKey = "3.0.0" // Initialize connection pool pool, err := nebula.NewConnectionPool(hostList, testPoolConfig, log) diff --git a/session_pool.go b/session_pool.go index e25312ac..04b0b4e6 100644 --- a/session_pool.go +++ b/session_pool.go @@ -79,7 +79,7 @@ func NewSessionPool(conf SessionPoolConf, log Logger) (*SessionPool, error) { func (pool *SessionPool) init() error { // check the hosts status if err := checkAddresses(pool.conf.timeOut, pool.conf.serviceAddrs, pool.conf.sslConfig, - pool.conf.useHTTP2, pool.conf.httpHeader, pool.conf.version); err != nil { + pool.conf.useHTTP2, pool.conf.httpHeader, pool.conf.handshakeKey); err != nil { return fmt.Errorf("failed to initialize the session pool, %s", err.Error()) } @@ -287,7 +287,7 @@ func (pool *SessionPool) newSession() (*pureSession, error) { // open a new connection if err := cn.open(cn.severAddress, pool.conf.timeOut, pool.conf.sslConfig, - pool.conf.useHTTP2, pool.conf.httpHeader, pool.conf.version); err != nil { + pool.conf.useHTTP2, pool.conf.httpHeader, pool.conf.handshakeKey); err != nil { return nil, fmt.Errorf("failed to create a net.Conn-backed Transport,: %s", err.Error()) } diff --git a/session_pool_test.go b/session_pool_test.go index aa03afb4..2d314a4e 100644 --- a/session_pool_test.go +++ b/session_pool_test.go @@ -125,25 +125,25 @@ func TestSessionPoolServerCheck(t *testing.T) { } } -func TestSessionPoolInvalidVersion(t *testing.T) { +func TestSessionPoolInvalidHandshakeKey(t *testing.T) { prepareSpace("client_test") defer dropSpace("client_test") hostAddress := HostAddress{Host: address, Port: port} - // wrong version info + // wrong handshakeKey info versionConfig, err := NewSessionPoolConf( "root", "nebula", []HostAddress{hostAddress}, "client_test", ) - versionConfig.version = "INVALID_VERSION" + versionConfig.handshakeKey = "INVALID_VERSION" versionConfig.minSize = 1 // create session pool _, err = NewSessionPool(*versionConfig, DefaultLogger{}) if err != nil { - assert.Contains(t, err.Error(), "incompatible version between client and server") + assert.Contains(t, err.Error(), "incompatible handshakeKey between client and server") } }