bzync-nextsql 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22fcc7ed7950fdad5c655543af1d813989ac8a76e291e2e1ff3a699268af052c
4
- data.tar.gz: e90a274dced110f5883f471c6daa4caa60d8757164962b11fdb778df843b9796
3
+ metadata.gz: 7f8ea5d62b319951e5324da7495acd2b082dc3c05945b9c7cd8810f81ab204ed
4
+ data.tar.gz: 773874cbee89f62cea0754249800a087f8de553e79a90c7f0d5d6e85026f0a39
5
5
  SHA512:
6
- metadata.gz: 8adc88df55005abbf9b1d643dc6d026d8786d4e954813327a0ddc84adb8cf27a1c4a22ed64b552ff2e3ddf9490cafdb3694ddf494392cbb5f74671a11a8d5df0
7
- data.tar.gz: 43e99ed4daf17b81e83eeba3ef2cb1c715679061534159bf712a5e6e433d6764949c2d477a8908437f7ee0b5bfad4bfb7ca9656cd90938b8a06a405fedb21e94
6
+ metadata.gz: 4c6cd6f4f39cd9aceedaaf0a373e8deedbe7a217ea9fdd0e04231bfc28409eeceb8cd84294b776ec1a48d8621fdf797e5007bc4203ff9bec950d95799333c128
7
+ data.tar.gz: 302b1dcfc03a25f1ac6ef126d99c9a1cfcb0c2c04dbf44414f8e4558e20b9029c8c0c5f2153f4f0de4326ff8ccb421944970ddb25412822d6cfc01887296050b
@@ -6,7 +6,6 @@
6
6
 
7
7
  require "socket"
8
8
  require "openssl"
9
- require "ipaddr"
10
9
 
11
10
  require_relative "protocol"
12
11
  require_relative "errors"
@@ -41,6 +40,7 @@ module NextSQL
41
40
  # from multiple threads/fibers — open one Connection per worker, or use
42
41
  # +Cluster+ which pools one connection per node.
43
42
  class Connection
43
+ LOOPBACK_RE = /\A127\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/.freeze
44
44
  CONNECT_TIMEOUT = 10.0
45
45
 
46
46
  class << self
@@ -73,12 +73,9 @@ module NextSQL
73
73
  host, = split_host_port(addr, allow_bare: true)
74
74
  host = host.strip.downcase
75
75
  return true if host == "localhost"
76
+ return true if %w[::1 0:0:0:0:0:0:0:1].include?(host)
76
77
 
77
- begin
78
- IPAddr.new(host).loopback?
79
- rescue IPAddr::Error
80
- false
81
- end
78
+ LOOPBACK_RE.match?(host)
82
79
  end
83
80
 
84
81
  def validate_config!(cfg)
@@ -372,17 +369,12 @@ module NextSQL
372
369
 
373
370
  def handshake
374
371
  cfg = @cfg
375
- write_frame(Protocol::TYPE_HELLO,
376
- Protocol.encode_hello(Protocol::VERSION, Protocol::FLAG_PUBLIC_ERROR_CODES, "\x00" * 8,
377
- cfg.database, cfg.user, cfg.realm))
372
+ write_frame(Protocol::TYPE_HELLO, Protocol.encode_hello(Protocol::VERSION, 0, "\x00" * 8, cfg.database, cfg.user, cfg.realm))
378
373
  typ, payload = read_frame
379
374
  raise unexpected(typ, payload) if typ != Protocol::TYPE_HELLO_OK
380
375
 
381
- _version, auth_method, secret, flags = Protocol.decode_hello_ok(payload)
376
+ _version, auth_method, secret = Protocol.decode_hello_ok(payload)
382
377
  @secret = secret
383
- # Diagnostic only: decode_error reads the field whenever it is present,
384
- # so nothing depends on this having been echoed.
385
- @public_error_codes = (flags & Protocol::FLAG_PUBLIC_ERROR_CODES) != 0
386
378
  write_frame(Protocol::TYPE_AUTH, Protocol.u16str(cfg.password))
387
379
  typ, payload = read_frame
388
380
  raise unexpected(typ, payload) if typ != Protocol::TYPE_AUTH_OK
@@ -10,16 +10,8 @@ module NextSQL
10
10
  class Error < StandardError
11
11
  attr_reader :error_code
12
12
 
13
- # +public_code+ is the stable ERR_* name from docs/error-codes.md. It is
14
- # set only on an error received over a connection that negotiated the
15
- # public taxonomy, and is "" otherwise -- for a local error, or an older
16
- # server. +error_code+ always carries the legacy class, so retry logic
17
- # keeps reading that and nothing should require +public_code+.
18
- attr_reader :public_code
19
-
20
- def initialize(error_code, message = "", public_code = "")
13
+ def initialize(error_code, message = "")
21
14
  @error_code = error_code
22
- @public_code = public_code
23
15
  super(message.empty? ? error_code : message)
24
16
  end
25
17
  end
@@ -53,12 +53,6 @@ module NextSQL
53
53
  AUTH_PASSWORD = 1
54
54
  AUTH_PASSWORD_KEY = 2
55
55
  FLAG_CANCEL = 1
56
- # FLAG_PUBLIC_ERROR_CODES asks the server for the stable ERR_* error
57
- # taxonomy (docs/error-codes.md). A server that does not implement it
58
- # ignores the bit and keeps the NSQL v1 error shape, which decode_error
59
- # still reads, so setting it is safe against any server version. The server
60
- # echoes it in the hello-ok flags when it was accepted.
61
- FLAG_PUBLIC_ERROR_CODES = 2
62
56
  FLAG_NULL = 0x01
63
57
 
64
58
  KIND_UUID = 1
@@ -319,16 +313,9 @@ module NextSQL
319
313
  end
320
314
 
321
315
  def decode_hello_ok(b)
322
- raise ProtocolError, "bad hello-ok length" unless [11, 13].include?(b.bytesize)
323
-
324
- flags = 0
325
- if b.bytesize == 13
326
- flags = u16(b, 11)
327
- # The server omits the field when it accepted no capability, so a
328
- # present-but-zero field is a second encoding of the v1 hello-ok.
329
- raise ProtocolError, "empty hello-ok flags" if flags.zero?
330
- end
331
- [u16(b, 0), b.getbyte(2), b.byteslice(3, 8), flags]
316
+ raise ProtocolError, "bad hello-ok length" unless b.bytesize == 11
317
+
318
+ [u16(b, 0), b.getbyte(2), b.byteslice(3, 8)]
332
319
  end
333
320
 
334
321
  def encode_query(sql, params)
@@ -959,16 +946,8 @@ module NextSQL
959
946
 
960
947
  def decode_error(b)
961
948
  code, off = read_u16_string(b, 0, MAX_NAME)
962
- msg, off = read_u16_string(b, off, MAX_NAME)
963
- # Optional trailing field, present only from a server that accepted
964
- # FLAG_PUBLIC_ERROR_CODES. Its absence is normal -- an older server
965
- # ignores the request bit -- so this must never be required.
966
- public_code = ""
967
- if off < b.bytesize
968
- public_code, = read_u16_string(b, off, MAX_NAME)
969
- raise ProtocolError, "empty public error code" if public_code.empty?
970
- end
971
- Error.new(code, msg, public_code)
949
+ msg, = read_u16_string(b, off, MAX_NAME)
950
+ Error.new(code, msg)
972
951
  end
973
952
 
974
953
  def encode_set_read_consistency(mode, max_staleness_ms)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NextSQL
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bzync-nextsql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rayan Reynaldo