import path

This commit is contained in:
insanity
2018-08-15 16:17:18 +09:00
parent 3d28519fa1
commit 14ddc4feba
52 changed files with 310 additions and 779 deletions

View File

@@ -6,12 +6,12 @@ import (
"io"
"strings"
csm "git.loafle.net/commons/service_matcher-go"
osm "git.loafle.net/overflow/service_matcher-go"
)
type MySqlMatcher struct {
csm.Matchers
meta csm.Metadata
osm.Matchers
meta osm.Metadata
}
func (m *MySqlMatcher) Key() string {
@@ -29,7 +29,7 @@ func (m *MySqlMatcher) Name() string {
return name
}
func (m *MySqlMatcher) Meta() csm.Metadata {
func (m *MySqlMatcher) Meta() osm.Metadata {
return m.meta
}
@@ -41,7 +41,7 @@ func (m *MySqlMatcher) HasResponse(index int) bool {
return true
}
func (m *MySqlMatcher) IsError(info csm.MatchInfo, index int, packet *csm.Packet) bool {
func (m *MySqlMatcher) IsError(info osm.MatchInfo, index int, packet *osm.Packet) bool {
return false
}
@@ -55,26 +55,26 @@ type serverSettings struct {
keepalive int64
}
func (m *MySqlMatcher) Match(info csm.MatchInfo, index int, packet *csm.Packet) error {
func (m *MySqlMatcher) Match(info osm.MatchInfo, index int, packet *osm.Packet) error {
if packet == nil || packet.Buffer == nil || packet.Len == 0 {
return csm.NoPacketReceivedError()
return osm.NoPacketReceivedError()
}
buf := bytes.NewBuffer(packet.Buffer[:3])
packetLen, _ := binary.ReadUvarint(buf)
if packetLen != uint64(packet.Len-4) {
return csm.NotMatchedError()
return osm.NotMatchedError()
}
pos := 4
p := new(serverSettings)
p.protocol = packet.Buffer[pos]
if p.protocol != 9 && p.protocol != 10 {
return csm.NotMatchedError()
return osm.NotMatchedError()
}
pos++
slice, err := readSlice(packet.Buffer[pos:], 0x00)
if err != nil {
return csm.NotMatchedError()
return osm.NotMatchedError()
}
m.meta["version"] = string(slice)
pos += len(slice) + 1
@@ -103,8 +103,8 @@ func bytesToUint32(b []byte) (n uint32) {
return
}
func NewMatcher() csm.Matcher {
func NewMatcher() osm.Matcher {
m := &MySqlMatcher{}
m.meta = csm.NewMetadata()
m.meta = osm.NewMetadata()
return m
}

View File

@@ -4,7 +4,7 @@ import (
"net"
"testing"
csm "git.loafle.net/commons/service_matcher-go"
osm "git.loafle.net/overflow/service_matcher-go"
)
func TestMySql(t *testing.T) {
@@ -17,7 +17,7 @@ func TestMySql(t *testing.T) {
bytes := make([]byte, 1024)
n, _ := conn.Read(bytes)
p := csm.NewPacket(bytes, n)
p := osm.NewPacket(bytes, n)
if err := m.Match(nil, 0, p); err != nil {
t.Error(err)