Skip to content

Commit f71dace

Browse files
committed
Make instance UUID for an established connection available
1 parent f2ffa88 commit f71dace

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

connection.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"net"
1111
"net/url"
12+
"regexp"
1213
"strings"
1314
"sync"
1415
"sync/atomic"
@@ -21,6 +22,8 @@ var (
2122
ErrSyncFailed = errors.New("SYNC failed")
2223

2324
versionPrefix = []byte("Tarantool ")
25+
26+
greetingRegexp = regexp.MustCompile("^Tarantool ([0-9.]+) [(]([^ ]+)[)] ([a-f0-9-]+)")
2427
)
2528

2629
type Options struct {
@@ -42,8 +45,9 @@ type Options struct {
4245
}
4346

4447
type Greeting struct {
45-
Version uint32
46-
Auth []byte
48+
Version uint32
49+
InstanceUUID string
50+
Auth []byte
4751
}
4852

4953
type Connection struct {
@@ -277,9 +281,16 @@ func parseGreeting(r io.Reader) (*Greeting, error) {
277281
return nil, err
278282
}
279283

284+
uuid := ""
285+
m := greetingRegexp.FindAllSubmatch(greeting[:64], -1)
286+
if len(m) > 0 && len(m[0]) > 3 {
287+
uuid = string(m[0][3])
288+
}
289+
280290
return &Greeting{
281-
Version: version,
282-
Auth: greeting[64:108],
291+
Version: version,
292+
Auth: greeting[64:108],
293+
InstanceUUID: uuid,
283294
}, nil
284295
}
285296

@@ -453,6 +464,10 @@ func (conn *Connection) IsClosed() bool {
453464
}
454465
}
455466

467+
func (conn *Connection) InstanceUUID() string {
468+
return conn.greeting.InstanceUUID
469+
}
470+
456471
func (conn *Connection) releasePacket(pp *BinaryPacket) {
457472
if conn.poolMaxPacketSize == 0 || conn.poolMaxPacketSize < cap(pp.body) {
458473
pp.Release()

0 commit comments

Comments
 (0)